WebSocket API
Connect to ws://HOST:PORT/audio (default port 8000 or 8001 in docs examples).
Client → server (binary)
Send raw PCM frames continuously while the user is speaking:
| Property | Value |
|---|---|
| Encoding | linear16 (signed 16-bit LE) |
| Sample rate | 16000 Hz |
| Channels | 1 (mono) |
| Frame size | Flexible; reference client uses 512–1024 samples/chunk |
Server → client (binary)
TTS audio chunks during a reply:
| Property | Value |
|---|---|
| Encoding | linear16 |
| Sample rate | 24000 Hz (configurable via TTS_SAMPLE_RATE) |
| Channels | 1 |
Server → client (JSON text)
Status and fallback text when voice fails:
{ "type": "status", "message": "Thinking…" }
{ "type": "status", "message": "Speaking…" }
{ "type": "status", "message": "Ready — speak anytime" }
{ "type": "reply_text", "message": "Full LLM text if TTS failed" }
{ "type": "error", "message": "Human-readable error" }Utterance lifecycle
- Client streams PCM while user talks
- Deepgram emits interim + final transcripts;
speech_finalmarks end of phrase - Server debounces (~120 ms in demo mode) then merges segments into one user question
- LLM + TTS pipeline runs; client should play binary chunks and show JSON status
- While AI speaks, reference client ducks mic (optional barge-in on loud speech)
Building your own client
- Use any WebSocket library; set
max_size=Nonefor large TTS frames - Run one task for
send(mic_pcm)and one forrecv()(duplex) - Parse string frames as JSON; treat everything else as PCM for playback
- See
scripts/send_test_pcm.pyforTtsPlaybackandcontinuous_tts_playback