Migrate from Azure AI Speech to Gladia
Azure AI Speech is used through its Speech SDK: a recognizer pulls audio from a stream and raises recognizing and recognized events. Gladia’s SDKs work the same way with an open protocol underneath: push the audio, get partial and final transcript messages. Batch transcription maps to a pre-recorded 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).
At a glance
Section titled “At a glance”| Azure AI Speech | Gladia | |
|---|---|---|
| Authentication | a resource key and region (SpeechConfig(subscription=…, region=…)) |
x-gladia-key: <key>, one API address per region (Regions) |
| Live | Speech SDK SpeechRecognizer, continuous recognition |
POST /v2/live with a JSON body, then its WebSocket url |
| Pre-recorded | batch transcription REST (/speechtotext/…/transcriptions) |
POST /v2/upload, POST /v2/pre-recorded, poll or callback |
| Audio | PushAudioInputStream |
binary frames |
| Models | the base model per locale, or a custom model | solaria-3 (multilingual), trantoria-1 (lowest latency) (Models) |
Live transcription
Section titled “Live transcription”Before and after
Section titled “Before and after”A typical Azure continuous recognition (Python, the Speech SDK):
# Azure AI Speech (before)import azure.cognitiveservices.speech as speechsdk
def stream(key, region, chunks): config = speechsdk.SpeechConfig(subscription=key, region=region) config.speech_recognition_language = "en-US" audio = speechsdk.audio.PushAudioInputStream(speechsdk.audio.AudioStreamFormat(samples_per_second=16000)) recognizer = speechsdk.SpeechRecognizer(speech_config=config, audio_config=speechsdk.audio.AudioConfig(stream=audio)) recognizer.recognizing.connect(lambda event: print("partial", event.result.text)) recognizer.recognized.connect(lambda event: print("final", event.result.text)) recognizer.start_continuous_recognition() for chunk in chunks: audio.write(chunk) audio.close() recognizer.stop_continuous_recognition()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_azure.py call.wav.
# pip install -U "gladiaio-sdk>=2.2"import osimport sysimport threadingimport 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 }}
client = GladiaClient(api_key=API_KEY, api_url=API_URL)session = client.live_v2().start_session(config) # POST /v2/live, then its WebSocketended, errors = threading.Event(), []
@session.on("message")def on_message(message): if message.type == "transcript": # Azure's "recognizing" and "recognized" events 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 endssession.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 chunkfor start in range(0, len(audio), step): session.send_audio(audio[start : start + step]) # binary frames, as beforesession.stop_recording() # closing Azure's push stream
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 }}Parameters
Section titled “Parameters”| Azure AI Speech | Gladia | Note |
|---|---|---|
speech_recognition_language = "en-US" |
language_config.languages: ["en"] |
ISO 639-1 codes (Supported languages) |
AutoDetectSourceLanguageConfig, continuous |
language_config: {"languages": […], "code_switching": true} |
Code switching |
AudioStreamFormat(samples_per_second, bits_per_sample, channels) |
sample_rate, bit_depth, channels |
|
PhraseListGrammar.add_phrase |
realtime_processing.custom_vocabulary and realtime_processing.custom_vocabulary_config |
Custom vocabulary |
ConversationTranscriber |
diarization: true |
Speaker diarization |
Speech_SegmentationSilenceTimeoutMs (ms) |
endpointing (s) |
Endpointing |
TranslationRecognizer |
realtime_processing.translation |
Real-time translation |
Messages
Section titled “Messages”| Azure AI Speech | Gladia | Note |
|---|---|---|
recognizing |
transcript, data.is_final: false |
|
recognized |
transcript, data.is_final: true |
the text: data.utterance.text |
speech_start_detected, speech_end_detected |
speech_start, speech_end |
|
session_stopped |
end_session |
with receive_lifecycle_events |
canceled |
error, or the WebSocket’s close code |
Pre-recorded (batch) transcription
Section titled “Pre-recorded (batch) transcription”Azure’s batch transcription takes contentUrls and writes its results as files you list and download. Gladia’s job takes one audio_url (or an upload) and its result is in the job.
Before and after
Section titled “Before and after”A typical Azure batch transcription (Python, the batch transcription REST API with requests; the file is in Blob Storage, read through a SAS URL):
# Azure AI Speech (before)import time
import requests
REGION = "westeurope"SUBMIT = f"https://{REGION}.api.cognitive.microsoft.com/speechtotext/transcriptions:submit?api-version=2024-11-15"
def transcribe(key, sas_url): headers = {"Ocp-Apim-Subscription-Key": key} body = { "contentUrls": [sas_url], "locale": "en-US", "displayName": "call", "properties": {"diarizationEnabled": True, "timeToLiveHours": 48}, } transcription = requests.post(SUBMIT, headers=headers, json=body).json() while transcription["status"] in ("NotStarted", "Running"): time.sleep(5) transcription = requests.get(transcription["self"], headers=headers).json() if transcription["status"] != "Succeeded": raise RuntimeError(transcription["status"]) files = requests.get(transcription["links"]["files"], headers=headers).json()["values"] for file in files: # the results are files to list, then download if file["kind"] == "Transcription": result = requests.get(file["links"]["contentUrl"]).json() print(result["combinedRecognizedPhrases"][0]["display"])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_azure_file.py call.wav.
# pip install requestsimport osimport sysimport 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"]} # Azure: "Ocp-Apim-Subscription-Key: <key>"TIMEOUT = 60 # seconds an HTTP call may takePOLL_EVERY = 1 # seconds between two reads of the jobENDED = ("done", "error") # the statuses a job ends with
# 1. Upload the file (or give your SAS URL as audio_url, as in contentUrls)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 bodycreated = requests.post( f"{API_URL}/v2/pre-recorded", headers=HEADERS, json={ "audio_url": upload.json()["audio_url"], "model": "solaria-3", # the locale's base model "language_config": {"languages": ["en"]}, # locale: "en-US" "diarization": True, # properties.diarizationEnabled }, 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 jobTo 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" }}| Azure AI Speech | Gladia | Note |
|---|---|---|
contentUrls |
audio_url |
one file per job |
locale |
language_config.languages |
|
properties.diarizationEnabled |
diarization |
|
properties.channels |
the file’s channels, each transcribed | Several channels |
the results files (combinedRecognizedPhrases) |
result.transcription.full_transcript, utterances |
|
polling the transcription’s status |
callback_config.url, or polling the job |
Differences to know
Section titled “Differences to know”- A session is opened over HTTP first.
POST /v2/livewith the session’s settings returns a WebSocketurlthat 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.3is 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.
- Language codes are ISO 639-1:
en, noten-US. - No resource key and region pair: one API key per workspace, and the API address of your region.