Skip to content

Punctuation and casing

The problem. Raw speech recognition gives a flat stream of words: “hello id like to change my address is that possible”. Punctuation and casing turn it into sentences people can read, and that downstream tools (summaries, search, LLMs) understand better.

Where it works. Every model, every language. On by default: nothing to do.

Live APIpunctuation
Pre-recorded (batch)punctuation_enhanced (how)
Live modelssolaria-3 (every live model)
LanguagesEvery language of the model (supported languages)
{ "text": "Hello, I'd like to change my address. Is that possible?" }

To feed your own text processing with the words only, set punctuation: false.

no_punctuation.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"]
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"
]
},
"punctuation": False
}
client = GladiaClient(api_key=API_KEY, api_url=API_URL)
# `punctuation`: Gladia Connect, not in the SDK's types: a dict is sent as is.
session = client.live_v2().start_session(config)
ended, errors = threading.Event(), []
@session.on("message")
def on_message(message):
if message.type == "transcript" and message.data.is_final:
print(message.data.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]) # live audio: send each chunk as it is captured
session.stop_recording()
ended.wait(timeout=60)
sys.exit(1 if errors or not ended.is_set() else 0)
  • Finals only. Punctuation and casing are applied to final transcripts. Partials show the text as the model writes it: their punctuation may differ, then settle in the final. Compare finals with finals.
  • Off means off. With punctuation: false, the casing goes too: do not expect sentences.
  • A Gladia Connect option. Gladia’s cloud API does not know punctuation: do not send it there.