Skip to content

Post-call transcript refinement for live calls (finalization)

The problem. A live transcript is written while people are still talking: each final is decided on what the model has heard so far, and the speakers are told apart on the fly. A note taker, a meeting recorder or a CRM that stores the call wants the best transcript of the whole call once it is over, and does not want the words to move on screen while it runs.

What finalization does. With "finalization": true, when the session ends, its whole recording goes through one post-call pass of the pre-recorded pipeline: solaria-3 over the entire call, with pre-recorded diarization. The live transcript is used as the pass’s draft, so the pass mostly checks words the live model already wrote and only pays where they were wrong. The pass is an ordinary pre-recorded job: you read it with GET /v2/pre-recorded/{id}, and its callback tells you when it is done.

What it does not do. Nothing changes during the call: the live finals you receive are never revised. The better transcript is a separate result, ready a short while after the call ends.

Live APIfinalization
Pre-recorded (batch)from_session_id (how)
Live modelssolaria-3, trantoria-1 (every live model)
LanguagesEvery language of the model (supported languages)

Add finalization to the session’s init body. To be told when the pass is done, give a callback URL too:

{
"model": "solaria-3",
"language_config": { "languages": ["en"] },
"finalization": true,
"callback": true,
"callback_config": { "url": "https://example.com/gladia/callback" }
}

Stream the audio and stop the session as you always do. The finals are the usual live finals.

Each program streams a 16-bit WAV file with finalization on, prints the live finals, then the session’s id: the pass is found from it once the call has ended. Put your API key in the GLADIA_API_KEY environment variable, then run python finalization.py call.wav.

finalization.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"]},
"finalization": True,
}
client = GladiaClient(api_key=API_KEY, api_url=API_URL)
# a dict is sent as is: the Gladia Enterprise options included
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)
print("session:", session.session_id) # GET /v2/live/{id} names its pass (step 3)
sys.exit(1 if errors or not ended.is_set() else 0)

3. Find the pass in the session’s result

Section titled “3. Find the pass in the session’s result”

Once the session has ended, GET /v2/live/{id} names the pass:

{
"finalization": {
"id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b",
"result_url": "https://eu1.api.gladia.io/v2/pre-recorded/0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b"
}
}

The pass is a pre-recorded job over the call. When it is done, its callback reaches your callback_config.url (the pre-recorded transcription.success event, with the job’s id), and its result is read like any pre-recorded job’s:

Terminal window
curl https://eu1.api.gladia.io/v2/pre-recorded/0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b \
-H "x-gladia-key: $GLADIA_API_KEY"

Its result.transcription.utterances are the call’s utterances with their speaker, from the pre-recorded diarization. Keep the live transcript for the call’s own screen, and store this one.

Run the pass yourself, after any live session

Section titled “Run the pass yourself, after any live session”

The pass is POST /v2/pre-recorded with from_session_id in place of audio_url: you can run it on any of your ended live sessions that were recorded, with the options you choose, without finalization at its init:

Terminal window
curl -X POST https://eu1.api.gladia.io/v2/pre-recorded \
-H "x-gladia-key: $GLADIA_API_KEY" \
-H "content-type: application/json" \
-d '{"from_session_id": "0199d7a2-0000-7000-8000-0000000c0a11", "model": "solaria-3", "diarization": true}'
  • When the pass is ready. The recording is archived a few seconds after the session ends; the pass then runs like any pre-recorded job of your workspace, in its queue. A long call takes longer, a shorter one less.
  • Billing. The pass is billed as a pre-recorded job of solaria-3 with diarization, on the call’s duration, besides the live session.
  • Why a pass may be missing. finalization.error says why: not_recorded (no recording, or a call with no audio), interrupted (the connection dropped and the session was not resumed), refused (no pre-recorded host runs it, or your workspace’s queue is full: status gives the HTTP status), invalid_options, no_public_address or unavailable. You can still run it yourself with from_session_id.
  • Your options. The pass keeps the session’s language_config and custom_metadata; the add-ons of the live session (translation, named entities, …) are not run on it. Run the pass yourself with from_session_id to choose its options.
  • API keys. from_session_id reads a live session: a key needs the live scope (realtime_stt) as well as the pre-recorded one, and a member’s key reaches its own sessions only.