Skip to content

Migrate from Deepgram to Gladia

Deepgram and Gladia work the same way for live audio: you stream raw audio over a WebSocket and receive partial and final transcripts. The move is mostly a mapping of names: query parameters become an init body, Results messages become transcript messages. Pre-recorded audio changes more: Deepgram answers the request with the transcript, Gladia runs a job. 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).

Deepgram Gladia
Authentication Authorization: Token <key> x-gladia-key: <key>
Live wss://api.deepgram.com/v1/listen?…, settings in the query string POST /v2/live with a JSON body, then its WebSocket url
Pre-recorded POST /v1/listen, the transcript in the answer POST /v2/pre-recorded, a job: poll it or get a callback
Audio binary frames binary frames
Models nova-3, … solaria-3 (multilingual), trantoria-1 (lowest latency) (Models)

A typical Deepgram stream (Python, its WebSocket with the websockets library):

# Deepgram (before)
import json
import websockets
URL = ("wss://api.deepgram.com/v1/listen?model=nova-3&language=en&encoding=linear16&sample_rate=16000"
"&channels=1&interim_results=true&endpointing=300&diarize=true&smart_format=true")
async def stream(key, chunks):
async with websockets.connect(URL, additional_headers={"Authorization": f"Token {key}"}) as ws:
for chunk in chunks:
await ws.send(chunk) # binary audio
await ws.send(json.dumps({"type": "CloseStream"}))
async for raw in ws: # {"type": "Results", "is_final": ..., "channel": {"alternatives": [...]}}
message = json.loads(raw)
if message["type"] == "Results":
print(message["channel"]["alternatives"][0]["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_deepgram.py call.wav.

from_deepgram.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
},
"endpointing": 0.3,
"diarization": True,
"numerals": 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": # Deepgram's "Results"
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() # Deepgram's "CloseStream"
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
},
"endpointing": 0.3,
"diarization": true,
"numerals": true
}
Deepgram Gladia Note
model=nova-3 model: "solaria-3" trantoria-1 for the lowest latency
language=en language_config.languages: ["en"]
language=multi language_config: {"languages": [], "code_switching": true} Code switching
encoding=linear16 encoding: "wav/pcm", bit_depth: 16
encoding=mulaw encoding: "wav/ulaw", bit_depth: 8 Phone calls
sample_rate, channels sample_rate, channels 1 or 2 channels, each transcribed on its own
multichannel=true channels: 2 every utterance carries its channel
interim_results=true messages_config.receive_partial_transcripts: true Partial transcripts
endpointing=300 (ms) endpointing: 0.3 (s)
utterance_end_ms end_of_turn: true End of turn
vad_events=true messages_config.receive_speech_events: true speech_start, speech_end
diarize=true diarization: true Speaker diarization
punctuate=true on by default (punctuation)
smart_format=true numerals: true punctuation is already on
keyterm, keywords realtime_processing.custom_vocabulary and realtime_processing.custom_vocabulary_config Custom vocabulary
redact pii: true PII redaction
callback callback: true, callback_config.url Callbacks
tag, extra custom_metadata Custom metadata
Deepgram Gladia Note
Results, is_final: false transcript, data.is_final: false the text: data.utterance.text
Results, is_final: true transcript, data.is_final: true one per utterance, never revised
Results, speech_final: true transcript final, then end_of_turn with end_of_turn: true
UtteranceEnd end_of_turn
SpeechStarted speech_start with receive_speech_events
Metadata end_session the last message, with receive_lifecycle_events
KeepAlive (you send) {"type": "keep_alive"} Keep a session open
Finalize (you send) {"type": "finalize"} Finalize now
CloseStream (you send) {"type": "stop_recording"} the SDK’s stop_recording()

Deepgram transcribes a file in the request itself: POST /v1/listen with the audio or {"url": …}, and the answer is the transcript. Gladia runs a job, so a long file never holds a request open.

A typical Deepgram file transcription (Python, its REST API with requests):

# Deepgram (before)
import requests
PARAMS = {"model": "nova-3", "language": "en", "diarize": "true", "smart_format": "true"}
def transcribe(key, path):
with open(path, "rb") as audio: # the file is the request's body
answer = requests.post(
"https://api.deepgram.com/v1/listen",
params=PARAMS,
headers={"Authorization": f"Token {key}", "Content-Type": "audio/wav"},
data=audio,
)
answer.raise_for_status() # the transcript is in the answer
print(answer.json()["results"]["channels"][0]["alternatives"][0]["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_deepgram_file.py call.wav.

from_deepgram_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"]} # Deepgram: "Authorization: Token <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 (Deepgram takes the file in the request itself)
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", # model=nova-3
"language_config": {"languages": ["en"]}, # language=en
"diarization": True, # diarize=true
},
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"
}
}
Deepgram Gladia Note
results.channels[0].alternatives[0].transcript result.transcription.full_transcript
results.utterances result.transcription.utterances each with speaker and channel
callback=… callback: true, callback_config.url Pre-recorded callbacks
detect_language=true language_config: {"languages": []}
summarize summarization: true, summarization_config.type once your cluster has a language model (Add-ons)
  • 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.
  • speech_final has no single field. Gladia sends the utterance’s final transcript, and with end_of_turn an end_of_turn message when the speaker’s turn is over: decide on that message, not on silence alone.
  • Pre-recorded is asynchronous. Read the job when its callback arrives, or poll it every few seconds.