Skip to main content
This guide streams a WAV file to the streaming WebSocket the way a live microphone would, prints the text as it is recognized, and then prints the final transcript.

Prerequisites

1

Create an API key

Sign in to the Chariot dashboard and generate an API key. Speech to text uses the same key and chariotai-api-key header as text to speech.
2

Prepare an audio file

Use a 16-bit mono WAV file recorded at 8, 16, 22.05, 24, 32, 44.1, or 48 kHz. The examples read the sample rate from the file and declare it with audio_format, for example pcm_16000 for 16 kHz.
3

Install a WebSocket client

Python: pip install websockets (version 14 or later). Node.js: npm install ws (Node.js 18 or later).

Stream a file

Save the Node.js example as transcribe.mjs so it can use import and top-level await.

What happens

1

The session starts

After the connection opens, the server sends session.started with a session_id and the settings in effect. Start sending audio when it arrives.
2

You stream audio

Each binary frame carries raw 16-bit little-endian samples in the declared audio_format. There is no JSON envelope and no base64.
3

Text arrives as it is recognized

transcript.delta events carry new text. Append each one to show a live transcript.
4

You finish

input.done tells the server no more audio is coming. It transcribes what is left, sends transcript.done with the complete transcript, and closes the connection with code 1000.
The session costs 1.5 credits per second of audio you sent. A 60-second file costs 90 credits.

Next steps

Streaming WebSocket

Every parameter, event, and close code.

Languages, modes, and styles

Pick a language hint, a latency mode, and an output style.

Audio formats

Microphone, telephony, and file audio.

Session history

Look up past sessions and their transcripts.