Code Examples
Complete code examples for real-time WebSocket transcription in Python, Node.js, and Browser JavaScript.
This guide contains complete examples demonstrating real-time audio transcription for various use cases in different programming languages.
- Python Example: Shows how to use websockets to transcribe a pre-recorded file in chunks.
- Node.js Example: Imitates real websocket usage by chunking a pre-recorded file in Node JS.
- JavaScript Example: Shows a browser example using Javascript.
- Streaming from Microphone: Shows real-time transcription from microphone audio.
Prerequisites
Python
Node.js
Python Example
This example shows how to stream audio from a file and receive real-time transcriptions:
Node.js Example
This example demonstrates real-time transcription using the ws library:
Browser JavaScript Example
This example shows how to stream audio from a file input in the browser:
Streaming from Microphone
Here’s an example of streaming live audio from a microphone in the browser:
Handling Responses
The WebSocket API sends JSON messages with the following structure:
Key Response Fields
is_final:falseindicates a partial/interim transcript;trueindicates a final transcriptis_last:truewhen the session is completetranscript: Current segment text. Concatenate eachis_final=truevalue to build a session-level transcript on the client.word_timestamps: Only included whenword_timestamps=truein query params
Browser
No additional dependencies required - uses native WebSocket API.
Error Handling
Always implement proper error handling for production use: