Skip to main content

Qwen3-TTS Streaming Engine (fast_tts)

GitHub Repository

True-streaming speech synthesis for Qwen3-TTS-0.6B, with CUDA Graphs acceleration for real-time playback. Installable as a PyPI package: pip install qwen3-tts-streaming.

What's inside

Component Description
fast_tts/ The pip-installable package — streaming engine, audio player, CLI, and the CUDA-graph patch for stock qwen-tts
fast_tts/engine.py FastTTSv14 — true streaming via native generate_custom_voice_streaming, seamless chunk concatenation
fast_tts/player.py StreamingAudioPlayer — callback-based live playback (sounddevice) with backpressure
fast_tts/_patch/ CUDA Graph acceleration (PredictorGraph, TalkerGraph) + streaming methods — our own implementation (provenance and attribution in the License section); attached to stock Qwen3TTSModel at import time
profile_v14.py Baseline profiler: load/capture cost, Mimi decode vs context, TTFA/RTF, token-cap usage
run_native.py / run_faster.py Quick tests of the native and FasterQwen3TTS streaming APIs
bench_sdpa.py SDPA attention performance benchmark
debug_graphs.py CUDA graph timing diagnostics
test_v14.py Full test suite — 10 sentences with playback verification
*.bat Windows launchers (double-click or from terminal)
docs/ Technical documentation on the optimizations
Qwen3-TTS/ Official Qwen3-TTS source (Apache-2.0) — development reference only, not shipped; the package itself works against plain pip install qwen-tts

Results on RTX 5060 Ti (CC 12.0)

Metric Before optimization After Speedup
ms/step ~248ms 31ms 7.9x
RTF 0.336 (slower than realtime) 2.67 (2.7× faster than realtime) 8.0x
TTFA (time to first audio) ~40s ~355ms 113x

Key optimizations

CUDA Graphs

  • PredictorGraph — captures the full 15-step code predictor loop as a single CUDA graph (~26ms vs ~190ms)
  • TalkerGraph — captures single-token talker decode (~12ms vs ~75ms)
  • Uses transformers.StaticCache instead of DynamicCache for fixed-size KV buffers

Streaming pipeline (v14)

  • Native generate_custom_voice_streaming() — no manual token management
  • Producer-consumer architecture: generation thread → queue → player
  • Automatic long-text segmentation via split_segments()
  • Seamless chunk concatenation (stateful generation preserves phase continuity)
  • 0.3s preroll — audio starts in ~350ms

Installation

1. Install the package

pip install qwen3-tts-streaming

This pulls qwen-tts, transformers, accelerate, torchaudio, soundfile, sounddevice and friends automatically. The streaming + CUDA-graph methods are attached to stock Qwen3TTSModel at import time — no patched or editable qwen_tts copy needed.

CUDA note: for GPU use, make sure you have a PyTorch build with your CUDA version (e.g. pip install torch --index-url https://download.pytorch.org/whl/cu126). Plain PyPI wheels are CPU-only on some platforms — check with torch.cuda.is_available().

2. Get the model weights

Download Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice from Hugging Face and point --model / MODEL_PATH at the local directory.

Attention implementation

SDPA attention is used by default — it is compatible with CUDA graph capture. Flash Attention 2 is NOT compatible with CUDA graph capture and will crash during warmup (CUDA error: operation not permitted when stream is capturing).

Quick start

CLI

fast-tts --model /path/to/Qwen3-TTS-0.6B --text "Hello world"
# or via env var:
MODEL_PATH=/path/to/model fast-tts --text "Привет мир"

Options: --speaker (default Sohee), --chunk-size {2,4,8}, --min-start-sec, --device <audio-device-index> (interactive menu if omitted).

Python API

from fast_tts import FastTTSv14

tts = FastTTSv14(
    model_path="Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice",
    speaker="Sohee",
)

# Streaming generation with live playback (optionally saves a WAV)
tts.generate_and_play("Hello! This is a streaming TTS test.", save_wav="out.wav")

Generation architecture (v14)

Text → split_segments() → generate_custom_voice_streaming() × N segments
                                      ↓
                    Talker prefill + Predictor × 15 (CUDA graphs)
                                      ↓
                    Codec tokens [cb0..cb14] → chunked_decode()
                                      ↓
                    Producer thread → queue → StreamingAudioPlayer
                                      ↓
                    Concatenate chunks (stateful) → Live playback @24kHz

Dependencies

  • Python 3.10+
  • PyTorch ≥ 2.5.1 with CUDA (for GPU use)
  • qwen-tts>=0.1.1,<0.2 — the overlay is verified against this API; a future qwen-tts release that renames any of its touchpoints will fail fast at import/load time (fast_tts._compat) instead of crashing mid-streaming
  • transformers>=4.57,<5
  • accelerate, torchaudio, soundfile, sounddevice, numpy

Repository layout (dev repo)

qwen3-tts-streaming/
├── fast_tts/                     # The pip package (built by hatchling, see pyproject.toml)
│   ├── __init__.py               # Exports + applies the qwen_tts patch on import
│   ├── engine.py                 # FastTTSv14 — true streaming, seamless chunk concatenation
│   ├── player.py                 # StreamingAudioPlayer — callback-based live playback
│   ├── cli.py                    # `fast-tts` entry point + dev test suite
│   └── _patch/                   # CUDA-graph modules + streaming methods (our own implementation — see License section)
├── fast_tts_v14.py               # Backward-compat shim → re-exports from the package
├── run_native.py / run_faster.py # Quick API tests
├── bench_sdpa.py                 # SDPA attention benchmark
├── debug_graphs.py               # CUDA graph timing diagnostics
├── test_v14.py                   # Full test suite — 10 sentences + playback
├── profile_v14.py                # Baseline profiler: load/capture, Mimi vs ctx, TTFA/RTF, token caps
├── pyproject.toml / LICENSE      # Packaging metadata (hatchling) + MIT license
├── *.bat                         # Windows launchers (double-click friendly)
├── docs/
│   ├── cuda_graphs_optimization.md  # Detailed CUDA Graphs breakdown
│   └── qwen3-tts-implementation.md  # Architecture and version history
└── Qwen3-TTS/                    # Official Qwen3-TTS source — dev-time reference only, not shipped

License

  • This package (fast_tts) — MIT (see LICENSE). Provenance of the _patch/ modules: the CUDA-graph capture strategy follows the approach published in faster-qwen3-tts (MIT, © andimarafioti); our implementation is written independently against that design. The talker input construction follows the official Qwen3-TTS algorithm (Apache-2.0), restructured with hoisted constants and per-sample helper dispatch.
  • Base model Qwen3-TTS and the qwen-tts dependency — Apache 2.0, Alibaba Group / QwenLM.

Metadata

Release files for qwen3-tts-streaming 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qwen3-tts-streaming 0.1.2
File Size Uploaded
qwen3_tts_streaming-0.1.2.tar.gz 30.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qwen3-tts-streaming 0.1.2
File Interpreter ABI Platform
qwen3_tts_streaming-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 65.6 kB

Release files / qwen3_tts_streaming-0.1.2.tar.gz

Download URL qwen3_tts_streaming-0.1.2.tar.gz
Size 30.9 kB
Tags Source
SHA-256 checksum
How to use checksums
344c7225c8a89809343d1b3c04231db6ef01d226e2a9b7b5b385d0e041fc3202
BLAKE2b-256 checksum
How to use checksums
344a4f695db938945adce62cd200e3949b24e012eda10917cb367ca4b8b644e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.13

Release files / qwen3_tts_streaming-0.1.2-py3-none-any.whl

Download URL qwen3_tts_streaming-0.1.2-py3-none-any.whl
Size 34.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0389403b51683c778041461e127a7746a5ca2748ea54b080c43c8ae6f96197c0
BLAKE2b-256 checksum
How to use checksums
194c576bbe1585d0585ea7338119eb64ea25f4f08cb3ed25a359502687bbef22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.13

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page