Low-latency streaming TTS server using Dia2, optimized for voice call applications.
| Scenario | Latency |
|---|---|
| Cold start (first sentence) | ~1.44s (delay buffer fill) |
| Warm continuation (inject) | ~80-160ms |
| Per-frame streaming | 80ms chunks |
# Clone the repo
git clone https://github.com/runvnc/dia2stream.git
cd dia2stream
# Install PyTorch with CUDA first (if not already installed)
pip install torch --index-url https://download.pytorch.org/whl/cu124
# Then install other dependencies and run
uv run python server.py
Or if torch is already installed in your environment:
git clone https://github.com/runvnc/dia2stream.git
cd dia2stream
uv run --no-sync python server.py # Skip dependency sync if torch already present
First run will download the Dia2-2B model (~4GB).
git clone https://github.com/runvnc/dia2stream.git
cd dia2stream
pip install torch --index-url https://download.pytorch.org/whl/cu124
pip install transformers huggingface_hub websockets numpy soundfile
python server.py
WebSocket Client
|
v
+---------------+
| Server |
| (server.py) |
+---------------+
|
+---------------+---------------+
| |
v v
StreamingSession Dia2 Model (GPU)
- KV Cache (warm) - Transformer
- Audio Buffer - Depformer
- State Machine - Mimi Codec
python server.py
Server listens on ws://0.0.0.0:8765
python test_client.py
Commands (JSON):
// Start new session (cold start)
{"cmd": "start", "text": "[S1] Hello world!"}
// Inject more text (warm, low latency)
{"cmd": "inject", "text": "[S1] More text here."}
// Pause generation
{"cmd": "pause"}
// Reset session completely
{"cmd": "reset"}
Responses:
<4 bytes: sample count><PCM16 audio data>{"event": "done"}, {"event": "paused"}, etc.For optimal latency in a voice call:
Call Start: Initialize with greeting
{"cmd": "start", "text": "[S1] Hello, how can I help you today?"}
User Speaks: Pause TTS, run STT + LLM
{"cmd": "pause"}
Agent Responds: Inject LLM output (low latency!)
{"cmd": "inject", "text": "[S1] Sure, I can help with that."}
Repeat steps 2-3 for conversation turns
Edit server.py to adjust:
self.default_config = GenerationConfig(
cfg_scale=3.0, # Classifier-free guidance
text=SamplingConfig(temperature=0.7, top_k=50),
audio=SamplingConfig(temperature=0.8, top_k=80),
initial_padding=0, # 0 for minimum latency
)
self.chunk_frames = 1 # 1 = decode every frame (80ms)
dia2stream/
├── dia2/ # Vendored Dia2 library
├── server.py # Main streaming server
├── test_client.py # Test client
├── pyproject.toml # uv/pip configuration
└── README.md
10 commits
Python
100.0%
Low-latency streaming TTS server using Dia2, optimized for voice call applications.
| Scenario | Latency |
|---|---|
| Cold start (first sentence) | ~1.44s (delay buffer fill) |
| Warm continuation (inject) | ~80-160ms |
| Per-frame streaming | 80ms chunks |
# Clone the repo
git clone https://github.com/runvnc/dia2stream.git
cd dia2stream
# Install PyTorch with CUDA first (if not already installed)
pip install torch --index-url https://download.pytorch.org/whl/cu124
# Then install other dependencies and run
uv run python server.py
Or if torch is already installed in your environment:
git clone https://github.com/runvnc/dia2stream.git
cd dia2stream
uv run --no-sync python server.py # Skip dependency sync if torch already present
First run will download the Dia2-2B model (~4GB).
git clone https://github.com/runvnc/dia2stream.git
cd dia2stream
pip install torch --index-url https://download.pytorch.org/whl/cu124
pip install transformers huggingface_hub websockets numpy soundfile
python server.py
WebSocket Client
|
v
+---------------+
| Server |
| (server.py) |
+---------------+
|
+---------------+---------------+
| |
v v
StreamingSession Dia2 Model (GPU)
- KV Cache (warm) - Transformer
- Audio Buffer - Depformer
- State Machine - Mimi Codec
python server.py
Server listens on ws://0.0.0.0:8765
python test_client.py
Commands (JSON):
// Start new session (cold start)
{"cmd": "start", "text": "[S1] Hello world!"}
// Inject more text (warm, low latency)
{"cmd": "inject", "text": "[S1] More text here."}
// Pause generation
{"cmd": "pause"}
// Reset session completely
{"cmd": "reset"}
Responses:
<4 bytes: sample count><PCM16 audio data>{"event": "done"}, {"event": "paused"}, etc.For optimal latency in a voice call:
Call Start: Initialize with greeting
{"cmd": "start", "text": "[S1] Hello, how can I help you today?"}
User Speaks: Pause TTS, run STT + LLM
{"cmd": "pause"}
Agent Responds: Inject LLM output (low latency!)
{"cmd": "inject", "text": "[S1] Sure, I can help with that."}
Repeat steps 2-3 for conversation turns
Edit server.py to adjust:
self.default_config = GenerationConfig(
cfg_scale=3.0, # Classifier-free guidance
text=SamplingConfig(temperature=0.7, top_k=50),
audio=SamplingConfig(temperature=0.8, top_k=80),
initial_padding=0, # 0 for minimum latency
)
self.chunk_frames = 1 # 1 = decode every frame (80ms)
dia2stream/
├── dia2/ # Vendored Dia2 library
├── server.py # Main streaming server
├── test_client.py # Test client
├── pyproject.toml # uv/pip configuration
└── README.md
10 commits
Python
100.0%