Types
Soniox Client SDK — Types Reference
ApiKeyConfig
API key configuration.
string- A pre-fetched temporary API key (e.g., injected from SSR)() => Promise<string>- An async function that fetches a fresh temporary key from your backend. Called once per recording session.
Example
Note: If you use Node.js, you can use the SonioxNodeClient to fetch a temporary API key via client.auth.createTemporaryKey().
AudioErrorCode
Error codes for audio-related errors
AudioSourceHandlers
Callbacks for receiving audio data and errors from an AudioSource.
Properties
| Property | Type | Description |
|---|---|---|
onData | (chunk) => void | Called when an audio chunk is available. |
onError | (error) => void | Called when a runtime error occurs during audio capture (after start). |
onMuted? | () => void | Called when the audio source is muted externally (e.g. OS-level or hardware mute). |
onUnmuted? | () => void | Called when the audio source is unmuted after an external mute. |
MicrophoneSourceOptions
Options for MicrophoneSource
Properties
| Property | Type | Description |
|---|---|---|
constraints? | MediaTrackConstraints | MediaTrackConstraints for the audio track. Default { echoCancellation: false, noiseSuppression: false, autoGainControl: false, channelCount: 1, sampleRate: 44100 } |
recorderOptions? | MediaRecorderOptions | MediaRecorder options. See https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder/MediaRecorder |
timesliceMs? | number | Time interval in milliseconds between audio data chunks. Default 60 |
PermissionResult
Result of a permission check or request.
Properties
| Property | Type | Description |
|---|---|---|
can_request | boolean | Whether the user can be prompted again. false means permanently denied (e.g., browser "Block" or iOS settings). Useful for showing "go to settings" instructions. |
status | PermissionStatus | Current permission status. |
PermissionStatus
Unified permission status across all platforms.
PermissionType
Permission types supported by the resolver.
RecordOptions
Options for creating a recording
Type Declaration
| Name | Type | Description |
|---|---|---|
buffer_queue_size? | number | Maximum number of audio chunks to buffer while waiting for key/connection Default 1000 |
session_options? | SttSessionOptions | SDK-level session options (signal, etc.) |
signal? | AbortSignal | AbortSignal for cancellation |
source? | AudioSource | Audio source to use. Defaults to MicrophoneSource if not provided. |
RecordingEvents
Events emitted by a Recording instance
Properties
| Property | Type | Description |
|---|---|---|
connected | () => void | WebSocket connected and ready. |
endpoint | () => void | Endpoint detected (speaker finished talking). |
error | (error) => void | Error occurred during recording. |
finalized | () => void | Finalization complete. |
finished | () => void | Recording finished (server acknowledged end of stream). |
result | (result) => void | Parsed result received from the server. |
source_muted | () => void | Audio source was muted externally (e.g. OS-level or hardware mute). |
source_unmuted | () => void | Audio source was unmuted after an external mute. |
state_change | (update) => void | Recording state transition. |
token | (token) => void | Individual token received. |
RecordingState
Unified recording lifecycle states.
SonioxClientOptions
Options for creating a SonioxClient instance.
Properties
| Property | Type | Description |
|---|---|---|
api_key | ApiKeyConfig | API key configuration. - string - A pre-fetched temporary API key (e.g., injected from SSR) - () => Promise<string> - Async function that fetches a fresh key from your backend |
buffer_queue_size? | number | Default maximum number of audio chunks to buffer while waiting for key/connection. Can be overridden per-recording. Default 1000 |
default_session_options? | SttSessionOptions | Default session options applied to all sessions. Can be overridden per-recording. |
permissions? | PermissionResolver | Optional permission resolver for pre-flight microphone permission checks. Not set by default (SSR-safe, RN-safe). Example import { BrowserPermissionResolver } from '@soniox/client'; const client = new SonioxClient({ api_key: fetchKey, permissions: new BrowserPermissionResolver(), }); |
ws_base_url? | string | WebSocket URL for real-time connections. Default 'wss://stt-rt.soniox.com/transcribe-websocket' |
SttOptions
Options for creating a low-level STT session.
Properties
| Property | Type | Description |
|---|---|---|
api_key | string | Resolved API key string (temporary key). |
session_options? | SttSessionOptions | Session options (signal, etc.). |
AudioSource
Platform-agnostic audio source interface.
Implementations must:
- Begin capturing audio in
start()and deliver chunks viahandlers.onData - Stop all capture and release resources in
stop() - Throw typed errors from
start()if capture cannot begin (e.g., permission denied)
Example
Methods
pause()?
Pause audio capture (optional). When paused, no data should be delivered via onData.
Returns
void
resume()?
Resume audio capture after pause (optional).
Returns
void
start()
Start capturing audio.
Parameters
| Parameter | Type | Description |
|---|---|---|
handlers | AudioSourceHandlers | Callbacks for audio data and errors |
Returns
Promise<void>
Throws
AudioPermissionError if microphone access is denied
Throws
AudioDeviceError if no audio device is found
Throws
AudioUnavailableError if audio capture is not supported
stop()
Stop capturing audio and release all resources. Safe to call multiple times.
Returns
void
PermissionResolver
Platform-agnostic permission resolver.
Implementations handle platform-specific permission APIs:
- Browser:
navigator.permissions.query+getUserMedia - React Native:
expo-avorreact-native-permissions
Example
Methods
check()
Check current permission status WITHOUT prompting the user.
Parameters
| Parameter | Type |
|---|---|
permission | "microphone" |
Returns
Promise<PermissionResult>
request()
Request permission from the user (may show a system prompt). On platforms where status is already 'granted', this is a no-op.
Parameters
| Parameter | Type |
|---|---|
permission | "microphone" |
Returns
Promise<PermissionResult>
resolveApiKey()
Resolves an ApiKeyConfig to a plain API key string.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | ApiKeyConfig | The API key configuration |
Returns
Promise<string>
The resolved API key string
Throws
If the function rejects or returns a non-string value