Download examples/quickstart.py from changh95/Qwen3-TTS: direct link, hf CLI and curl.
- Browser
- Download file 2.9 kB
-
https://huggingface.co/changh95/Qwen3-TTS/resolve/main/examples/quickstart.py
- Command line
-
hf download hf://changh95/Qwen3-TTS/examples/quickstart.py
-
curl -L -o quickstart.py https://huggingface.co/changh95/Qwen3-TTS/resolve/main/examples/quickstart.py
2.9 kB
| #!/usr/bin/env python3 | |
| # SPDX-License-Identifier: Apache-2.0 | |
| """Qwen3-TTS quickstart (the Python API): one sentence to a WAV file, then the same sentence streamed packet by packet. | |
| python examples/quickstart.py [--profile 1.7b-customvoice] [--text "..."] [--fake] | |
| Needs ttnn (a tt-metal build with the patches in ../patches/, or the container image) and one p150; ``--fake`` runs | |
| the same host pipeline on the deterministic stand-in for the device (tones instead of speech; no chip, no weights). | |
| The weights are downloaded from Qwen's repositories at the pinned commits (Apache-2.0). Base profiles clone the | |
| reference clip shipped in code/tt_qwen3_tts/samples/ref_ryan_en/. | |
| """ | |
| import argparse | |
| import json | |
| import sys | |
| import time | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT / "code")) | |
| from tt_qwen3_tts import Qwen3TTS # noqa: E402 | |
| from tt_qwen3_tts.audio_io import encode_file # noqa: E402 | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--profile", default="1.7b-customvoice") | |
| ap.add_argument("--text", default="Hello from a Tenstorrent p150. This voice is generated as you listen.") | |
| ap.add_argument("--fake", action="store_true", help="the deterministic stand-in instead of the p150") | |
| ap.add_argument("--out", default="quickstart.wav") | |
| a = ap.parse_args() | |
| with Qwen3TTS.from_pretrained(a.profile, backend="fake" if a.fake else "tt") as tts: | |
| v = tts.variant | |
| kw = {"language": "English", "seed": 7} | |
| if v.is_custom_voice: | |
| kw["speaker"] = "ryan" | |
| elif v.is_voice_design: | |
| kw["instruct"] = "A warm, calm middle-aged male voice with a low pitch, speaking slowly and clearly." | |
| else: | |
| sample = ROOT / "code" / "tt_qwen3_tts" / "samples" / "ref_ryan_en" | |
| meta = json.loads((sample / "sample.json").read_text()) | |
| voice = tts.create_voice((sample / meta["file"]).read_bytes(), ref_text=meta["ref_text"], voice_id="ryan") | |
| print(f"voice {voice.id}: {voice.ref_frames} reference frames ({voice.ref_seconds:.2f} s)") | |
| kw["voice"] = "ryan" | |
| out = tts.synthesize(a.text, **kw) | |
| Path(a.out).write_bytes(encode_file(out.audio, "wav", out.sample_rate)) | |
| print(f"{v.name}: {out.frames} frames = {out.seconds:.2f} s of audio, stop {out.stop_reason}, seed {out.seed}, " | |
| f"timing {out.timing_ms} -> {a.out}") | |
| t0 = time.perf_counter() | |
| run = tts.stream(a.text, **kw) | |
| for p in run: | |
| if p.index < 3: | |
| print(f" packet {p.index}: {p.frames} frame(s) after {(time.perf_counter() - t0) * 1e3:.1f} ms") | |
| print(f"streamed {run.summary['packets']} packets, {run.summary['frames']} frames, first packet " | |
| f"{run.summary['timing_ms']['first_packet']} ms") | |
| if __name__ == "__main__": | |
| main() | |