Live transcription

Stream audio over a WebSocket and get each word about half a second after it's spoken.

Live transcription keeps a WebSocket open while someone speaks. You send audio as you capture it; words come back about half a second after they're spoken, and a complete, punctuated transcript arrives when you finish. It uses the same models and API key as file transcription, at $0.012 per minute of audio (see Limits and billing).

import time

from wistfareai import WistfareAI

client = WistfareAI()  # reads WISTFARE_API_KEY

with client.speech_to_text.realtime.connect(
    model="wistfare-stt-v3-beta",
    language="auto",
    latency="balanced",
    key_terms=["Kigali", "MTN MoMo"],
) as stream:                                  # returns once the model is ready
    with open("call-24k-mono.pcm", "rb") as f:   # 16-bit mono PCM, 24 kHz
        while chunk := f.read(15_360):           # 320 ms per chunk
            stream.send(chunk)
            for event in stream.poll():          # non-blocking
                if event.type == "partial":
                    print("…", event.text)       # still being recognised, may change
                elif event.type == "final":
                    print("✓", event.text)       # committed words
            time.sleep(0.32)                     # real-time pacing, like a microphone
    transcript = stream.end()                    # waits for the complete transcript

print(transcript.text)
print(transcript.transcription_id, transcript.cost_cents)

cURL can't hold a WebSocket open. To use the socket without an SDK, see the realtime protocol reference, which has a complete example in plain Python and Node.js.

How it works

Connect to wss://api.voice.wistfare.com/v1/stt/stream with your API key in the Authorization header and the options in the query string.

Stream audio: 16-bit PCM, mono, 24 kHz, in chunks of about 320 ms.

Read words. Each update has the newly completed words, the word still being recognised (the partial), and the detected language.

Finish: send the end message, receive the final transcript with its id and cost, and the server closes the socket.

Events

EventFieldsMeaning
partialtextThe words still being recognised. Replace it on every event.
finaltext, words, replaceWords that won't change: append them. replace is true after a recovery, when words is everything so far.
statusstate, messageThe service is reconnecting or catching up; keep sending audio.
donetext, transcriptThe complete transcript, also returned by end().
errorcode, message, transcriptThe session stopped. What was received is still saved and billed.

Only partial, final and done have text, so check event.type before reading it. Over the wire, partial and final come from the protocol's words messages and done from its final message; see the protocol reference.

From the microphone (Python)

With pip install "wistfareai[mic]", the Python SDK captures the default microphone, resamples it and streams it for you:

with client.speech_to_text.realtime.connect(language="rw") as live:
    try:
        for event in live.stream_microphone():   # Ctrl+C to stop
            if event.type == "final":
                print(event.text)
    except KeyboardInterrupt:
        pass                                     # leaving the loop stops the microphone
    print(live.end().text)

In JavaScript, capture with the Web Audio API and pass float samples to stream.sendFloat32(samples, sampleRate); see Streaming from a browser or app.

Options

OptionDefaultDescription
modelwistfare-stt-v3-betawistfare-stt-v3-beta, wistfare-stt-v2-beta or wistfare-stt-v1-beta.
languageautoA language code, or auto to detect the language of every sentence (v3).
latencybalancedv3: fast, balanced or accurate. See Latency.
key_terms / keyTerms (boost over HTTP)—v3: up to 100 names or phrases to favour (about 50 works best). See Key terms.
punctuationonv3: off returns lower-case words without punctuation.
sample_rate / sampleRate (SDK only)24000The rate of the PCM you send. The SDK resamples anything else to 24 kHz.

Live sessions don't label speakers; for who-said-what, transcribe the recording as a file with diarize=true.

Audio format

The server takes raw PCM: 16-bit signed little-endian samples, mono, 24,000 Hz, with no WAV header. The SDKs accept other rates (sample_rate / sampleRate) and resample for you; the Python SDK also takes numpy arrays (stream.send_numpy, with wistfareai[numpy]). Chunks of about 320 ms (7,680 samples, 15,360 bytes) are a good default. Send audio as it's captured. For audio that's already recorded, file transcription or a batch job is simpler.

To prepare test audio from any file:

ffmpeg -i meeting.mp3 -ac 1 -ar 24000 -f s16le call-24k-mono.pcm

Latency

latency (v3) sets how far the model looks ahead before it commits a word:

ValueWords appear afterAccuracy
fast≈ 0.32 sSlightly lower than the other settings.
balanced (default)≈ 0.56 sSame as accurate. Recommended.
accurate≈ 1.12 sUse when latency doesn't matter.

End-to-end delay also includes your chunk size and the network. With fast, send smaller chunks (80–160 ms) so audio doesn't wait in your buffer. Other models ignore latency.

Partial and final words

  • A partial is the word being recognised right now. It can still change, so replace it on every update.
  • Final words are committed: append them to your transcript. Each has its start time and, on v3, its sentence's language.
  • The done transcript at the end has every word with start and end, display-ready segments, the session's main language, a transcription_id and cost_cents. You can fetch it again later with GET /v1/stt/transcriptions/{id}; it also appears in the console history as "Live session".

If the connection to the model is interrupted, the service reconnects on its own and replays the buffered audio. Keep sending: you'll get a final event with replace set and the full word list once it's caught up. The protocol reference has the details.

A bad or revoked key is refused with HTTP 403 before the socket opens: the SDKs raise AuthenticationError, and invalid options or missing credits raise BadRequestError or InsufficientCreditsError from connect().

Limits and billing

LimitValueWhat happens
Audio per session15 minutesThe session ends with audio_limit and a final transcript. Open a new session to continue.
Wall-clock time per session20 minutesThe session ends with wall_clock_limit.
No audio30 seconds without audio framesThe session ends with audio_idle_timeout. Silent audio keeps a session open, but it is billed like any audio.
Concurrent sessions2 per account by defaultA third session is refused with concurrency_limit and close code 4429. Raisable on request.
Key terms100 per sessiontoo_many_boost_terms.
  • Billing is per second of audio you send, at $0.012 per minute on every model, with a minimum of one minute (2¢) for a session that received audio. The charge is made when the session ends, including when your client disconnects without finishing.
  • Credits are held a minute at a time. Before each new minute of audio, the next minute is reserved. If that fails, the session ends gracefully: you get insufficient_credits, then the final transcript of everything so far, and you're charged only for that audio.
  • If the model connection fails and can't recover, you're charged only for the audio up to the last committed word, and the error message states exactly what was charged.
  • Capacity: if all live capacity is in use, you get a busy error. Retry after a few seconds.

From a browser or mobile app

Your server can stream with the API key directly. If audio comes from a browser or mobile app, don't ship the key in the client: mint a single-use token on your server and connect the client with it. This is optional, and only needed for client-side streaming. See Streaming from a browser or app.

Next steps

On this page