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(), error(), …). 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) => voidEvery status event Speechineer emits for this session — progress, warnings, and failures alike. Use it for logging or a live status display.
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. Read error.code to branch and error.recoverable to decide whether to offer a retry.
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.

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() : voice.start()">
      {{ 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")] },
  });
}

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) => voidEvery status event Speechineer emits for this session — progress, warnings, and failures alike. Use it for logging or a live status display.
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. Read error.code to branch and error.recoverable to decide whether to offer a retry.
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.

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.
errorSignal<SpeechineerError | null>The last error, or null.
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.