API reference

@speechineer/js

The configuration and data types every Speechineer package shares. Whichever package you install, these are the same: how you configure the client, how you describe the form to fill, the callbacks that deliver values and progress, the errors and events that report problems, and the state every session reports.

The package for your framework documents its own functions; everything those functions' options are built from is described here, once.

Setup

Create the client once, at app startup, with your credentials — every session starts from it. Without a baseUrl it talks to the production Speechineer API.

SpeechineerClient

Your connection to Speechineer. Create one with createClient and keep it for the lifetime of your app; every session starts from it.

Methods

speechToForm()

ts
speechToForm(options): SpeechToFormSession;

Fill a form by voice. Returns the session; call start() on it when the user is ready to speak. In React and Angular use useSpeechToForm / injectSpeechToForm instead — they take the same options and manage the session for you.

Parameters

ParameterType
optionsSpeechToFormOptions

Returns

SpeechToFormSession

textToForm()

ts
textToForm(options): TextToFormSession;

Extract field values from text — no microphone involved. Returns the session; call extract(text) as often as you like. In React and Angular use useTextToForm / injectTextToForm.

Parameters

ParameterType
optionsTextToFormOptions

Returns

TextToFormSession

Properties

PropertyTypeDescription
baseUrlstringThe API root this client talks to (no trailing slash).
uiLanguage?"en" | "de"The language people are shown messages in, as the app asked for it — undefined when it did not. Deliberately not defaulted here. It travels to Speechineer as the session's language, and sending nothing is meaningful: Speechineer then negotiates from the browser's Accept-Language, which is a better answer than any guess this SDK could make (the header can say de-CH,de;q=0.9 while navigator.language says en-US). A session overrides it with its own uiLanguage. The SDK's own handful of messages still need a concrete language even when this is undefined — see negotiateSdkLanguage, which is the fallback for those only.

ClientOptions

How the SDK reaches Speechineer and on whose behalf. Pass it once to createClient (or to the React provider / Angular provideSpeechineer).

Fill in one of the two credential styles:

  • apiKey (+ account) — for an Unsigned API key. The SDK builds the token for you. Convenient for development, but the key is readable in your frontend.
  • token — for a Signed API key. Your server signs a short-lived token per user and you hand it over (a string, or a function that fetches one); the SDK forwards it untouched, because signing requires a private key that must never reach the browser. Use this in production.

Properties

PropertyTypeDescription
baseUrl?stringThe Speechineer API root, without a trailing slash. Defaults to the production API — set it only to target another environment.
apiKey?stringThe API key of the workspace this app belongs to. Unsigned mode only — with a signed token the key travels inside the token.
token?string | TokenProviderA 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?AccountThe end user sessions are for, unless a session says otherwise. Required with apiKey; ignored with token (the token carries the account).
uiLanguage?"en" | "de"The language to show people messages in — 'en' or 'de', defaulting to English. It reaches two places. Every userMessage Speechineer sends is already translated into it, because the language travels with the session; and the handful of messages the SDK writes itself (a denied microphone, an unreachable service) are rendered in it too. Developer messages stay English, since they are for you. Set it once here and every session follows. If you do not, Speechineer falls back to the browser's Accept-Language and then to English.

DEFAULT_BASE_URL

ts
const DEFAULT_BASE_URL: "https://ai.speechineer.com/api" = 'https://ai.speechineer.com/api';

Where the SDK sends its requests unless createClient({ baseUrl }) says otherwise — the production Speechineer API.


createClient()

ts
function createClient(options?): SpeechineerClient;

Create the client once, at app startup, and create every session from it.

Parameters

ParameterType
optionsClientOptions

Returns

SpeechineerClient

Example

ts
import { createClient } from "@speechineer/js";

// Development — an unsigned workspace key + who the end user is:
const speechineer = createClient({ apiKey: "spnr_live_…", account: { key: user.id } });

// Production — your server signs a short-lived token per user:
const speechineer = createClient({ token: () => fetch("/api/speechineer-token").then((r) => r.text()) });

Authentication

Who is calling: your workspace's API key plus an identifier for the end user, or a token your server signed (a string, or a function that fetches a fresh one).

Account

The end user a session is for. Usage and per-account limits are tracked against it, so avoid one shared value for everybody.

Properties

PropertyTypeDescription
keystringA stable id for the end user — your own user id works well.
pseudonym?stringAn optional readable label for that account, shown in your workspace instead of the raw id (for example a team or desk name).

TokenProvider

ts
type TokenProvider = () => string | Promise<string>;

Returns a token your server signed for the current user — called every time a session is created or resumed, so a fresh, short-lived token is always used.

Returns

string | Promise<string>

Forms

Which form to fill and where its definition lives: configured in Speechineer (a workspace form — your code names it) or defined in your code (an inline form — fields, prompts, and model configurations ship with the call).

FormIdentity

The identity every form carries, whichever side defines it.

Extended by

Properties

PropertyTypeDescription
keystringThe form's key. For a workspace form: the key shown in Speechineer. For an inline form: your own stable identifier — Speechineer records the form under it so usage is attributed and limited like any other form.
versionstringWhich version of that form. Pin it: your integration keeps working while a new version is drafted, and you move over when ready.
languagestringThe language of the form definition itself — the field labels and prompts (for example 'en', 'de'). Independent of the language the user speaks.

WorkspaceForm

A form configured in Speechineer. Your code names it, and the fields, prompts and models come from your workspace — change them there without shipping a release. Individual fields can be marked in your workspace as set by code, and those arrive through fieldConfigs.

Extends

Properties

PropertyTypeDescription
keystringThe form's key. For a workspace form: the key shown in Speechineer. For an inline form: your own stable identifier — Speechineer records the form under it so usage is attributed and limited like any other form.
versionstringWhich version of that form. Pin it: your integration keeps working while a new version is drafted, and you move over when ready.
languagestringThe language of the form definition itself — the field labels and prompts (for example 'en', 'de'). Independent of the language the user speaks.
source"workspace"The definition lives in your Speechineer workspace.
fieldConfigs?FieldSpec[]Configuration for the fields your form marks as set by your code — a choice field whose options come from your own data, for example. Build each one with FormFieldConfig, giving it the same field id it has in your workspace. Only the marked fields are read from here, and one of them missing stops the session from starting. Every other field keeps the definition it has in your workspace.

Prompts

The prompts an inline form supplies, one per slot: how to transcribe, and how to extract the field values. Each is plain-language instruction text. Omit a slot to use the default.

Properties

PropertyTypeDescription
transcription?stringGuidance for the transcription step (vocabulary, domain, style).
extraction?stringGuidance for turning the transcript into field values.

Models

The model configurations an inline form pins, one per slot, by the keys you gave them in your workspace. Omit a slot to use the workspace default.

Properties

PropertyTypeDescription
transcription?stringThe model configuration key for transcription.
extraction?stringThe model configuration key for extraction.

InlineForm

A form defined in your code: you declare the fields to extract (build them with FormField) and, optionally, the prompts and model configurations to use. Speechineer records it under key / version in your workspace.

Extends

Properties

PropertyTypeDescription
keystringThe form's key. For a workspace form: the key shown in Speechineer. For an inline form: your own stable identifier — Speechineer records the form under it so usage is attributed and limited like any other form.
versionstringWhich version of that form. Pin it: your integration keeps working while a new version is drafted, and you move over when ready.
languagestringThe language of the form definition itself — the field labels and prompts (for example 'en', 'de'). Independent of the language the user speaks.
source"inline"The definition lives in your code.
fieldsFieldSpec[]Fields to extract — build with FormField.
prompts?PromptsCustom prompts per slot.
models?ModelsModel configurations per slot, by workspace key.

FormDefinition

ts
type FormDefinition = WorkspaceForm | InlineForm;

Where the form comes from: the one configured in Speechineer (source: 'workspace') or the one your code defines (source: 'inline'). Every capability that fills a form takes one of these as form.

Fields

What to extract and how to describe it. Build each field of an inline form with FormField; the prompt is the instruction Speechineer follows for that field.

OptionsFieldConfig

The allowed options of a choice field (select / multiselect).

Properties

PropertyTypeDescription
kind"options"Marks the options configuration.
optionsstring[]The values the user may choose from.
appendOptionsToPrompt?booleanAppend the options to the prompt so the extraction sees them as part of the instruction.

RangeFieldConfig

The [min, max] range of a slider field.

Properties

PropertyTypeDescription
kind"range"Marks the range configuration.
range[number, number]The lowest and highest value allowed.

FieldSpec

One field to extract. Build these with FormField rather than by hand — the factory picks the right type and validates the options for you.

Properties

PropertyTypeDescription
idstringYour id for the field. It comes back with every value — in values and in onFieldValue.
promptstringWhat to extract, in plain language — "Extract the patient's full name". This instruction is what makes the difference between a good and a poor result, so be specific about the value you want.
typeFieldTypeThe kind of value expected, which also shapes how it is normalized.
config?FieldConfigExtra rules for types that need them: the options of a choice, or a slider range.

FieldFactory

The field factory surface. Every helper returns a ready FieldSpec.

Methods

text()

ts
text(id, prompt): FieldSpec;

Free-form text.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

textarea()

ts
textarea(id, prompt): FieldSpec;

Multi-line free-form text; same value semantics as text.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

email()

ts
email(id, prompt): FieldSpec;

An email address.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

phone()

ts
phone(id, prompt): FieldSpec;

A phone number.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

url()

ts
url(id, prompt): FieldSpec;

A URL.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

integer()

ts
integer(id, prompt): FieldSpec;

A whole number.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

float()

ts
float(id, prompt): FieldSpec;

A decimal number.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

checkbox()

ts
checkbox(id, prompt): FieldSpec;

A yes/no value.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

date()

ts
date(id, prompt): FieldSpec;

A calendar date.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

time()

ts
time(id, prompt): FieldSpec;

A time of day.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

datetime()

ts
datetime(id, prompt): FieldSpec;

A date with a time.

Parameters

ParameterType
idstring
promptstring

Returns

FieldSpec

slider()

ts
slider(
   id, 
   prompt, 
   range): FieldSpec;

Ranged numeric field; range is [min, max] with min < max.

Parameters

ParameterType
idstring
promptstring
range[number, number]

Returns

FieldSpec

select()

ts
select(
   id, 
   prompt, 
   options, 
   appendOptionsToPrompt?): FieldSpec;

Single-choice; options must be non-empty.

Parameters

ParameterType
idstring
promptstring
optionsstring[]
appendOptionsToPrompt?boolean

Returns

FieldSpec

multiselect()

ts
multiselect(
   id, 
   prompt, 
   options, 
   appendOptionsToPrompt?): FieldSpec;

Multi-choice; options must be non-empty.

Parameters

ParameterType
idstring
promptstring
optionsstring[]
appendOptionsToPrompt?boolean

Returns

FieldSpec


FieldConfigFactory

The factory surface for configuring a workspace form's code-defined fields. Only the three types that take a configuration appear here — the rest have nothing for code to supply.

Methods

slider()

ts
slider(id, range): FieldSpec;

Ranged numeric field; range is [min, max] with min < max.

Parameters

ParameterType
idstring
range[number, number]

Returns

FieldSpec

select()

ts
select(
   id, 
   options, 
   appendOptionsToPrompt?): FieldSpec;

Single-choice; options must be non-empty.

Parameters

ParameterType
idstring
optionsstring[]
appendOptionsToPrompt?boolean

Returns

FieldSpec

multiselect()

ts
multiselect(
   id, 
   options, 
   appendOptionsToPrompt?): FieldSpec;

Multi-choice; options must be non-empty.

Parameters

ParameterType
idstring
optionsstring[]
appendOptionsToPrompt?boolean

Returns

FieldSpec


FieldConfig

ts
type FieldConfig = 
  | OptionsFieldConfig
  | RangeFieldConfig;

The extra configuration a field type may carry: the allowed options of a choice field, or the range of a slider.


FieldType

ts
type FieldType = 
  | "text"
  | "textarea"
  | "email"
  | "phone"
  | "url"
  | "integer"
  | "float"
  | "slider"
  | "checkbox"
  | "select"
  | "multiselect"
  | "date"
  | "time"
  | "datetime"
  | "template";

FIELD_TYPES

ts
const FIELD_TYPES: readonly ["text", "textarea", "email", "phone", "url", "integer", "float", "slider", "checkbox", "select", "multiselect", "date", "time", "datetime"];

The field types you can declare, in presentation order. Use it to build a type picker without redeclaring the list.


FormField

ts
const FormField: FieldFactory;

Build the fields of an inline form. A factory object (no new, tree-shakeable) producing FieldSpecs, with light runtime validation for the config-bearing types.

Example

ts
import { FormField } from "@speechineer/js"; // also exported by @speechineer/react and @speechineer/angular

const fields = [
  FormField.text("patientName", "Extract the patient full name"),
  FormField.integer("age", "Extract the age in years"),
  FormField.select("species", "Extract the species", ["Canine", "Feline", "Equine"]),
  FormField.slider("painLevel", "Extract the pain level", [0, 10]),
];

FormFieldConfig

ts
const FormFieldConfig: FieldConfigFactory;

Configure the fields your workspace form marks as set by your code — a choice field whose options come from your own data, for example. Pass the results as the form's fields.

Same validation as FormField, without the prompt: what to extract is already written in your workspace, so only the field id and the configuration come from here.

Example

ts
import { FormFieldConfig } from "@speechineer/js"; // also exported by @speechineer/react and @speechineer/angular

const form = {
  source: "workspace",
  key: "intake",
  version: "1",
  language: "en",
  fields: [FormFieldConfig.select("species", await loadSpeciesFromMyDatabase())],
} as const;

Callbacks

Optional hooks for imperative integrations. Everything they report — values, the transcript, events, errors — is also in the session state.

SessionCallbacks

The callbacks every session accepts. All of them are optional: a session runs without any, and you add the ones your integration reacts to. Everything they report is also visible in the session state, so a UI that renders from the state needs none of them.

Properties

PropertyTypeDescription
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.

FormValueCallbacks

Field-value callbacks, added by every capability that fills a form. Optional — the latest value of every field is always available as values in the session state; use the callback to push values into a form library imperatively.

Properties

PropertyTypeDescription
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.

TranscriptCallbacks

Transcript callbacks, added by every capability that returns the spoken text. Optional — the transcript so far is always available as transcript in the session state.

Properties

PropertyTypeDescription
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.

Events and errors

What you receive when something noteworthy or fatal happens during a session: a typed error with a stable code, and the stream of status events.

SpeechineerClientError

Your app's own mistake, caught before anything was sent — missing credentials, an action before start(), or a microphone the browser would not give up.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerAuthError

The credentials were missing, malformed, expired, or rejected.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerQuotaError

A usage allowance is spent. meta carries the ceiling that bound and how much of it was used — see QuotaMeta.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerAccessError

The credentials are valid but not allowed to do this.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerNotFoundError

Something named in the request does not exist — a form, a version, or a session whose id answers to nothing because it was never created or has long since ended and been swept.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerConflictError

The request conflicts with the current state — for example an action whose prerequisite has not happened yet.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerValidationError

The request was not acceptable. When several things are wrong at once you get one error per cause in state.errors, so a rejected form tells you everything in one round trip.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerMethodError

The path is right but the HTTP method is not one it accepts. A mistake in how the request was built, not in what it asked for.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerNotAcceptableError

Nothing that can be returned matches the Accept header the request sent.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerTooLargeError

The request body is larger than the endpoint will read. Send less, or send it in parts.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerUnsupportedMediaError

The body's content type is not one the endpoint reads. The body itself may be perfectly well-formed — it is the type that is not supported.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerRateLimitError

Too many requests. Slow down and retry.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerRuntimeError

A running session stopped because something failed — transcription or field extraction could not be restarted. The session is over; offer the user a fresh start.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerServiceError

Speechineer could not handle the request, for a reason that is not your app's doing. Retrying the same request may work.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerUpstreamError

A service Speechineer depends on answered with something unusable. Retrying the same request the same way is unlikely to help.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerUnavailableError

Speechineer is temporarily unreachable. Nothing is wrong with your request — retry later.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

SpeechineerTimeoutError

The request took too long to complete. Retrying is reasonable.

Extends

Properties

PropertyTypeDescription
level"error"Always 'error': a failure is the terminal level, by definition.
typestringThe category. Prefer catching the matching subclass over comparing this yourself.
codestringA stable identifier for what went wrong. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
metaRecord<string, unknown> | nullData belonging to this failure — the shape depends on code.
cause?unknownThe underlying failure, when there was one.
namestringThe class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.
messagestringFor you, in English: what went wrong and what to do about it. Log this one.
stack?stringWhere the failure was raised, when the browser provides it.

QuotaMeta

The meta a SpeechineerQuotaError carries: the allowance that bound, and how much of it was used.

The amounts are decimal strings, not numbers — usage is metered in fractional units and a JSON number would round them.

Properties

PropertyTypeDescription
limitstringThe ceiling that bound.
usedstringHow much of it had been used.
remainingstringWhat was left.
layerstringWhich allowance bound — for example an account's monthly budget.

SpeechineerEvent

Anything Speechineer reports, at any level — a failure, a warning, a progress note.

This is what onEvent receives, so it is the one shape worth learning. level is the terminality: 'error' means the session is over and nothing else does, so you never have to inspect a code to find out whether you can keep going.

Extended by

Properties

PropertyTypeDescription
level"debug" | "info" | "warning" | "error"'error' means the session ended. The other three are advisory.
typestringThe category — handle a whole family at once without enumerating codes.
codestringA stable identifier for what happened. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
messagestringFor you: what happened and what to do about it. Belongs in your logs.
metaRecord<string, unknown> | nullData belonging to this particular event — the shape depends on code.

SessionNotice

One thing that happened while the session kept running — delivered to onWarning, onInfo or onDebug, and to onEvent along with everything else.

Notices are advisory by definition: a connection re-establishing itself, a setting the service could not honour as asked, a stage of the work finishing. Anything that ends the session is not a notice — it arrives as a SpeechineerError through onError and state.errors.

Identical to SpeechineerEvent but for the narrower level; it adds no fields, because the event is the whole report.

Extends

Properties

PropertyTypeDescription
typestringThe category — handle a whole family at once without enumerating codes.
codestringA stable identifier for what happened. Branch on this, not on a message.
userMessagestringFor the person using your app, in the session's language. Show this one.
messagestringFor you: what happened and what to do about it. Belongs in your logs.
metaRecord<string, unknown> | nullData belonging to this particular event — the shape depends on code.
level"debug" | "info" | "warning"Never 'error' — a notice that ended the session would be a contradiction.

SpeechineerErrorCode

ts
type SpeechineerErrorCode = 
  | keyof typeof SDK_ERRORS
  | string & {
};

A stable identifier for what went wrong.

The union lists what this version knows about but stays open on purpose: Speechineer can name a new failure without every app upgrading first, so the type must not claim the list is closed.


EventLevel

ts
type EventLevel = LevelSdk;

How severe something is — and, for error, that the session is over.

There is no critical: nothing ever emitted one, and it named a severity no handler treated differently from error.


SDK_ERROR_CODES

ts
const SDK_ERROR_CODES: readonly (
  | "NO_AUTH"
  | "NO_ACCOUNT"
  | "NO_CLIENT"
  | "NO_SESSION"
  | "MICROPHONE_DENIED"
  | "MICROPHONE_UNAVAILABLE"
  | "AUDIO_UNSUPPORTED"
  | "NETWORK"
  | "UNKNOWN"
  | "REQUEST_FAILED")[];

The codes the SDK names itself, as opposed to the ones Speechineer sends.

Useful for telling the two apart — "did this request even leave the browser?" is a different question from "what did Speechineer say?", and it changes what you do about it. A code in this list means nothing was sent: a missing credential, a denied microphone, a browser that cannot record. The one exception is REQUEST_FAILED, which means Speechineer was reached but answered in a shape that carried no code of its own.

Example

ts
import { SDK_ERROR_CODES } from "@speechineer/js";

onError: (error) => {
  const isLocal = (SDK_ERROR_CODES as readonly string[]).includes(error.code);
  if (isLocal) showSetupHint(error);
  else reportToSupport(error.code, session.getState().requestId);
};

SpeechineerError

Something Speechineer could not do. The session is over.

Branch on code — it is stable — or catch a subclass to handle a whole category at once (SpeechineerQuotaError covers every way an allowance can run out).

Two messages, for two readers. userMessage is written for the person using your app and arrives already translated into the session's language — show that one. message is written for you: it says what to do about the failure, and belongs in your logs rather than on screen.

It is also a SpeechineerEvent with level: 'error', which is why onEvent can receive failures and notices alike.

Extends

  • Error

Extended by

Implements

Constructors

Constructor

ts
new SpeechineerError(options): SpeechineerError;

Parameters

ParameterType
optionsSpeechineerErrorOptions

Returns

SpeechineerError

Overrides

ts
Error.constructor

Properties

level

ts
readonly level: "error";

Always 'error': a failure is the terminal level, by definition.

Implementation of

SpeechineerEvent.level

type

ts
readonly type: string;

The category. Prefer catching the matching subclass over comparing this yourself.

Implementation of

SpeechineerEvent.type

code

ts
readonly code: string;

A stable identifier for what went wrong. Branch on this, not on a message.

Implementation of

SpeechineerEvent.code

userMessage

ts
readonly userMessage: string;

For the person using your app, in the session's language. Show this one.

Implementation of

SpeechineerEvent.userMessage

meta

ts
readonly meta: Record<string, unknown> | null;

Data belonging to this failure — the shape depends on code.

Implementation of

SpeechineerEvent.meta

cause?

ts
readonly optional cause?: unknown;

The underlying failure, when there was one.

name

ts
readonly name: string;

The class name — "SpeechineerQuotaError" and so on. Prefer code or a catch by class.

Overrides

ts
Error.name

message

ts
readonly message: string;

For you, in English: what went wrong and what to do about it. Log this one.

Implementation of

SpeechineerEvent.message

Overrides

ts
Error.message

stack?

ts
readonly optional stack?: string;

Where the failure was raised, when the browser provides it.

Overrides

ts
Error.stack

Session state

What a running session reports about itself — its lifecycle, its id, the last error, the latest values, the transcript, whether it is listening, and whether each of its connections is open. The same shape in every framework: read it, subscribe to it, render from it.

ConnectionState

The state of one connection.

Properties

PropertyType
statusConnectionStatus

SessionState

Everything a session reports about itself. Read it with getState(), receive it through subscribe / onStateChange, or — in React and Angular — take it from the hook / inject result. Render your UI from it. The object is immutable — every change produces a new one — so it is safe to compare by reference.

Properties

PropertyTypeDescription
statusSessionStatusWhere the session is in its life — see SessionStatus.
sessionIdstring | nullThe id of the running session, or null before it exists.
errorsreadonly SpeechineerError[]Everything that has failed, root cause first — empty when nothing has. A single request can report several problems at once (a rejected form names every offending field), and a session that ends reports the one failure that ended it. Read errors[0] for the cause to show; the rest is the context it arrived with. Cleared when the next start() succeeds.
requestIdstring | nullThe id of the most recent answer, or null. Quote it when reporting a problem: the same id follows the request through every part of Speechineer that handled it.
connectionsSessionConnectionsThe status of each connection: session always, the others when the capability uses them.
valuesReadonly<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.
transcriptstringThe spoken text so far (the full accumulated transcript), or '' when the session does not stream it.
isListeningbooleanThe microphone is on and audio is being sent.
isConnectingbooleanThe session or one of its connections is being established.
isEndingbooleanThe session is being finished (end()), or the microphone is winding down after stop().

SessionStatus

ts
type SessionStatus = "idle" | "starting" | "active" | "recovering" | "ending" | "failed";

Where the session is in its life.

  • idle — nothing started yet (or the session was ended).
  • starting — the session is being created and its connection opened.
  • active — the session exists; isListening and connections tell you what it is doing.
  • recovering — the session vanished on the server and is being resumed.
  • ending — end() is discarding the session.
  • failed — the session is not usable: starting or recovering did not succeed, or a running session ended because something failed (a crash, a spent allowance). See errors; errors[0].code says which. start() may be called again.

ConnectionStatus

ts
type ConnectionStatus = "closed" | "connecting" | "open" | "closing";

Whether one connection of the session is open. closing is reported by the microphone connection between stop() and the moment capture has fully wound down.


ConnectionKey

ts
type ConnectionKey = "session" | "audio" | "results" | "transcript";

The connections a session may have. session is the main connection every session has — when it is lost, every other connection is closed as well. audio carries the microphone, results the recognized values, transcript the spoken text. A session only lists the connections its capability uses.


SessionConnections

ts
type SessionConnections = {
  session: ConnectionState;
} & Readonly<Partial<Record<Exclude<ConnectionKey, "session">, ConnectionState>>>;

The connections of a session: session always, the others only when the capability uses them.

Type Declaration

NameType
sessionConnectionState

Type Aliases

SdkLanguage

ts
type SdkLanguage = typeof SDK_LANGUAGES[number];

A language the SDK can speak.

Variables

SDK_LANGUAGES

ts
const SDK_LANGUAGES: readonly ["en", "de"];

The languages the SDK can render its own sentences in. The service translates its own.


DEFAULT_SDK_LANGUAGE

ts
const DEFAULT_SDK_LANGUAGE: SdkLanguage = 'en';

The language used when nothing else answers — the same fallback the service ends on.