| """Command-line interface for Ava Persian TTS.""" |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| from pathlib import Path |
|
|
| from .model import Ava |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser(description="Generate Persian speech with Ava") |
| parser.add_argument("text", nargs="?", help="Persian text to speak") |
| parser.add_argument("--text-file", type=Path, help="read Persian text from a UTF-8 file") |
| parser.add_argument("-o", "--output", type=Path, default=Path("ava.wav")) |
| parser.add_argument("--speed", type=float, default=1.0) |
| parser.add_argument( |
| "--device", |
| choices=("auto", "cpu", "mps", "cuda"), |
| default="auto", |
| ) |
| parser.add_argument( |
| "--raw-boundaries", |
| action="store_true", |
| help="disable the recommended leading/trailing artifact cleanup", |
| ) |
| args = parser.parse_args() |
|
|
| text = args.text |
| if args.text_file: |
| text = args.text_file.read_text(encoding="utf-8") |
| if not text: |
| parser.error("provide Persian text or --text-file") |
|
|
| tts = Ava(device=args.device) |
| result = tts.generate( |
| text, |
| speed=args.speed, |
| cleanup=not args.raw_boundaries, |
| ) |
|
|
| import soundfile as sf |
|
|
| args.output.parent.mkdir(parents=True, exist_ok=True) |
| sf.write(args.output, result.audio, result.sample_rate, subtype="PCM_16") |
| print(f"Saved {result.duration:.2f}s of speech to {args.output.resolve()}") |
| print(f"Device: {result.device}; segments: {len(result.phonemes)}") |
|
|
|
|