File size: 1,650 Bytes
501847e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Simple Kokoro TTS Test Script
Run this after installing dependencies
"""

from kokoro import KPipeline
import soundfile as sf
import time

def main():
    print("🎡 Starting Kokoro TTS test...")
    
    # Initialize the model
    print("πŸ“¦ Loading model...")
    start_time = time.time()
    pipeline = KPipeline(lang_code='a')  # 'a' for English
    load_time = time.time() - start_time
    print(f"βœ… Model loaded in {load_time:.2f} seconds")
    
    # Test text
    text = "Hello! This is a test of Kokoro text-to-speech. The model sounds quite natural!"
    
    # Generate speech
    print("πŸ—£οΈ Generating speech...")
    gen_start = time.time()
    generator = pipeline(text, voice='af_heart')
    
    # Process and save audio
    for i, (gs, ps, audio) in enumerate(generator):
        gen_time = time.time() - gen_start
        duration = len(audio) / 24000  # seconds
        
        # Save audio file
        filename = f"kokoro_test_output_{i}.wav"
        sf.write(filename, audio, 24000)
        
        print(f"βœ… Generated {duration:.2f}s of audio in {gen_time:.2f}s")
        print(f"πŸ’Ύ Saved as: {filename}")
        print(f"⚑ Real-time factor: {gen_time/duration:.2f}x")
        
    print("πŸŽ‰ Test completed successfully!")
    print("🎧 Play the generated .wav file to hear the result")

if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        print(f"❌ Error: {e}")
        print("\nπŸ”§ Make sure you've installed all dependencies:")
        print("   brew install espeak")
        print("   pip install torch torchaudio kokoro>=0.9.2 soundfile")