Skip to content

Migrate from Rev.ai to Gladia

Rev.ai and Gladia both stream raw audio over a WebSocket and run asynchronous jobs for files. Rev.ai puts its settings and the access token in the WebSocket’s query string and ends a stream with an EOS text message; Gladia opens the session over HTTP first and ends it with stop_recording. 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).

Rev.ai Gladia
Authentication access_token (query string), Authorization: Bearer for jobs x-gladia-key: <key>; the WebSocket url carries its own token
Live wss://api.rev.ai/speechtotext/v1/stream?… POST /v2/live with a JSON body, then its WebSocket url
Pre-recorded POST /speechtotext/v1/jobs, then the transcript POST /v2/upload, POST /v2/pre-recorded, poll or callback
Audio binary frames, content_type=audio/x-raw;… binary frames, the format in the init body
Models one per language solaria-3 (multilingual), trantoria-1 (lowest latency) (Models)

A typical Rev.ai stream (Python, its WebSocket with the websockets library):

# Rev.ai (before)
import json
import websockets
CONTENT_TYPE = "audio/x-raw;layout=interleaved;rate=16000;format=S16LE;channels=1"
async def stream(token, chunks):
url = f"wss://api.rev.ai/speechtotext/v1/stream?access_token={token}&content_type={CONTENT_TYPE}"
async with websockets.connect(url) as ws:
await ws.recv() # {"type": "connected", "id": ...}: wait for it before sending audio
for chunk in chunks:
await ws.send(chunk) # binary audio
await ws.send("EOS")
async for raw in ws: # {"type": "partial" | "final", "elements": [{"value": ...}]}
message = json.loads(raw)
if message["type"] == "final":
print("".join(element["value"] for element in message["elements"]))

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_revai.py call.wav.

from_revai.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
}
}
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": # Rev.ai's "partial" and "final"
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() # Rev.ai's "EOS"
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
}
}
Rev.ai Gladia Note
content_type=audio/x-raw;…format=S16LE encoding: "wav/pcm", bit_depth: 16
rate, channels (in content_type) sample_rate, channels
language language_config.languages
custom_vocabulary_id realtime_processing.custom_vocabulary and realtime_processing.custom_vocabulary_config the words in the request, no vocabulary to create first
partials (sent by default), detailed_partials=true messages_config.receive_partial_transcripts: true off by default in Gladia: set it to keep partials; they carry their words
max_segment_duration_seconds maximum_duration_without_endpointing Endpointing
Rev.ai Gladia Note
connected the SDK’s connected event (start_recording with receive_lifecycle_events) send audio once connected
partial transcript, data.is_final: false
final transcript, data.is_final: true the text: data.utterance.text, not elements
elements[].ts, end_ts data.utterance.words[].start, end in seconds
EOS (you send) {"type": "stop_recording"} the SDK’s stop_recording()

Both run a job from a URL or a file and notify you when it is done.

A typical Rev.ai asynchronous job (Python, its REST API with requests; the file at a URL):

# Rev.ai (before)
import time
import requests
BASE = "https://api.rev.ai/speechtotext/v1"
def transcribe(token, media_url):
headers = {"Authorization": f"Bearer {token}"}
body = {"source_config": {"url": media_url}, "language": "en", "skip_diarization": False}
job = requests.post(f"{BASE}/jobs", headers=headers, json=body).json()
while job["status"] == "in_progress":
time.sleep(3)
job = requests.get(f"{BASE}/jobs/{job['id']}", headers=headers).json()
if job["status"] != "transcribed":
raise RuntimeError(job.get("failure_detail"))
transcript = requests.get(f"{BASE}/jobs/{job['id']}/transcript", headers=headers).json()
for monologue in transcript["monologues"]: # a second call for the transcript
print(monologue["speaker"], "".join(element["value"] for element in monologue["elements"]))

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_revai_file.py call.wav.

from_revai_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"]} # Rev.ai: "Authorization: Bearer <token>"
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 (or give the file's URL as audio_url, as source_config.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 body
created = requests.post(
f"{API_URL}/v2/pre-recorded",
headers=HEADERS,
json={
"audio_url": upload.json()["audio_url"],
"model": "solaria-3", # Rev.ai's model per language
"language_config": {"languages": ["en"]}, # language: "en"
"diarization": True, # skip_diarization: false
},
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"
}
}
Rev.ai Gladia Note
source_config.url audio_url
notification_config.url callback: true, callback_config.url Pre-recorded callbacks
language language_config.languages
skip_diarization: false diarization: true
speaker_channels_count the file’s channels, each transcribed Several channels
GET /jobs/{id}/transcript (monologues) the job’s result.transcription.utterances 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.
  • The transcript is text, not elements: data.utterance.text holds the punctuated sentence; its words carry the timings.