Spaces:
Sleeping
Sleeping
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") |