# Qwen3-TTS on Tenstorrent p150: Python API Alibaba Qwen's Qwen3-TTS (0.6B / 1.7B Base voice clone, 0.6B / 1.7B CustomVoice, 1.7B VoiceDesign) on one Tenstorrent Blackhole p150. The HTTP server of this package (`tt_qwen3_tts.server.app`) serves exactly this API: a request's fields are the keyword arguments below, validated by the same function. The weights are Qwen's (Apache-2.0) and are not part of this package: they are downloaded from `Qwen/Qwen3-TTS-12Hz-*` and `Qwen/Qwen3-TTS-Tokenizer-12Hz` at pinned commits ([`tt_qwen3_tts/licenses/NOTICE.md`](tt_qwen3_tts/licenses/NOTICE.md)). This package is a third-party port, not affiliated with or endorsed by Alibaba or the Qwen team. ## Install The container image has everything. Outside it you need a host build of tt-metal (`ttnn`) at the commit of the package's Provenance with the patches in `patches/` applied, then, from the root of the model repo: ```bash pip install -e . # numpy<2, safetensors, huggingface_hub, tokenizers, soundfile, soxr pip install -e ".[server,test]" # + fastapi, uvicorn, pytest, httpx ``` ## Quickstart ```python from tt_qwen3_tts import Qwen3TTS with Qwen3TTS.from_pretrained("1.7b-customvoice") as tts: # pinned weights -> chip (ETH, 12x10) -> warm-up out = tts.synthesize("Hello from a Tenstorrent p150.", speaker="ryan", language="English", seed=7) print(out.audio.shape, out.sample_rate, out.frames, out.stop_reason, out.timing_ms) run = tts.stream("A longer sentence, streamed as it is generated.", speaker="vivian", packet_frames=4) for packet in run: # float32 numpy, 24 kHz, 1 frame first then 4 play(packet.audio) print(run.summary) # frames, seed, stop reason, timing ``` `from_pretrained(variant, **overrides)` takes a serve profile (`0.6b-base`, `1.7b-base`, `0.6b-customvoice`, `1.7b-customvoice`, `1.7b-voicedesign`), an official name (`1.7B-CustomVoice`) or a repo id; the keyword overrides are the server-start settings of `config.ServeConfig` (`max_positions`, `prefill_buckets`, `chunk_max`, `k_max`, `engine`, `precision`, `codec_mode`, `weights_dir`, `codec_dir`, `dispatch`, `backend`, ...), which otherwise come from the `QWEN3TTS_*` environment. `backend="cpu"` runs the same API on the float32 CPU reference engines (real speech, no chip, about 0.6 s per 80 ms frame for 0.6B); `backend="fake"` on a deterministic stand-in for the device (no chip, no weights; tones instead of speech) for development and tests. The first `from_pretrained` of a checkpoint builds the device engines' caches (the projected text table, the talker's packed weights, the codec decoder's programs, the host build of the device sampler: about 1.3 GB per 0.6B and 2.6 GB per 1.7B checkpoint) under `QWEN3TTS_CACHE_DIR` (the `cache_dir` override), default `~/.cache/tt_qwen3_tts`; later calls reuse them. tt-metal keeps its compiled kernels in its own cache (`TT_METAL_CACHE`). ## Voice cloning (Base profiles) ```python with Qwen3TTS.from_pretrained("1.7b-base") as tts: voice = tts.create_voice(open("reference.wav", "rb").read(), # or (waveform, sample_rate) ref_text="exactly what the clip says", voice_id="me") out = tts.synthesize("Now in the cloned voice.", voice="me", language="English") # or inline, without registering: ref_audio=..., ref_text=... # x_vector_only_mode=True clones from the speaker embedding alone (no transcript; lower similarity) ``` A voice keeps the speaker embedding, the reference clip's codec codes and the transcript; the uploaded file itself is not kept. The codec codes are a compressed encoding of the clip (the codec decoder turns them back into an intelligible version of it: 12 dB SNR, the same transcript, speaker similarity 0.999 in an independent check), so a stored voice is as sensitive as the recording. `QWEN3TTS_VOICES=` (or `voices_dir=`) persists voices as `.safetensors` + `.json`. ## Parameters | keyword | profiles | default | valid | | --- | --- | --- | --- | | `text` | all | required | up to `QWEN3TTS_MAX_TEXT_CHARS` (10,000); longer than one prompt: split at sentences, one continuous stream | | `language` | all | `auto` | auto, chinese, english, japanese, korean, german, french, russian, portuguese, spanish, italian | | `speaker` | CustomVoice | required | aiden, dylan, eric, ono_anna, ryan, serena, sohee, uncle_fu, vivian | | `instruct` | 1.7B CustomVoice, VoiceDesign | `""` | text; `InputError` on 0.6B CustomVoice and Base | | `voice` / `ref_audio` / `ref_text` / `x_vector_only_mode` | Base | -- | a stored voice id, or an inline clip (bytes, base64, `(array, rate)`) and its transcript | | `non_streaming_mode` | all | True (CustomVoice, VoiceDesign), False (Base) | the official prompt layout | | `do_sample`, `temperature`, `top_k`, `top_p`, `repetition_penalty` | all | True, 0.9, 50, 1.0, 1.05 | T > 0; top_k 0 or 1..`K_MAX` (64; >= 2049 = off); top_p [0, 1]; penalty > 0 | | `subtalker_dosample`, `subtalker_temperature`, `subtalker_top_k`, `subtalker_top_p` | all | True, 0.9, 50, 1.0 | as above | | `max_new_tokens` | all | 8192 | >= 2: at most `max_new_tokens - 1` frames in total | | `seed` | all | random | 0 .. 2^64 - 1 (text chunk i of a long request uses `seed + i * 0x9E3779B97F4A7C15`) | | `response_format`, `sample_rate` | all | `wav`, 24000 | used by the server's encoders (`synthesize` returns float32; `sample_rate` resamples it) | | `stream`, `packet_frames`, `first_packet_frames` | all | True, 4, 1 | packet sizes 1..`CHUNK_MAX` (8) | Errors are `tt_qwen3_tts.InputError` (HTTP 400 in the server) with the reason. ## Pieces - `tt_qwen3_tts.frontend`: `QwenTokenizer` (the checkpoints' Qwen2 BPE through `tokenizers`), `build_plan` (the prompt of every official mode as ids), `materialize` (ids -> float32 rows through an embedder), `HostEmbedder`, `split_text`. - `tt_qwen3_tts.audio_io`: reference decoding (WAV, FLAC, OGG, MP3 via libsndfile; mono mix; soxr resampling to 24 kHz), the output encoders (`AudioEncoder`: wav / pcm / f32 / flac, streaming or one file). - `tt_qwen3_tts.tt.model.Qwen3TTSDevice`: the device engines (talker, code predictor, codec decoder) behind `start` / `step` / `poll` / `decode` and the codec-state calls.