API-Referenz
@speechineer/react
Speechineer for React. Wrap your app in SpeechineerProvider once (your API key, or a
token your server signs), then call one hook per capability: useSpeechToForm to fill
a form by voice, useTextToForm to fill it from text. Each hook gives you the session
state as plain values (values, transcript, isListening, error, …) and the
controls (start, stop, end / extract). The client, the form definition, the
callbacks, and the state types are shared by every package and documented once in the
Core reference.
Setup
The provider: give it your credentials (or a client you created) and every hook below it uses the same client.
SpeechineerProviderProps
What the provider takes: either a client you created yourself, or the client
options (apiKey / token, account, baseUrl) — the provider creates the client
for you and keeps it for as long as the options stay the same.
Extends
ClientOptions
Properties
| Property | Type | Description |
|---|---|---|
baseUrl? | string | The Speechineer API root, without a trailing slash. Defaults to the production API — set it only to target another environment. |
apiKey? | string | The API key of the workspace this app belongs to. Unsigned mode only — with a signed token the key travels inside the token. |
token? | string | TokenProvider | A token your server signed, or a function that returns one. Takes precedence over apiKey, and is the only option a Signed API key accepts. With a function the SDK asks for a fresh token on every session start, so expiry is never your problem. |
account? | Account | The end user sessions are for, unless a session says otherwise. Required with apiKey; ignored with token (the token carries the account). |
client? | SpeechineerClient | A client you created with createClient. When given, the other options are ignored. |
children? | ReactNode | The part of your app that uses Speechineer. |
SpeechineerProvider()
function SpeechineerProvider(__namedParameters): Element;Wrap your app (or the part of it that talks to Speechineer) once. Every hook below it uses the same client.
Parameters
| Parameter | Type |
|---|---|
__namedParameters | SpeechineerProviderProps |
Returns
Element
Example
import { SpeechineerProvider } from "@speechineer/react";
<SpeechineerProvider apiKey={import.meta.env.VITE_SPEECHINEER_KEY} account={{ key: user.id }}>
<App />
</SpeechineerProvider>useSpeechineer()
function useSpeechineer(): SpeechineerClient;The client the nearest SpeechineerProvider created — for the rare case where you
want to create a session yourself (client.speechToForm(...)) instead of using a hook.
Returns
SpeechineerClient
Capability: Speech to form
Fill a form by voice: values stream into values (and onFieldValue) as the user
speaks; add transcript: true to also receive the spoken text.
UseSpeechToFormOptions
The options of useSpeechToForm: the session options every framework shares, plus
an optional client to use instead of the provider's.
Extends
SpeechToFormOptions
Properties
| Property | Type | Description |
|---|---|---|
onSessionStart? | (sessionId) => void | Fires once, as soon as the session exists and work can begin. Receives the session id — keep it if you want to correlate it with your own logs. |
onStateChange? | (state) => void | The session state changed — its lifecycle, its id, a value, the transcript, an error, or the status of one of its connections. Receives the whole new state; render from it. |
onEvent? | (event) => void | Every status event Speechineer emits for this session — progress, warnings, and failures alike. Use it for logging or a live status display. |
onError? | (error) => void | Something failed in a way you should handle: a rejected request, a denied microphone permission, a lost connection, or a failure Speechineer reported while the session ran. Read error.code to branch and error.recoverable to decide whether to offer a retry. |
onFieldValue? | (fieldId, value) => void | One recognized field value. Called repeatedly while the user speaks, and more than once for the same fieldId when a value is refined — always apply the latest. fieldId is the id you gave the field; value is passed through as received, so cast or validate it the way your form expects. |
onTranscript? | (text) => void | The transcript so far — the full accumulated text, not just the newest words, so you can render it directly without stitching updates together. |
form | FormDefinition | Which form to fill: the one configured in Speechineer, or one defined right here. |
spokenLanguage? | string | The language the user will speak (for example 'en', 'de'). Detected automatically when omitted; set it when you already know, for slightly faster and more reliable recognition. |
transcript? | boolean | Also stream the spoken text: transcript in the state (and onTranscript) fills while the user speaks. Fixed for the session — change it by creating a new one. |
initialValues? | Record<string, unknown> | Values you already captured, keyed by field id — for example when a user resumes a form that was partly filled in earlier. They appear in values immediately and Speechineer continues from them. |
account? | Account | The end user this session is for, when it differs from the client's default account. Ignored when the client authenticates with a signed token — the token carries the account. |
client? | SpeechineerClient | Use this client instead of the nearest SpeechineerProvider's. |
UseSpeechToFormResult
What useSpeechToForm returns: the session state spread out for rendering
(values, transcript, isListening, isConnecting, isEnding, error,
sessionId, status, connections), the controls, and the full state object
for when you want to compare by reference.
Extends
SessionState
Properties
| Property | Type | Description |
|---|---|---|
status | SessionStatus | Where the session is in its life — see SessionStatus. |
sessionId | string | null | The id of the running session, or null before it exists. |
error | SpeechineerError | null | The last error, or null. Cleared when the next start() succeeds. |
connections | SessionConnections | The status of each connection: session always, the others when the capability uses them. |
values | Readonly<Record<string, unknown>> | The latest recognized value of every field, keyed by the field id you gave it. Starts with initialValues (if any) and grows as values are recognized; a refined value replaces the earlier one. |
transcript | string | The spoken text so far (the full accumulated transcript), or '' when the session does not stream it. |
isListening | boolean | The microphone is on and audio is being sent. |
isConnecting | boolean | The session or one of its connections is being established. |
isEnding | boolean | The session is being finished (end()), or the microphone is winding down after stop(). |
start | () => Promise<void> | Start listening — see SpeechToFormSession.start. |
stop | () => void | Pause listening — see SpeechToFormSession.stop. |
end | () => Promise<void> | Finish the session — see SpeechToFormSession.end. |
state | SessionState | The whole state object (the same values as the spread fields). |
useSpeechToForm()
function useSpeechToForm(options): UseSpeechToFormResult;Fill a form by voice. The session is created once per component and released
when the component goes away; the callbacks you pass are always the latest ones.
transcript and form.source are fixed for the component's lifetime; the rest of
form (key, version, language) is read each time a session starts, so a change
applies to the next session after end(). To change everything at once, render a
new component (for example with a key).
Parameters
| Parameter | Type |
|---|---|
options | UseSpeechToFormOptions |
Returns
Example
import { useSpeechToForm, FormField } from "@speechineer/react";
const fields = [
FormField.text("patientName", "Extract the patient full name"),
FormField.integer("age", "Extract the age in years"),
];
function TalkToForm() {
const { start, stop, isListening, values } = useSpeechToForm({
form: { source: "inline", key: "patient-intake", version: "1", language: "en", fields },
});
return (
<>
<button type="button" onClick={isListening ? stop : () => void start()}>
{isListening ? "Stop" : "Talk"}
</button>
<input value={String(values.patientName ?? "")} readOnly />
</>
);
}Capability: Text to form
No recording at all — turn text the user typed or pasted into field values, as often as you like.
UseTextToFormOptions
The options of useTextToForm: the session options every framework shares, plus
an optional client to use instead of the provider's.
Extends
TextToFormOptions
Properties
| Property | Type | Description |
|---|---|---|
onSessionStart? | (sessionId) => void | Fires once, as soon as the session exists and work can begin. Receives the session id — keep it if you want to correlate it with your own logs. |
onStateChange? | (state) => void | The session state changed — its lifecycle, its id, a value, the transcript, an error, or the status of one of its connections. Receives the whole new state; render from it. |
onEvent? | (event) => void | Every status event Speechineer emits for this session — progress, warnings, and failures alike. Use it for logging or a live status display. |
onError? | (error) => void | Something failed in a way you should handle: a rejected request, a denied microphone permission, a lost connection, or a failure Speechineer reported while the session ran. Read error.code to branch and error.recoverable to decide whether to offer a retry. |
onFieldValue? | (fieldId, value) => void | One recognized field value. Called repeatedly while the user speaks, and more than once for the same fieldId when a value is refined — always apply the latest. fieldId is the id you gave the field; value is passed through as received, so cast or validate it the way your form expects. |
form | FormDefinition | Which form to fill: the one configured in Speechineer, or one defined right here. |
initialValues? | Record<string, unknown> | Values you already captured, keyed by field id. They appear in values immediately and Speechineer treats them as the baseline for the next extraction. |
account? | Account | The end user this session is for, when it differs from the client's default account. Ignored when the client authenticates with a signed token. |
client? | SpeechineerClient | Use this client instead of the nearest SpeechineerProvider's. |
UseTextToFormResult
What useTextToForm returns: the session state spread out for rendering, the
controls, isExtracting while a call is in flight, and the full state object.
Extends
SessionState
Properties
| Property | Type | Description |
|---|---|---|
status | SessionStatus | Where the session is in its life — see SessionStatus. |
sessionId | string | null | The id of the running session, or null before it exists. |
error | SpeechineerError | null | The last error, or null. Cleared when the next start() succeeds. |
connections | SessionConnections | The status of each connection: session always, the others when the capability uses them. |
values | Readonly<Record<string, unknown>> | The latest recognized value of every field, keyed by the field id you gave it. Starts with initialValues (if any) and grows as values are recognized; a refined value replaces the earlier one. |
transcript | string | The spoken text so far (the full accumulated transcript), or '' when the session does not stream it. |
isListening | boolean | The microphone is on and audio is being sent. |
isConnecting | boolean | The session or one of its connections is being established. |
isEnding | boolean | The session is being finished (end()), or the microphone is winding down after stop(). |
extract | (text) => Promise<Readonly<Record<string, unknown>>> | Extract field values from text — see TextToFormSession.extract. |
start | () => Promise<void> | Open the session ahead of time — see TextToFormSession.start. |
end | () => Promise<void> | Finish the session — see TextToFormSession.end. |
isExtracting | boolean | An extract call is in flight. |
state | SessionState | The whole state object (the same values as the spread fields). |
useTextToForm()
function useTextToForm(options): UseTextToFormResult;Extract field values from text the user typed or pasted. extract opens the
session on first use and merges every result into values. form.source is fixed
for the component's lifetime; the rest of form is read each time a session
starts, so a change applies to the next session after end().
Parameters
| Parameter | Type |
|---|---|
options | UseTextToFormOptions |
Returns
Example
const { extract, values, isExtracting } = useTextToForm({
form: { source: "workspace", key: "patient-intake", version: "1", language: "en" },
});
await extract("Patient Jane Doe, born 1990-03-28.");