Build a Django 5 application that captures browser microphone audio and streams it through Django Channels WebSockets to Deepgram's Live STT API, displaying transcription results on the page in real-time. The Deepgram API key stays server-side — the browser never sees it.
A Django web application that uses Django Channels to handle WebSocket connections from the browser. When a user clicks "Start Listening", the page captures microphone audio, streams it over a WebSocket to a Django Channels consumer, which forwards it to Deepgram's Live STT API (Nova-3). Transcription results flow back through the same WebSocket and appear on the page instantly.
- Python 3.11+
- Deepgram account — get a free API key
| Variable | Where to find it |
|---|---|
DEEPGRAM_API_KEY |
Deepgram console |
Copy .env.example to .env and fill in your values.
cd examples/220-django-channels-live-stt-python
pip install -r requirements.txt
cp .env.example .env
# Edit .env and add your DEEPGRAM_API_KEY
python src/manage.py runserverThen open http://127.0.0.1:8000 in your browser and click Start Listening.
| Parameter | Value | Description |
|---|---|---|
model |
nova-3 |
Deepgram's latest and most accurate speech recognition model |
smart_format |
True |
Adds punctuation, capitalization, and number formatting |
interim_results |
True |
Returns partial transcripts while you're still speaking |
encoding |
linear16 |
Raw 16-bit PCM audio format from the browser |
sample_rate |
16000 |
16 kHz sample rate — good balance of quality and bandwidth |
- Browser — the HTML page uses
getUserMediato capture microphone audio, resamples it to 16 kHz linear16 PCM via aScriptProcessorNode, and sends binary frames over a WebSocket to/ws/transcribe/ - Django Channels consumer (
consumer.py) — anAsyncWebsocketConsumerthat on connect opens a Deepgram live STT WebSocket using the official Python SDK (client.listen.v1.connect()) - Audio forwarding — each binary WebSocket frame from the browser is forwarded to Deepgram via
connection.send_media() - Transcript delivery — Deepgram fires
EventType.MESSAGEcallbacks withListenV1Results; the consumer sends each transcript back to the browser as JSON withis_finalindicating whether the result is finalized - Browser display — interim results appear greyed out and get replaced; final results are appended permanently
Browser Microphone
|
| WebSocket (binary PCM audio)
v
Django Channels Consumer
|
| Deepgram Python SDK (WebSocket)
v
Deepgram Live STT (nova-3)
|
| transcript JSON
v
Django Channels Consumer
|
| WebSocket (JSON)
v
Browser Display
If you want a ready-to-run base for your own project, check the deepgram-starters org — there are starter repos for every language and every Deepgram product.