Soniox Python SDK

2.2.0 · active · verified Thu Apr 16

The official Python SDK for the Soniox API, providing fully typed access to Async and Real-time Speech-to-Text (STT) capabilities. It simplifies integration by handling authentication, file uploads, transcription polling, and real-time stream helpers. The library is actively maintained with frequent updates, aiming to be a developer-friendly ecosystem for voice AI. [2, 3]

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the synchronous `SonioxClient`, transcribe an audio file from a public URL, wait for its completion, retrieve the transcript, and then delete the transcription. It uses the `SONIOX_API_KEY` environment variable for authentication. [1, 2]

import os
from soniox import SonioxClient

# Get your API key from https://console.soniox.com/api-keys
# It's recommended to set SONIOX_API_KEY as an environment variable.
soniox_api_key = os.environ.get('SONIOX_API_KEY', 'YOUR_SONIOX_API_KEY')

if not soniox_api_key or soniox_api_key == 'YOUR_SONIOX_API_KEY':
    print("Error: SONIOX_API_KEY environment variable not set or placeholder used.")
    print("Please set it to your actual Soniox API key.")
else:
    try:
        client = SonioxClient(api_key=soniox_api_key)

        # Example: Transcribe an audio file from a public URL asynchronously
        print("Starting transcription...")
        transcription = client.stt.transcribe(
            audio_url="https://soniox.com/media/examples/coffee_shop.mp3"
        )

        print(f"Transcription ID: {transcription.id}")
        print("Waiting for transcription to complete...")
        client.stt.wait(transcription.id, timeout_sec=120)

        transcript = client.stt.get_transcript(transcription.id)
        print("\nTranscription complete:")
        print(transcript.text)

        # Optionally delete the transcription and associated file to save resources
        client.stt.delete(transcription.id)
        print(f"Transcription {transcription.id} and associated file deleted.")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →