File size: 2,623 Bytes
0232a88 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #!/usr/bin/env python3
"""SWARAI — local inference example.
Loads the SWARAI model directory (full fine-tune of Qwen3-TTS-0.6B-Base)
and synthesizes Indonesian speech with the single built-in speaker
"swarai".
Requirements:
pip install -U qwen-tts soundfile torch
# GPU recommended (bf16, ~4 GB VRAM). CPU works but is slow.
# Optional: pip install -U flash-attn --no-build-isolation
Usage:
python generate.py --model . \
--text "Halo, saya Suaray. Saya adalah model suara Bahasa Indonesia." \
--out swarai-demo.wav
python generate.py --model . --text "Selamat pagi." \
--out pagi.wav --sample # sampling instead of greedy
Notes:
- The model speaks with ONE built-in voice ("swarai"). It is not a general
voice cloner: there is no reference-audio input in this path. The base
Qwen3-TTS cloning capability is not exposed by this fine-tuned CustomVoice
model.
- The voice is the X-lord narrator (Dewi Anggreini reading "Ronggeng Dukuh
Paruk"). It is NOT a LibriVox voice. LibriVox readers 2814/3205/3232 were
used only for small separate probe fine-tunes during development.
- Indonesian text works with the default language handling; the model
was fine-tuned on normalized modern Indonesian (EYD).
- Pronunciation: write "SWARAI" as "Suaray" and "neugi.com" as
"niugi dot kom" in the input text if you want the brand names read
the way the author pronounces them.
"""
import argparse
import soundfile as sf
import torch
from qwen_tts import Qwen3TTSModel
def main() -> None:
ap = argparse.ArgumentParser(description="SWARAI local inference")
ap.add_argument("--model", required=True,
help="path to the SWARAI model directory")
ap.add_argument("--text", required=True, help="text to synthesize")
ap.add_argument("--out", default="swarai-output.wav",
help="output wav path (24 kHz)")
ap.add_argument("--sample", action="store_true",
help="use sampling (do_sample=True) instead of greedy")
ap.add_argument("--device", default="cuda:0",
help='torch device, e.g. "cuda:0" or "cpu"')
args = ap.parse_args()
tts = Qwen3TTSModel.from_pretrained(
args.model,
device_map=args.device,
dtype=torch.bfloat16,
attn_implementation="sdpa",
)
wavs, sr = tts.generate_custom_voice(
text=args.text,
speaker="swarai",
do_sample=args.sample,
)
sf.write(args.out, wavs[0], sr)
print(f"saved {args.out} sr={sr} duration={len(wavs[0]) / sr:.2f}s")
if __name__ == "__main__":
main()
|