Skip to content

Evaluate Gladia on your own audio (WER test)

The problem. Public benchmarks are measured on someone else’s audio. Your accents, your microphones, your jargon and your phone lines decide how well a speech-to-text API works for you, and the only way to know is to test it on your own recordings.

What a WER test gives you. The word error rate (WER) counts the words a transcript gets wrong against a reference written by a person: substituted, missing and extra words, divided by the words of the reference. 0.08 means 8 errors per 100 words. Run the same files through each API you compare, with the same normalization, and the lowest WER wins on your audio. For Gladia’s own published figures and how they are measured, see the benchmarks.

What How
You need 30 to 60 minutes of your audio, cut in files, and a reference transcript per file
Transcribe the live API (as your product will), or a pre-recorded job for files
Compare each transcript to its reference, both normalized the same way
Read the WER over all files: the sum of the errors over the sum of the reference words

Take recordings like the ones your product will get: the same channel (phone, laptop, studio), the same languages and accents, the same vocabulary. Thirty minutes to an hour, from several speakers, is enough to rank vendors; a single clean file says little.

Have a person transcribe each file word for word, every hesitation they hear included or every one left out, but the same rule for all files. Save each next to its audio: call-01.wav and call-01.reference.txt.

The programs below stream a WAV file to the live API, as your product will, keep the final transcript, and print its WER against the reference next to it. Put your API key in the GLADIA_API_KEY environment variable, then run python evaluate_wer.py call-01.wav.

evaluate_wer.py
# pip install -U "gladiaio-sdk>=2.2"
import os
import sys
import threading
import time
import unicodedata
import wave
from pathlib import Path
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"]
def normalize(text):
"""Lowercase words without punctuation: apply the same to every vendor's transcript and to the reference."""
text = unicodedata.normalize("NFKC", text).lower().replace("’", "'")
# keep letters, their marks (Hindi, Thai, Arabic vowels) and digits; any other character separates words
words = "".join(c if c == "'" or unicodedata.category(c)[0] in "LMN" else " " for c in text).split()
return [w.strip("'") for w in words if w.strip("'")] # 'no' is no; don't stays don't
def errors(reference, hypothesis):
"""Substitutions + deletions + insertions to turn the reference into the hypothesis (word edit distance)."""
row = list(range(len(hypothesis) + 1))
for i, ref_word in enumerate(reference, 1):
previous, row[0] = row[0], i
for j, hyp_word in enumerate(hypothesis, 1):
previous, row[j] = row[j], min(row[j] + 1, row[j - 1] + 1, previous + (ref_word != hyp_word))
return row[-1]
audio_path = Path(sys.argv[1]) # a 16-bit PCM WAV file
reference = normalize(audio_path.with_suffix(".reference.txt").read_text(encoding="utf-8"))
with wave.open(str(audio_path)) as wav:
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"}
client = GladiaClient(api_key=API_KEY, api_url=API_URL)
session = client.live_v2().start_session(config)
ended, errors_seen, finals = threading.Event(), [], []
@session.on("message")
def on_message(message):
if message.type == "transcript" and message.data.is_final:
finals.append(message.data.utterance.text)
session.on("error", errors_seen.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_seen 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])
time.sleep(0.1) # at the pace of real time: the live API closes a session far ahead of it
session.stop_recording()
ended.wait(timeout=60)
if errors_seen or not ended.is_set():
sys.exit(1)
hypothesis = normalize(" ".join(finals))
wrong = errors(reference, hypothesis)
wer = f"{wrong / len(reference):.1%}" if reference else "n/a (empty reference)" # silence, hold music
print(f"{audio_path.name}: {wrong} errors / {len(reference)} reference words, WER {wer}")

Run it on every file, add up the errors and the reference words, and divide: that is your WER. Averaging the WER of each file instead gives a short file as much weight as a long one.

Run the same files through every API, with each one’s own best settings for your case (language, model, custom vocabulary), and score every transcript with the same normalize. Then read the errors themselves, not only the rate: a wrong product name costs more than a missing “uh”.

  • Normalization decides the number. Punctuation, case, “20” against “twenty”, “okay” against “OK”: an unnormalized comparison counts style as errors. Use one normalizer for everything, and set numerals the same way for every API you compare.
  • The reference is a transcript too. A rushed reference inflates every vendor’s WER; check a sample of it.
  • Set the language when you know it (language detection): detection on the first words of a short clip can pick the wrong one and fail the whole file.
  • Live and pre-recorded differ. A live transcript is decided while people speak; a file transcribed after the fact sees the whole call. Test the mode your product will use.
  • Hesitations and fillers. Decide once whether “uh”, “um”, repeated words count, apply it to the references, and drop them from the transcripts in normalize if they do not.
  • A few minutes is noise. Two vendors 1 point apart on ten minutes of audio are tied.