Soniox
SDKs

Python SDK

Python SDK for Soniox REST and realtime APIs.

Soniox Python SDK gives you fully typed access to our Async and Real-time Speech-to-Text APIs.

Quickstart

Install

pip install soniox

Set your API key

export SONIOX_API_KEY=<YOUR_API_KEY>

Get API key

Create a Soniox account and log in to the Console to get your API key.

Create your first real-time session

from soniox import SonioxClient
from soniox.types import RealtimeSTTConfig, Token
from soniox.utils import render_tokens, throttle_audio, start_audio_thread

# Grab the demo file from: 
# https://github.com/soniox/soniox_examples/raw/refs/heads/master/speech_to_text/assets/coffee_shop.mp3
AUDIO_FILE = "coffee_shop.mp3"

client = SonioxClient()
config = RealtimeSTTConfig(model="stt-rt-v4", audio_format="mp3")
final_tokens: list[Token] = []
non_final_tokens: list[Token] = []

def realtime():
    # Create new real-time websocket session
    with client.realtime.stt.connect(config=config) as session:

        # Stream audio to websocket
        start_audio_thread(session, throttle_audio(AUDIO_FILE, delay_seconds=0.1))

        # Receive events from Soniox Real-time STT
        for event in session.receive_events():
            for token in event.tokens:
                if token.is_final:
                    final_tokens.append(token)
                else:
                    non_final_tokens.append(token)
            print(render_tokens(final_tokens, non_final_tokens))
            non_final_tokens.clear()

realtime()

Learn more about Real-time transcription.

Create your first async transcription

from soniox import SonioxClient

client = SonioxClient()

# Create new transcription from `audio_url`
transcription = client.stt.transcribe(
    audio_url="https://soniox.com/media/examples/coffee_shop.mp3",
)

# Wait until transcription processing is finished
client.stt.wait(transcription.id)

# Get transcription transcript and print it
transcript = client.stt.get_transcript(transcription.id)
print(transcript.text)

Learn more about Async transcription.

Next steps