API reference

@speechineer/angular

Speechineer for Angular. Register it once with provideSpeechineer (your API key, or a token your server signs), then call one inject function per capability in a component or service: injectSpeechToForm to fill a form by voice, injectTextToForm to fill it from text. Each returns the session (start, stop, end / extract) with its state as signals (values(), transcript(), isListening(), errors(), …). 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 function: give it your credentials (or a client you created) in your application providers and every inject function uses the same client.

provideSpeechineer()

ts
function provideSpeechineer(clientOrOptions): EnvironmentProviders;

Register Speechineer once, in your application providers. Pass the client options (apiKey / token, account, baseUrl) — or a client you created with createClient — and every inject… function uses it.

Parameters

ParameterType
clientOrOptionsClientOptions | SpeechineerClient

Returns

EnvironmentProviders

Example

ts
// app.config.ts
import { provideSpeechineer } from "@speechineer/angular";

export const appConfig: ApplicationConfig = {
  providers: [provideSpeechineer({ apiKey: environment.speechineerKey })],
};

injectSpeechineer()

ts
function injectSpeechineer(): SpeechineerClient;

The client provideSpeechineer registered — for the rare case where you want to create a session yourself (client.speechToForm(...)) instead of using an inject function. Call it in an injection context (a constructor or a field initializer).

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.

InjectSpeechToFormOptions

The options of injectSpeechToForm: the session options every framework shares, plus an optional client to use instead of the provided one.

Extends

  • SpeechToFormOptions

Properties

PropertyTypeDescription
client?SpeechineerClientUse this client instead of the one provideSpeechineer registered.
onSessionStart?(sessionId) => voidFires 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) => voidThe 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) => voidEverything Speechineer reports for this session, at every level, failures included. One stream for logging or a live status display. event.level tells you what you have: 'error' means the session is over, and the other three are advisory. If you only want one level, take the matching hook below instead.
onError?(error) => voidSomething 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. Branch on error.code for the exact cause, or on the error's class (SpeechineerQuotaError, SpeechineerRuntimeError, …) to handle a whole family at once. Fires once per failure, so one rejected request reporting several problems calls this several times — the same list you can read as errors in the session state.
onWarning?(notice) => voidSomething did not go as asked, but the session carried on — a setting Speechineer could not honour, a connection it refused, a component that had to retry. Worth surfacing or logging; never fatal.
onInfo?(notice) => voidA step worth reporting — a phase of the work starting or finishing.
onDebug?(notice) => voidTrace-level detail, for diagnosing an integration. Only arrives if the session is running at debug; otherwise Speechineer never sends it, so this stays silent rather than being filtered here.
onFieldValue?(fieldId, value) => voidOne 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) => voidThe transcript so far — the full accumulated text, not just the newest words, so you can render it directly without stitching updates together.
formFormDefinitionWhich form to fill: the one configured in Speechineer, or one defined right here.
spokenLanguage?stringThe 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?booleanAlso 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?AccountThe 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.
uiLanguage?"en" | "de"The language to show this session's messages in, when it differs from the client's uiLanguage. It travels with the session, so every userMessage arrives already translated. Setting it again later — on start() after a stop, which re-seeds the session — switches the language from that point on; leaving it unset leaves the session in whatever language it was already running in.

InjectSpeechToFormResult

ts
type InjectSpeechToFormResult = SpeechToFormSession & SessionSignals;

What injectSpeechToForm returns: the session (start, stop, end, …) plus its state as signals.


injectSpeechToForm()

ts
function injectSpeechToForm(options): InjectSpeechToFormResult;

Fill a form by voice. Call it in an injection context; the session is released with the component. Render from the signals (isListening(), values(), …) and drive it with start() / stop() / end().

Pass a plain object when the options never change. Pass a function when they depend on signals: it is re-read whenever those signals change, so callbacks and initialValues follow the component instead of staying at the values they had when the session was created. That matters for initialValues in particular — a session that reconnects sends the values the form holds at that moment, not the ones it started with.

Parameters

Returns

InjectSpeechToFormResult

Example

ts
import { Component } from "@angular/core";
import { injectSpeechToForm, FormField } from "@speechineer/angular";

@Component({
  selector: "talk-to-form",
  template: `
    <button type="button" (click)="voice.isListening() ? voice.stop() : talk()">
      {{ voice.isListening() ? "Stop" : "Talk" }}
    </button>
    <input [value]="voice.values()['patientName'] ?? ''" readonly />
  `,
})
export class TalkToForm {
  readonly voice = injectSpeechToForm({
    form: { source: "inline", key: "patient-intake", version: "1", language: "en",
      fields: [FormField.text("patientName", "Extract the patient full name")] },
  });

  // A template cannot catch, and `start()` rejects when the session cannot open — the
  // same error is in `voice.errors()`, so this only keeps the rejection from going
  // unhandled.
  talk() {
    void this.voice.start().catch(() => {});
  }
}

Capability: Text to form

No recording at all — turn text the user typed or pasted into field values, as often as you like.

InjectTextToFormOptions

The options of injectTextToForm: the session options every framework shares, plus an optional client to use instead of the provided one.

Extends

  • TextToFormOptions

Properties

PropertyTypeDescription
client?SpeechineerClientUse this client instead of the one provideSpeechineer registered.
onSessionStart?(sessionId) => voidFires 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) => voidThe 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) => voidEverything Speechineer reports for this session, at every level, failures included. One stream for logging or a live status display. event.level tells you what you have: 'error' means the session is over, and the other three are advisory. If you only want one level, take the matching hook below instead.
onError?(error) => voidSomething 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. Branch on error.code for the exact cause, or on the error's class (SpeechineerQuotaError, SpeechineerRuntimeError, …) to handle a whole family at once. Fires once per failure, so one rejected request reporting several problems calls this several times — the same list you can read as errors in the session state.
onWarning?(notice) => voidSomething did not go as asked, but the session carried on — a setting Speechineer could not honour, a connection it refused, a component that had to retry. Worth surfacing or logging; never fatal.
onInfo?(notice) => voidA step worth reporting — a phase of the work starting or finishing.
onDebug?(notice) => voidTrace-level detail, for diagnosing an integration. Only arrives if the session is running at debug; otherwise Speechineer never sends it, so this stays silent rather than being filtered here.
onFieldValue?(fieldId, value) => voidOne 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.
formFormDefinitionWhich 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?AccountThe end user this session is for, when it differs from the client's default account. Ignored when the client authenticates with a signed token.
uiLanguage?"en" | "de"The language to show this session's messages in, when it differs from the client's uiLanguage. It travels with the session, so every userMessage arrives already translated. Setting it again later switches the language from that point on; leaving it unset leaves the session in whatever language it was already running in.

InjectTextToFormResult

ts
type InjectTextToFormResult = TextToFormSession & SessionSignals;

What injectTextToForm returns: the session (extract, start, end, …) plus its state as signals.


injectTextToForm()

ts
function injectTextToForm(options): InjectTextToFormResult;

Extract field values from text. Call it in an injection context; extract(text) opens the session on first use and merges every result into values().

As with injectSpeechToForm, pass a function instead of a plain object when the options depend on signals and should follow the component.

Parameters

ParameterType
options| InjectTextToFormOptions | (() => InjectTextToFormOptions)

Returns

InjectTextToFormResult

Session state

The state as signals — one per field you typically render.

SessionSignals

The session state as signals — the same shape every framework reports, one signal per field you typically render, plus state for the whole object.

Properties

PropertyTypeDescription
stateSignal<SessionState>The whole state object as a signal; it updates on every change.
statusSignal<SessionStatus>Where the session is in its life.
sessionIdSignal<string | null>The id of the running session, or null.
errorsSignal<readonly SpeechineerError[]>Everything that has failed, root cause first — empty when nothing has. Read errors()[0] for the cause to show.
requestIdSignal<string | null>The id of the most recent answer, or null — quote it when reporting a problem.
valuesSignal<Readonly<Record<string, unknown>>>The latest recognized value of every field, keyed by field id.
transcriptSignal<string>The spoken text so far.
isListeningSignal<boolean>The microphone is on and audio is being sent.
isConnectingSignal<boolean>The session or one of its connections is being established.
isEndingSignal<boolean>The session is being finished, or the microphone is winding down.