Classes
Soniox Client SDK — Class Reference
SonioxClient
Main entry point for the Soniox client SDK.
Example
permissions
Permission resolver, if configured.
Returns undefined if no resolver was provided (SSR-safe).
Example
Returns
PermissionResolver | undefined
Constructor
Parameters
| Parameter | Type |
|---|---|
options | SonioxClientOptions |
Returns
SonioxClient
Properties
| Property | Type | Description |
|---|---|---|
realtime | { record: (options) => Recording; stt: (config, options) => RealtimeSttSession; } | Real-time API namespace |
realtime.record | (options) => Recording | Start a high-level recording session. Returns synchronously so callers can attach event listeners before any async work (key fetch, mic access, connection) begins. |
realtime.stt | (config, options) => RealtimeSttSession | Create a low-level STT session |
Recording
High-level recording orchestrator
Manages the lifecycle of audio capture and real-time transcription:
- Starts audio source immediately (buffers chunks)
- Resolves the API key (from string or async function)
- Connects to the Soniox WebSocket API
- Drains buffered audio, then pipes live audio to the session
Example
state
Current recording state
Returns
cancel()
Immediately cancel recording without waiting for final results
Returns
void
finalize()
Request the server to finalize current non-final tokens.
Parameters
| Parameter | Type |
|---|---|
options? | { trailing_silence_ms?: number; } |
options.trailing_silence_ms? | number |
Returns
void
off()
Remove an event handler
Type Parameters
| Type Parameter |
|---|
E extends keyof RecordingEvents |
Parameters
| Parameter | Type |
|---|---|
event | E |
handler | RecordingEvents[E] |
Returns
this
on()
Register an event handler
Type Parameters
| Type Parameter |
|---|
E extends keyof RecordingEvents |
Parameters
| Parameter | Type |
|---|---|
event | E |
handler | RecordingEvents[E] |
Returns
this
once()
Register a one-time event handler
Type Parameters
| Type Parameter |
|---|
E extends keyof RecordingEvents |
Parameters
| Parameter | Type |
|---|---|
event | E |
handler | RecordingEvents[E] |
Returns
this
pause()
Pause recording.
Pauses the audio source (stops microphone capture) and pauses the session (activates automatic keepalive to prevent server disconnect).
Returns
void
resume()
Resume recording after pause.
Resumes the audio source and session. Audio capture and transmission continue from where they left off.
Returns
void
stop()
Gracefully stop recording
Stops the audio source and waits for the server to process all buffered audio and return final results.
Returns
Promise<void>
Promise that resolves when the server acknowledges completion
MicrophoneSource
Browser microphone audio source
Uses navigator.mediaDevices.getUserMedia to capture audio from the microphone
and MediaRecorder to encode it into chunks.
Example
Constructor
Parameters
| Parameter | Type |
|---|---|
options | MicrophoneSourceOptions |
Returns
MicrophoneSource
pause()
Pause audio capture
Returns
void
resume()
Resume audio capture
Returns
void
start()
Request microphone access and start recording
Parameters
| Parameter | Type |
|---|---|
handlers | AudioSourceHandlers |
Returns
Promise<void>
Throws
AudioUnavailableError if getUserMedia or MediaRecorder is not supported
Throws
AudioPermissionError if microphone access is denied
Throws
AudioDeviceError if no microphone is found
stop()
Stop recording and release all resources
Returns
void
BrowserPermissionResolver
Browser permission resolver for checking and requesting microphone access.
Example
Constructor
Returns
BrowserPermissionResolver
check()
Check current microphone permission status without prompting the user.
Parameters
| Parameter | Type |
|---|---|
permission | "microphone" |
Returns
Promise<PermissionResult>
request()
Request microphone permission from the user. This may show a browser permission prompt.
Parameters
| Parameter | Type |
|---|---|
permission | "microphone" |
Returns
Promise<PermissionResult>
AudioPermissionError
Thrown when microphone access is denied by the user or blocked by the browser.
Maps to getUserMedia NotAllowedError DOMException.
Extends
SonioxError
toJSON()
Converts to a plain object for logging/serialization
Returns
Record<string, unknown>
Inherited from
toString()
Creates a human-readable string representation
Returns
string
Inherited from
Properties
| Property | Type | Description |
|---|---|---|
cause | unknown | The underlying error that caused this error, if any. |
code | | SonioxErrorCode | string & { } | Error code describing the type of error. Typed as string at the base level to allow subclasses (e.g. HTTP errors) to use their own error code unions. |
statusCode | number | undefined | HTTP status code when applicable (e.g., 401 for auth errors, 500 for server errors). |
AudioDeviceError
Thrown when no audio input device is found
Maps to getUserMedia NotFoundError DOMException.
Extends
SonioxError
toJSON()
Converts to a plain object for logging/serialization
Returns
Record<string, unknown>
Inherited from
toString()
Creates a human-readable string representation
Returns
string
Inherited from
Properties
| Property | Type | Description |
|---|---|---|
cause | unknown | The underlying error that caused this error, if any. |
code | | SonioxErrorCode | string & { } | Error code describing the type of error. Typed as string at the base level to allow subclasses (e.g. HTTP errors) to use their own error code unions. |
statusCode | number | undefined | HTTP status code when applicable (e.g., 401 for auth errors, 500 for server errors). |
AudioUnavailableError
Thrown when audio capture is not supported in the current environment
For example, when getUserMedia or MediaRecorder is not available.
Extends
SonioxError
toJSON()
Converts to a plain object for logging/serialization
Returns
Record<string, unknown>
Inherited from
toString()
Creates a human-readable string representation
Returns
string
Inherited from
Properties
| Property | Type | Description |
|---|---|---|
cause | unknown | The underlying error that caused this error, if any. |
code | | SonioxErrorCode | string & { } | Error code describing the type of error. Typed as string at the base level to allow subclasses (e.g. HTTP errors) to use their own error code unions. |
statusCode | number | undefined | HTTP status code when applicable (e.g., 401 for auth errors, 500 for server errors). |