Skip to content

Migrate from Speechmatics to Gladia

Speechmatics and Gladia both stream raw audio over a WebSocket. Speechmatics configures the session with a first StartRecognition message on the socket; Gladia configures it over HTTP (POST /v2/live) before you connect. Its AddPartialTranscript and AddTranscript become Gladia’s transcript messages, partial then final. Batch jobs map one to one. The Gladia SDKs (gladiaio-sdk for Python, @gladiaio/sdk for JavaScript) open the session, keep the audio until it is transcribed and reconnect without losing a word (SDKs).

Speechmatics Gladia
Authentication Authorization: Bearer <key>, or a short-lived JWT x-gladia-key: <key>; the WebSocket url carries its own token
Live wss://<region>.rt.speechmatics.com/v2, then a StartRecognition message POST /v2/live with a JSON body, then its WebSocket url
Pre-recorded POST /v2/jobs (file + config), then the transcript POST /v2/upload, POST /v2/pre-recorded, poll or callback
Audio AddAudio: binary frames binary frames
Models standard, enhanced solaria-3 (multilingual), trantoria-1 (lowest latency) (Models)

A typical Speechmatics real-time stream (Python, its WebSocket with the websockets library):

# Speechmatics (before)
import json
import websockets
START = {
"message": "StartRecognition",
"audio_format": {"type": "raw", "encoding": "pcm_s16le", "sample_rate": 16000},
"transcription_config": {"language": "en", "enable_partials": True, "max_delay": 0.7, "diarization": "speaker"},
}
async def stream(key, chunks):
url = "wss://eu2.rt.speechmatics.com/v2"
async with websockets.connect(url, additional_headers={"Authorization": f"Bearer {key}"}) as ws:
await ws.send(json.dumps(START))
for chunk in chunks:
await ws.send(chunk) # AddAudio: binary audio
await ws.send(json.dumps({"message": "EndOfStream", "last_seq_no": len(chunks)}))
async for raw in ws: # AddPartialTranscript, AddTranscript, EndOfTranscript
message = json.loads(raw)
if message["message"] == "AddTranscript":
print(message["metadata"]["transcript"])

With Gladia, the same stream: the SDK opens the session (POST /v2/live) and its WebSocket, and you send the same audio bytes. Put your Gladia API key in GLADIA_API_KEY, then run python from_speechmatics.py call.wav.

from_speechmatics.py
# pip install -U "gladiaio-sdk>=2.2"
import os
import sys
import threading
import wave
from gladiaio_sdk import GladiaClient
API_URL = os.environ.get("GLADIA_API_URL", "https://eu1.api.gladia.io")
API_KEY = os.environ["GLADIA_API_KEY"] # x-gladia-key, from Gladia Workspace
with wave.open(sys.argv[1]) as wav: # a 16-bit PCM WAV file
rate, channels = wav.getframerate(), wav.getnchannels()
audio = wav.readframes(wav.getnframes())
config = {
"encoding": "wav/pcm",
"sample_rate": rate,
"bit_depth": 16,
"channels": channels,
"model": "solaria-3",
"language_config": {
"languages": [
"en"
]
},
"messages_config": {
"receive_partial_transcripts": True
},
"diarization": True
}
client = GladiaClient(api_key=API_KEY, api_url=API_URL)
session = client.live_v2().start_session(config) # POST /v2/live, then its WebSocket
ended, errors = threading.Event(), []
@session.on("message")
def on_message(message):
if message.type == "transcript": # Speechmatics' "AddPartialTranscript" and "AddTranscript"
utterance = message.data.utterance
print(("final " if message.data.is_final else "partial ") + utterance.text)
session.on("error", errors.append)
session.once("ended", lambda _: ended.set())
# Stream once the socket is open: a stop sent while it opens can pass the audio queued until then.
connected = threading.Event()
session.once("connected", lambda _: connected.set())
session.once("ended", lambda _: connected.set()) # a session that never connects ends
session.on("error", lambda _: connected.set())
if session.status == "connected": # it opened before the listener above
connected.set()
if not connected.wait(timeout=30) or errors or ended.is_set():
sys.exit(1) # no open session to stream to
step = rate * channels * 2 // 10 # 100 ms of audio per chunk
for start in range(0, len(audio), step):
session.send_audio(audio[start : start + step]) # binary frames, as before
session.stop_recording() # Speechmatics' "EndOfStream"
ended.wait(timeout=60)
sys.exit(1 if errors or not ended.is_set() else 0)

The init body the program sends, as JSON:

{
"encoding": "wav/pcm",
"sample_rate": 16000,
"bit_depth": 16,
"channels": 1,
"model": "solaria-3",
"language_config": {
"languages": [
"en"
]
},
"messages_config": {
"receive_partial_transcripts": true
},
"diarization": true
}
Speechmatics Gladia Note
audio_format.encoding: pcm_s16le encoding: "wav/pcm", bit_depth: 16
audio_format.encoding: mulaw encoding: "wav/ulaw", bit_depth: 8 Phone calls
audio_format.sample_rate sample_rate
transcription_config.language language_config.languages [] to detect the language
operating_point / model: enhanced model: "solaria-3" trantoria-1 for the lowest latency
enable_partials: true messages_config.receive_partial_transcripts: true Partial transcripts
max_delay endpointing, maximum_duration_without_endpointing Endpointing
diarization: "speaker" diarization: true Speaker diarization
diarization: "channel" channels: 2 Several channels
additional_vocab realtime_processing.custom_vocabulary and realtime_processing.custom_vocabulary_config Custom vocabulary
translation_config realtime_processing.translation and realtime_processing.translation_config Real-time translation
Speechmatics Gladia Note
RecognitionStarted start_recording with receive_lifecycle_events
AddPartialTranscript transcript, data.is_final: false
AddTranscript transcript, data.is_final: true the text: data.utterance.text
AudioAdded audio_chunk (acknowledgment) once the audio is transcribed
EndOfTranscript end_session with receive_lifecycle_events
EndOfStream (you send) {"type": "stop_recording"} the SDK’s stop_recording()
SetRecognitionConfig (you send) {"type": "session_config", …} Change settings mid-session

Both run a job: Speechmatics takes the file and a config in one multipart request; Gladia takes the file first (POST /v2/upload), then a JSON job.

A typical Speechmatics batch job (Python, its REST API with requests):

# Speechmatics (before)
import json
import time
import requests
BASE = "https://asr.api.speechmatics.com/v2"
CONFIG = {
"type": "transcription",
"transcription_config": {"language": "en", "operating_point": "enhanced", "diarization": "speaker"},
}
def transcribe(key, path):
headers = {"Authorization": f"Bearer {key}"}
with open(path, "rb") as audio: # the file and its config in one multipart request
job_id = requests.post(
f"{BASE}/jobs", headers=headers, files={"data_file": audio}, data={"config": json.dumps(CONFIG)}
).json()["id"]
while (status := requests.get(f"{BASE}/jobs/{job_id}", headers=headers).json()["job"]["status"]) == "running":
time.sleep(3)
if status != "done":
raise RuntimeError(status)
transcript = requests.get(f"{BASE}/jobs/{job_id}/transcript", headers=headers, params={"format": "txt"})
print(transcript.text) # a second call for the transcript

With Gladia, the same file in three steps: upload it (POST /v2/upload), start a job with its audio_url (POST /v2/pre-recorded), then read the job (GET /v2/pre-recorded/{id}) until its status is done (Transcribe a file). Put your Gladia API key in GLADIA_API_KEY, then run python from_speechmatics_file.py call.wav.

from_speechmatics_file.py
# pip install requests
import os
import sys
import time
import requests
API_URL = os.environ.get("GLADIA_API_URL", "https://eu1.api.gladia.io")
HEADERS = {"x-gladia-key": os.environ["GLADIA_API_KEY"]} # Speechmatics: "Authorization: Bearer <key>"
TIMEOUT = 60 # seconds an HTTP call may take
POLL_EVERY = 1 # seconds between two reads of the job
ENDED = ("done", "error") # the statuses a job ends with
# 1. Upload the file (Speechmatics' data_file)
with open(sys.argv[1], "rb") as audio:
upload = requests.post(f"{API_URL}/v2/upload", headers=HEADERS, files={"audio": audio}, timeout=TIMEOUT)
upload.raise_for_status()
# 2. Start the job on the uploaded file, the options in a JSON body
created = requests.post(
f"{API_URL}/v2/pre-recorded",
headers=HEADERS,
json={
"audio_url": upload.json()["audio_url"],
"model": "solaria-3", # operating_point: "enhanced"
"language_config": {"languages": ["en"]}, # transcription_config.language
"diarization": True, # diarization: "speaker"
},
timeout=TIMEOUT,
)
created.raise_for_status()
job_url = f"{API_URL}/v2/pre-recorded/{created.json()['id']}"
# 3. Read the job until it ends (or get a callback, below)
while True:
answer = requests.get(job_url, headers=HEADERS, timeout=TIMEOUT)
answer.raise_for_status()
job = answer.json()
if job["status"] in ENDED:
break
time.sleep(POLL_EVERY)
if job["status"] == "error":
sys.exit(f"the job failed: {job.get('error_code')}")
print(job["result"]["transcription"]["full_transcript"]) # the result is in the job

To be called back rather than poll, add a callback to the job: Gladia calls your URL when the job ends (Pre-recorded callbacks). The job’s body, with a callback:

{
"audio_url": "https://eu1.api.gladia.io/file/0199d7a2-0000-7000-8000-00000000f11e",
"language_config": {
"languages": [
"en"
]
},
"diarization": true,
"callback": true,
"callback_config": {
"url": "https://example.com/gladia/callback"
}
}
Speechmatics Gladia Note
POST /v2/jobs (data_file + config) POST /v2/upload, then POST /v2/pre-recorded
fetch_data.url audio_url any public or signed URL
transcription_config.diarization: "speaker" diarization: true
notification_config callback: true, callback_config.url Pre-recorded callbacks
GET /v2/jobs/{id}, status: done GET /v2/pre-recorded/{id}, status: done
GET /v2/jobs/{id}/transcript?format=json-v2 the job’s result no second call
  • A session is opened over HTTP first. POST /v2/live with the session’s settings returns a WebSocket url that carries its own token: settings go in a JSON body, not in the WebSocket’s query string, and your API key never reaches the client that streams. The SDKs do both steps.
  • Endpointing is in seconds: endpointing: 0.3 is 300 ms (Endpointing).
  • Punctuation and casing are on by default (Punctuation); numbers as digits are numerals: true (Numbers as digits).
  • Audio is acknowledged once transcribed, not once received: keep it until then to resend it after a network drop (Reconnections). The SDKs do it for you.
  • No sequence numbers. Gladia acknowledges audio by byte_range (audio_chunk messages), not by seq_no; stop_recording takes no count.