Soniox
Docs

Language hints

Enhance recognition accuracy by providing language hints parameter.

Soniox Speech-to-Text AI is a single model that transcribes speech in over 50 languages with extreme accuracy. There is no need to pre-select a language — Soniox STT automatically detects and transcribes speech in any of the supported languages. Additionally, it can seamlessly handle multilingual audio, even when different languages are mixed within a single recording.

If you expect the audio to contain a specific language or set of languages, you can provide language hints using the language hints parameter. This guides the AI model toward the expected language(s), which may further enhance recognition accuracy.

If no language hints are specified, the AI model will automatically detect and transcribe all spoken languages within the audio, whether it's a single language or multiple languages mixed together.

See the list of supported languages by Soniox Speech-to-Text AI.

Examples

The language_hints parameter containing a list of language codes can be passed as payload when calling the Create Transcription API endpoint.

Example payload that hints towards English and Spanish:

{
  "language_hints": ["en", "es"]
}

Code example using language hints:

import os
import time
import requests
 
API_BASE = "https://api.soniox.com"
AUDIO_URL = "https://soniox.com/media/examples/multiple_languages_one_speaker.mp3"
API_KEY = os.environ["SONIOX_API_KEY"]
 
session = requests.Session()
session.headers["Authorization"] = f"Bearer {API_KEY}"
 
# 1. Start a new transcription session by sending the audio URL to the API
print("Starting transcription...")
 
response = session.post(
    f"{API_BASE}/v1/transcriptions",
    json={
        "audio_url": AUDIO_URL,
        "model": "stt-async-preview",
        "language_hints": ["en", "es", "fr", "pt"],  # include list of language hints
    },
)
response.raise_for_status()
transcription = response.json()
transcription_id = transcription["id"]
 
print(f"Transcription started with ID: {transcription_id}")
 
# 2. Poll the transcription endpoint until the status is 'completed'
while True:
    response = session.get(f"{API_BASE}/v1/transcriptions/{transcription_id}")
    response.raise_for_status()
    transcription = response.json()
 
    status = transcription.get("status")
    if status == "error":
        raise Exception(
            f"Transcription error: {transcription.get('error_message', 'Unknown error')}"
        )
    elif status == "completed":
        break
    time.sleep(1)
 
# 3. Retrieve the final transcript once transcription is completed
response = session.get(f"{API_BASE}/v1/transcriptions/{transcription_id}/transcript")
response.raise_for_status()
transcript = response.json()
 
print("Transcript:")
print(transcript["text"])
 

On this page