Helpers
Soniox Python SDK - Helper Functions Reference
output_file_for_audio_format()
Build an output file path with the correct extension for the audio format.
Parameters
| Parameter | Type | Description |
|---|---|---|
audio_format | str | Audio format name (e.g. "wav", "mp3", "pcm_s16le"). |
prefix | str | Filename prefix without extension. The chosen extension is appended to this prefix to form the returned path. |
Returns
Path
render_tokens()
Build a human-friendly transcript from token metadata.
Parameters
| Parameter | Type | Description |
|---|---|---|
final_tokens | list[Token] | Token metadata emitted during realtime streaming transcriptions. |
non_final_tokens | list[Token] | Token metadata emitted during realtime streaming transcriptions. |
Returns
str
start_audio_thread()
Stream audio into the session on a background thread.
Parameters
| Parameter | Type | Description |
|---|---|---|
session | RealtimeSTTSession | Synchronous WebSocket session for a single real-time speech-to-text stream. |
chunks | bytes | Iterator[bytes] | Audio chunks to stream to realtime transcription. |
name | str | None | Name of the model. |
daemon | bool | - |
Returns
threading.Thread
start_text_thread()
Stream text into a realtime TTS session on a background thread.
Parameters
| Parameter | Type | Description |
|---|---|---|
session | RealtimeTTSConnection | RealtimeTTSStream | Synchronous WebSocket connection for one realtime Text-to-Speech stream. |
chunks | str | Iterator[str] | Audio chunks to stream to realtime transcription. |
text_end | bool | Whether this message marks the final text chunk for the stream. |
name | str | None | Name of the model. |
daemon | bool | - |
Returns
threading.Thread
stream_audio()
Yield fixed-size chunks from an audio source.
Supports bytes, file paths, or binary streams and slices them into
chunk_size_bytes blocks for realtime transmission.
Parameters
| Parameter | Type | Description |
|---|---|---|
file | Path | str | BinaryIO | bytes | File input to upload or transcribe. |
chunk_size_bytes | int | - |
Returns
Iterator[bytes]
stream_audio_async()
Asynchronously yield fixed-size chunks from an audio source.
Mirrors stream_audio but produces an async iterator for later consumption.
Parameters
| Parameter | Type | Description |
|---|---|---|
file | Path | str | BinaryIO | bytes | File input to upload or transcribe. |
chunk_size_bytes | int | - |
Returns
AsyncIterator[bytes]
throttle_audio()
Yield audio chunks at a regulated pace, optionally sleeping between yields.
Parameters
| Parameter | Type | Description |
|---|---|---|
file | Path | str | BinaryIO | bytes | File input to upload or transcribe. |
chunk_size_bytes | int | - |
delay_seconds | float | - |
Returns
Iterator[bytes]
throttle_audio_async()
Async counterpart of throttle_audio, yielding chunks with optional delay.
Parameters
| Parameter | Type | Description |
|---|---|---|
file | Path | str | BinaryIO | bytes | File input to upload or transcribe. |
chunk_size_bytes | int | - |
delay_seconds | float | - |
Returns
AsyncIterator[bytes]