Audio version — Estimated duration: 5 min 53 sec
File: md_to_audio_base.py
Usage
python md_to_audio_base.py <input_md> --ref_audio <wav> --ref_text <transcript> [options]Arguments
input_md (positional, required)
Path to the input Markdown file. The script reads this file, strips Markdown formatting, and generates speech from the remaining text.
python md_to_audio_base.py sample.md --ref_audio voice.wav --ref_text "..."If the file doesn’t exist, the script prints an error and exits.
--model_path
| Type | Default |
|---|---|
str | ./Qwen3-TTS-12Hz-0.6B-Base |
Path to the Base model directory. This must contain the model files downloaded from Hugging Face (config.json, model safetensors, tokenizer files, etc.).
python md_to_audio_base.py sample.md \
--model_path /mnt/models/Qwen3-TTS-Base \
--ref_audio voice.wav --ref_text "..."--ref_audio (required)
| Type | Default |
|---|---|
str | — (required) |
Path to a WAV file containing the reference voice to clone. The audio should be:
- 5–15 seconds long
- Clean (no background noise, music, or reverb)
- Same speaker throughout
- Sampled at any rate (the model handles resampling)
--ref_text (required)
| Type | Default |
|---|---|
str | — (required) |
The verbatim transcript of --ref_audio. Every word, every filler — “um”, “uh”, pauses — if they’re in the audio, include them. Even small mismatches (“it’s” vs “it is”) noticeably degrade clone quality.
--output
| Type | Default |
|---|---|
str | output.wav |
Path for the output WAV file. The audio is always 24 kHz mono 32-bit float. If the file exists, it will be overwritten.
python md_to_audio_base.py sample.md --ref_audio v.wav --ref_text "..." --output my_clone.wav--lang
| Type | Default |
|---|---|
str | English |
Language for generation. Must match both the reference audio language and the input text language. Supported values include English, Chinese, Japanese, Korean, French, German, Spanish (depends on the model’s training data).
--chunk_size
| Type | Default | Range |
|---|---|---|
int | 200 | 50–500 |
Maximum characters per chunk. The script splits text at sentence boundaries (.!?), and falls back to commas for long sentences. Smaller chunks use less VRAM but may chop sentences mid-phrase.
| Value | Effect |
|---|---|
| 100 | Fast, but may sound choppy |
| 200 (default) | Good balance |
| 400 | Smoother prosody, more VRAM |
--batch_size
| Type | Default | Range |
|---|---|---|
int | 4 | 1–16 |
Number of chunks to process in a single GPU call. Higher values increase throughput but require more VRAM. If a batch fails (OOM), the script falls back to sequential generation automatically.
| VRAM | Recommended |
|---|---|
| 6 GB | 1–2 |
| 8 GB | 2–4 |
| 12 GB+ | 4–8 |
Behaviour details
Model loading
The script loads the model with:
torch_dtype=torch.float16— half precision, saves VRAMattn_implementation="sdpa"— PyTorch’s scaled dot-product attention- TF32 matmul and cuDNN kernels enabled (
torch.backends.cuda.matmul.allow_tf32,torch.backends.cudnn.allow_tf32)
Generation
Each chunk is generated with max_new_tokens=1024 (fixed). The model produces audio tokens at 12 Hz, so 1024 tokens ≈ 85 seconds of audio — more than enough for any chunk.
Error handling
- If the input Markdown file is empty after cleaning → prints error, exits
- If the model fails to load → prints error, exits
- If a batch fails during generation → falls back to sequential processing per chunk
- If no audio is generated at all → prints error, exits
Output
- Format: WAV
- Sample rate: 24 kHz
- Channels: Mono
- Bit depth: 32-bit float
See Voice Cloning Guide for usage examples.