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