File size: 2,553 Bytes
10ea2f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393129e
10ea2f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393129e
10ea2f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Chiluka TTS - HuggingFace Hub Example

Load model weights directly from HuggingFace Hub.
No need to clone the repository or download weights manually.

Requirements:
    pip install chiluka
    sudo apt-get install espeak-ng

Usage:
    python huggingface_example.py --reference path/to/reference.wav
    python huggingface_example.py --reference ref.wav --model telugu --language te --text "నమస్కారం"
"""

import argparse
from chiluka import Chiluka, list_models


def main():
    parser = argparse.ArgumentParser(description="Chiluka TTS - HuggingFace Hub Example")
    parser.add_argument("--reference", type=str, required=True, help="Path to reference audio file")
    parser.add_argument("--model", type=str, default="hindi_english", choices=["hindi_english", "telugu"],
                        help="Model variant to use (default: hindi_english)")
    parser.add_argument("--text", type=str, default=None, help="Text to synthesize")
    parser.add_argument("--language", type=str, default=None, help="Language code (en-us, hi, te)")
    parser.add_argument("--output", type=str, default="output_hf.wav", help="Output wav file path")
    parser.add_argument("--device", type=str, default=None, help="Device: cuda or cpu")
    args = parser.parse_args()

    # Show available models
    print("Available models:")
    for name, info in list_models().items():
        marker = " <--" if name == args.model else ""
        print(f"  {name}: {info['description']}{marker}")
    print()

    # Set defaults based on model choice
    if args.text is None:
        if args.model == "telugu":
            args.text = "నమస్కారం, నేను చిలుక మాట్లాడుతున్నాను"
        else:
            args.text = "Hello, I am Chiluka, a text to speech system."

    if args.language is None:
        if args.model == "telugu":
            args.language = "te"
        else:
            args.language = "en-us"

    # Load model from HuggingFace Hub (auto-downloads on first use)
    print(f"Loading '{args.model}' model from HuggingFace Hub...")
    tts = Chiluka.from_pretrained(model=args.model, device=args.device)

    # Synthesize
    print(f"Synthesizing: '{args.text}'")
    print(f"Language: {args.language}")
    wav = tts.synthesize(
        text=args.text,
        reference_audio=args.reference,
        language=args.language,
    )

    # Save
    tts.save_wav(wav, args.output)
    print(f"Duration: {len(wav) / 24000:.2f} seconds")


if __name__ == "__main__":
    main()