Migrate from Amazon Transcribe to Gladia
Amazon Transcribe streams over an HTTP/2 event stream signed with AWS credentials; Gladia streams over a WebSocket opened with an API key. The settings map one to one, and transcription jobs become pre-recorded jobs that take a URL instead of an S3 location. 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”| Amazon Transcribe | Gladia | |
|---|---|---|
| Authentication | AWS Signature Version 4 (IAM credentials) | x-gladia-key: <key> |
| Live | StartStreamTranscription (HTTP/2 event stream) |
POST /v2/live with a JSON body, then its WebSocket url |
| Pre-recorded | StartTranscriptionJob with an S3 MediaFileUri |
POST /v2/upload, POST /v2/pre-recorded, poll or callback |
| Audio | AudioEvent chunks |
binary frames |
| Models | per language | solaria-3 (multilingual), trantoria-1 (lowest latency) (Models) |
Live transcription
Section titled “Live transcription”Before and after
Section titled “Before and after”A typical Amazon Transcribe stream (Python, the amazon-transcribe library):
# Amazon Transcribe (before)import asyncio
from amazon_transcribe.client import TranscribeStreamingClientfrom amazon_transcribe.handlers import TranscriptResultStreamHandler
class Printer(TranscriptResultStreamHandler): async def handle_transcript_event(self, transcript_event): for result in transcript_event.transcript.results: print("partial" if result.is_partial else "final", result.alternatives[0].transcript)
async def stream(chunks): client = TranscribeStreamingClient(region="eu-west-1") session = await client.start_stream_transcription( language_code="en-US", media_sample_rate_hz=16000, media_encoding="pcm", show_speaker_label=True )
async def send(): for chunk in chunks: await session.input_stream.send_audio_event(audio_chunk=chunk) await session.input_stream.end_stream()
await asyncio.gather(send(), Printer(session.output_stream).handle_events()) # results while sendingWith 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_aws.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 }, "diarization": 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": # Amazon Transcribe's results, "IsPartial" true or false 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() # Amazon Transcribe's "end_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 }, "diarization": true}Parameters
Section titled “Parameters”| Amazon Transcribe | Gladia | Note |
|---|---|---|
LanguageCode: en-US |
language_config.languages: ["en"] |
ISO 639-1 codes |
IdentifyLanguage, LanguageOptions |
language_config.languages: […] |
the language detected among them |
IdentifyMultipleLanguages |
language_config.code_switching: true |
Code switching |
MediaEncoding: pcm |
encoding: "wav/pcm", bit_depth: 16 |
|
MediaSampleRateHertz |
sample_rate |
|
EnableChannelIdentification, NumberOfChannels |
channels |
Several channels |
ShowSpeakerLabel |
diarization: true |
Speaker diarization |
| partial results (always sent) | messages_config.receive_partial_transcripts: true |
off by default (Partial transcripts) |
VocabularyName |
realtime_processing.custom_vocabulary and realtime_processing.custom_vocabulary_config |
the words in the request, no vocabulary to create first |
ContentRedactionType: PII |
pii: true |
PII redaction |
Messages
Section titled “Messages”| Amazon Transcribe | Gladia | Note |
|---|---|---|
TranscriptEvent, IsPartial: true |
transcript, data.is_final: false |
|
TranscriptEvent, IsPartial: false |
transcript, data.is_final: true |
the text: data.utterance.text |
Alternatives[0].Items |
data.utterance.words |
|
ChannelId |
data.utterance.channel |
|
| end of the event stream | end_session |
with receive_lifecycle_events |
Pre-recorded (batch) transcription
Section titled “Pre-recorded (batch) transcription”A transcription job reads the media from S3 and writes its transcript to S3. A Gladia job reads any URL (a presigned S3 URL works) or an upload, and its transcript is in the job.
Before and after
Section titled “Before and after”A typical Amazon Transcribe job (Python, boto3; the file is in S3):
# Amazon Transcribe (before)import jsonimport timeimport urllib.request
import boto3
def transcribe(job_name, s3_uri): client = boto3.client("transcribe", region_name="eu-west-1") client.start_transcription_job( TranscriptionJobName=job_name, Media={"MediaFileUri": s3_uri}, # s3://bucket/call.wav MediaFormat="wav", LanguageCode="en-US", Settings={"ShowSpeakerLabels": True, "MaxSpeakerLabels": 2}, ) while True: job = client.get_transcription_job(TranscriptionJobName=job_name)["TranscriptionJob"] if job["TranscriptionJobStatus"] in ("COMPLETED", "FAILED"): break time.sleep(5) if job["TranscriptionJobStatus"] == "FAILED": raise RuntimeError(job["FailureReason"]) with urllib.request.urlopen(job["Transcript"]["TranscriptFileUri"]) as answer: # a file to download print(json.load(answer)["results"]["transcripts"][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_aws_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"]} # Amazon Transcribe: IAM credentials (Signature Version 4)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 a presigned S3 URL as audio_url)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", # Amazon Transcribe picks its model by language "language_config": {"languages": ["en"]}, # LanguageCode="en-US" "diarization": True, # Settings.ShowSpeakerLabels "diarization_config": {"max_speakers": 2}, # Settings.MaxSpeakerLabels }, 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" }}| Amazon Transcribe | Gladia | Note |
|---|---|---|
Media.MediaFileUri (s3://…) |
audio_url (a presigned https:// URL), or POST /v2/upload |
|
LanguageCode |
language_config.languages |
|
Settings.ShowSpeakerLabels, MaxSpeakerLabels |
diarization, diarization_config.max_speakers |
|
Settings.ChannelIdentification |
the file’s channels, each transcribed | |
ContentRedaction |
pii_redaction |
|
GetTranscriptionJob, COMPLETED |
GET /v2/pre-recorded/{id}, status: done |
or a callback |
results.transcripts[0].transcript |
result.transcription.full_transcript |
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.
- No IAM signing: an API key in a header, created in Gladia Workspace (Authentication).
- No vocabulary resource to create: send the words with the session or the job.