File size: 1,527 Bytes
bb3a349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""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)}")