Spaces:
Running
Running
File size: 2,204 Bytes
b388a4a |
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 |
#!/usr/bin/env python3
"""
Test script for KittenTTS functionality
"""
import soundfile as sf
import numpy as np
from kittentts import KittenTTS
def test_kittentts():
"""Test the KittenTTS model with a simple example"""
print("π Testing KittenTTS...")
try:
# Initialize the model
print("π¦ Loading KittenTTS model...")
model = KittenTTS("KittenML/kitten-tts-nano-0.1")
print("β
Model loaded successfully!")
# Test text
test_text = "Hello! This is a test of the KittenTTS model."
test_voice = 'expr-voice-2-f'
print(f"π€ Generating speech for: '{test_text}'")
print(f"π΅ Using voice: {test_voice}")
# Generate audio
audio = model.generate(test_text, voice=test_voice)
print(f"β
Audio generated successfully!")
print(f"π Audio shape: {audio.shape}")
print(f"π Audio dtype: {audio.dtype}")
print(f"π Audio range: {np.min(audio):.4f} to {np.max(audio):.4f}")
# Save test audio
output_file = 'test_output.wav'
sf.write(output_file, audio, 24000)
print(f"πΎ Audio saved to: {output_file}")
# Test all voices
print("\nπ Testing all available voices...")
available_voices = [
'expr-voice-2-m', 'expr-voice-2-f', 'expr-voice-3-m', 'expr-voice-3-f',
'expr-voice-4-m', 'expr-voice-4-f', 'expr-voice-5-m', 'expr-voice-5-f'
]
for i, voice in enumerate(available_voices, 1):
print(f" {i}/8: Testing {voice}...")
try:
test_audio = model.generate("Test voice.", voice=voice)
print(f" β
{voice} works!")
except Exception as e:
print(f" β {voice} failed: {e}")
print("\nπ All tests completed successfully!")
return True
except Exception as e:
print(f"β Test failed: {e}")
return False
if __name__ == "__main__":
success = test_kittentts()
exit(0 if success else 1) |