Soniox
SDKsPython

Async transcription with Python SDK

Transcribe audio files asynchronously with the Soniox Python SDK

Soniox Python SDK supports asynchronous transcription for audio files. This allows you to transcribe recordings without maintaining a live connection or streaming pipeline. You can either wait for completion or create a job and retrieve the results based on the webhook event.

Quickstart

The SDK provides a convenient transcribe method that accepts a local file, public URL, or previously uploaded file ID. It will upload the file (if provided) and create the transcription job.

Don't forget to remove files and transcriptions from Soniox after you're done with them.

from soniox import SonioxClient

client = SonioxClient()

# Transcribe from a local file
transcription = client.stt.transcribe(
    model="stt-async-v4",
    file="audio.mp3",
)

# Transcribe from a public URL and fetch the transcript later
transcription = client.stt.transcribe(
    model="stt-async-v4",
    audio_url="https://soniox.com/media/examples/coffee_shop.mp3",
)

# Transcribe from a previously uploaded file
transcription = client.stt.transcribe(
    model="stt-async-v4",
    file_id="uploaded-file-id",
)

After creating the job, you can poll the status with client.stt.get or wait for completion with client.stt.wait. To get the final transcript, call client.stt.get_transcript.

# Check status
transcription = client.stt.get("transcription-id")
print(transcription.status)

# Wait for completion
client.stt.wait("transcription-id")

# Fetch transcript
transcript = client.stt.get_transcript("transcription-id")
print(transcript.text)

Don't forget to delete files and transcriptions from Soniox after you're done with them.

Get transcription

You can get a transcription by ID using get method.

transcription = client.stt.get("transcription-id")
print(transcription.id, transcription.status)

Get a transcription or return None if it doesn't exist:

transcription = client.stt.get_or_none("transcription-id")
if transcription is None:
    print("Transcription not found")

Get transcription transcript

If you want to receive text or tokens from a transcription, fetch the transcription transcript with get_transcript.

transcript = client.stt.get_transcript("transcription-id")
print(transcript.text)

Retrieve list of transcriptions

You can retrieve a list of transcriptions using list method.

from soniox import SonioxClient

client = SonioxClient()

response = client.stt.list(limit=100)
for transcription in response.transcriptions:
    print(transcription.id, transcription.status)

# Use pagination to list more transcriptions
while response.next_page_cursor:
    response = client.stt.list(
        limit=100,
        cursor=response.next_page_cursor,
    )
    for transcription in response.transcriptions:
        print(transcription.id, transcription.status)

Delete or destroy transcription

You can delete or destroy a transcription using delete or destroy method.

Delete transcription only:

client.stt.delete("transcription-id")

Delete a transcription only if it exists:

client.stt.delete_if_exists("transcription-id")

Delete transcription and its file if it was uploaded:

client.stt.destroy("transcription-id")

Delete all transcriptions and files from your account

You have limited space for files and transcriptions, see: Limits and quotas.

These operations are irreversible and cannot be undone.

Delete all transcriptions

You can delete all transcriptions using transcriptions.delete_all.

client.stt.delete_all()

Delete all files

You can delete all files using files.delete_all.

client.files.delete_all()

Delete all transcriptions and its files

You can delete all transcriptions and its files (if it exist) using files.destroy_all.

client.files.destroy_all()