title: Open-Source Voice Agent
emoji: π€
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false
license: apache-2.0
π€ Open-Source Voice Agent
End-to-end English voice agent built entirely from open-source HuggingFace models with a streaming overlap pipeline β TTS synthesis for sentence N starts the moment sentence N is detected in the LLM token stream, while the model continues generating sentences N+1, N+2 β¦ in parallel.
Models
| Stage | Model | Params | Device |
|---|---|---|---|
| VAD | silero-vad | 2 MB | CPU |
| STT | openai/whisper-base.en | 74 M | GPU / CPU |
| LLM | HuggingFaceTB/SmolLM2-1.7B-Instruct | 1.7 B | GPU / CPU |
| TTS | facebook/mms-tts-eng | ~430 M | CPU |
Lighter CPU-only alternative: swap STT β
whisper-tiny.en(39 M) and LLM βSmolLM2-360M-Instruct(360 M) inmodels.py.
Architecture
Browser mic (16 kHz PCM)
β
βΌ WebSocket binary frames
Silero VAD βββββββββββββββββββββββΊ discard noise/silence
β speech segment detected
βΌ
Whisper base.en βββββββββββββββββββΊ transcript text
β
βΌ
SmolLM2-1.7B (TextIteratorStreamer)
β token stream
βΌ
SentenceBuffer βββΊ complete sentence
β β
β MMS-TTS-eng (CPU executor) β overlap: LLM still generating!
β β
β PCM bytes βββΊ ws.send_bytes()
β β
ββββββββββββββββββββββ repeat until stream ends
β
βΌ
Browser AudioQueue βββΊ AudioContext playback
Streaming overlap benefit: while the browser plays sentence 1, the server is already synthesising sentence 2. This removes the full TTS latency from the inter-sentence gap, giving noticeably more natural turn-taking.
Project structure
sts-pipeline/
βββ app.py FastAPI server + WebSocket handler
βββ models.py All model loading & inference (STT/LLM/TTS/VAD)
βββ pipeline.py Streaming overlap pipeline
βββ sentence_buffer.py Token-stream β sentence boundary detector
βββ requirements.txt
βββ Dockerfile
βββ static/
βββ index.html Browser UI
βββ app.js WebSocket client + audio queue
βββ audio-capture-worklet.js Mic capture @ 16 kHz (AudioWorklet)
Local development
# 1. Clone
git clone https://huggingface.co/spaces/<your-user>/voice-agent
cd voice-agent
# 2. Install (GPU)
pip install -r requirements.txt
# 2b. Install (CPU-only)
pip install torch==2.5.1+cpu torchaudio==2.5.1+cpu \
--index-url https://download.pytorch.org/whl/cpu
pip install -r requirements.txt
# 3. Run
python app.py # or: uvicorn app:app --port 7860
# Open http://localhost:7860
Models are downloaded automatically on first run (3 GB total) and cached in
`/.cache/huggingface/hub`.
HuggingFace Spaces deployment
- Create a new Space β Docker SDK.
- Push this repo as-is.
- The Space will build the Docker image and serve on port 7860.
- For GPU hardware: remove the CPU-only torch lines in
Dockerfileand uncomment the plainpip install -r requirements.txt.
WebSocket protocol reference
| Direction | Frame type | Payload |
|---|---|---|
| Client β Server | binary | PCM int16, mono, 16 kHz, 640 B chunks |
| Client β Server | text | {"type":"start"} or {"type":"stop"} |
| Server β Client | binary | PCM int16, mono, 16 kHz (TTS audio) |
| Server β Client | text | {"type":"transcript","text":"..."} |
| Server β Client | text | {"type":"agent_start"} |
| Server β Client | text | {"type":"agent_done","text":"...","latency_ms":000} |
| Server β Client | text | {"type":"error","message":"..."} |
License
Apache 2.0 β all component models carry their own licenses; see their respective HuggingFace model cards for terms of use.