OtherSDKsPythonFull SDK reference

Helpers

Soniox Python SDK - Helper Functions Reference


output_file_for_audio_format()

output_file_for_audio_format(audio_format: str, prefix: str) -> Path

Build an output file path with the correct extension for the audio format.

Parameters

ParameterTypeDescription
audio_formatstrAudio format name (e.g. "wav", "mp3", "pcm_s16le").
prefixstrFilename prefix without extension. The chosen extension is appended to this prefix to form the returned path.

Returns

Path


render_tokens()

render_tokens(final_tokens: list[Token], non_final_tokens: list[Token]) -> str

Build a human-friendly transcript from token metadata.

Parameters

ParameterTypeDescription
final_tokenslist[Token]Token metadata emitted during realtime streaming transcriptions.
non_final_tokenslist[Token]Token metadata emitted during realtime streaming transcriptions.

Returns

str


start_audio_thread()

start_audio_thread(session: RealtimeSTTSession, chunks: bytes | Iterator[bytes], *, name: str | None = None, daemon: bool = True) -> threading.Thread

Stream audio into the session on a background thread.

Parameters

ParameterTypeDescription
sessionRealtimeSTTSessionSynchronous WebSocket session for a single real-time speech-to-text stream.
chunksbytes | Iterator[bytes]Audio chunks to stream to realtime transcription.
namestr | NoneName of the model.
daemonbool-

Returns

threading.Thread


start_text_thread()

start_text_thread(session: RealtimeTTSConnection | RealtimeTTSStream, chunks: str | Iterator[str], *, text_end: bool = True, name: str | None = None, daemon: bool = True) -> threading.Thread

Stream text into a realtime TTS session on a background thread.

Parameters

ParameterTypeDescription
sessionRealtimeTTSConnection | RealtimeTTSStreamSynchronous WebSocket connection for one realtime Text-to-Speech stream.
chunksstr | Iterator[str]Audio chunks to stream to realtime transcription.
text_endboolWhether this message marks the final text chunk for the stream.
namestr | NoneName of the model.
daemonbool-

Returns

threading.Thread


stream_audio()

stream_audio(file: Path | str | BinaryIO | bytes, *, chunk_size_bytes: int = 4 * 1024) -> Iterator[bytes]

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

ParameterTypeDescription
filePath | str | BinaryIO | bytesFile input to upload or transcribe.
chunk_size_bytesint-

Returns

Iterator[bytes]


stream_audio_async()

stream_audio_async(file: Path | str | BinaryIO | bytes, *, chunk_size_bytes: int = 4 * 1024) -> AsyncIterator[bytes]

Asynchronously yield fixed-size chunks from an audio source.

Mirrors stream_audio but produces an async iterator for later consumption.

Parameters

ParameterTypeDescription
filePath | str | BinaryIO | bytesFile input to upload or transcribe.
chunk_size_bytesint-

Returns

AsyncIterator[bytes]


throttle_audio()

throttle_audio(file: Path | str | BinaryIO | bytes, *, chunk_size_bytes: int = 4096, delay_seconds: float = 0.0) -> Iterator[bytes]

Yield audio chunks at a regulated pace, optionally sleeping between yields.

Parameters

ParameterTypeDescription
filePath | str | BinaryIO | bytesFile input to upload or transcribe.
chunk_size_bytesint-
delay_secondsfloat-

Returns

Iterator[bytes]


throttle_audio_async()

throttle_audio_async(file: Path | str | BinaryIO | bytes, *, chunk_size_bytes: int = 32 * 1024, delay_seconds: float = 0.0) -> AsyncIterator[bytes]

Async counterpart of throttle_audio, yielding chunks with optional delay.

Parameters

ParameterTypeDescription
filePath | str | BinaryIO | bytesFile input to upload or transcribe.
chunk_size_bytesint-
delay_secondsfloat-

Returns

AsyncIterator[bytes]