Spaces:
Running
Running
Upload test_app.py
Browse files- test_app.py +65 -0
test_app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
Test script for KittenTTS functionality
|
4 |
+
"""
|
5 |
+
|
6 |
+
import soundfile as sf
|
7 |
+
import numpy as np
|
8 |
+
from kittentts import KittenTTS
|
9 |
+
|
10 |
+
def test_kittentts():
|
11 |
+
"""Test the KittenTTS model with a simple example"""
|
12 |
+
|
13 |
+
print("π Testing KittenTTS...")
|
14 |
+
|
15 |
+
try:
|
16 |
+
# Initialize the model
|
17 |
+
print("π¦ Loading KittenTTS model...")
|
18 |
+
model = KittenTTS("KittenML/kitten-tts-nano-0.1")
|
19 |
+
print("β
Model loaded successfully!")
|
20 |
+
|
21 |
+
# Test text
|
22 |
+
test_text = "Hello! This is a test of the KittenTTS model."
|
23 |
+
test_voice = 'expr-voice-2-f'
|
24 |
+
|
25 |
+
print(f"π€ Generating speech for: '{test_text}'")
|
26 |
+
print(f"π΅ Using voice: {test_voice}")
|
27 |
+
|
28 |
+
# Generate audio
|
29 |
+
audio = model.generate(test_text, voice=test_voice)
|
30 |
+
|
31 |
+
print(f"β
Audio generated successfully!")
|
32 |
+
print(f"π Audio shape: {audio.shape}")
|
33 |
+
print(f"π Audio dtype: {audio.dtype}")
|
34 |
+
print(f"π Audio range: {np.min(audio):.4f} to {np.max(audio):.4f}")
|
35 |
+
|
36 |
+
# Save test audio
|
37 |
+
output_file = 'test_output.wav'
|
38 |
+
sf.write(output_file, audio, 24000)
|
39 |
+
print(f"πΎ Audio saved to: {output_file}")
|
40 |
+
|
41 |
+
# Test all voices
|
42 |
+
print("\nπ Testing all available voices...")
|
43 |
+
available_voices = [
|
44 |
+
'expr-voice-2-m', 'expr-voice-2-f', 'expr-voice-3-m', 'expr-voice-3-f',
|
45 |
+
'expr-voice-4-m', 'expr-voice-4-f', 'expr-voice-5-m', 'expr-voice-5-f'
|
46 |
+
]
|
47 |
+
|
48 |
+
for i, voice in enumerate(available_voices, 1):
|
49 |
+
print(f" {i}/8: Testing {voice}...")
|
50 |
+
try:
|
51 |
+
test_audio = model.generate("Test voice.", voice=voice)
|
52 |
+
print(f" β
{voice} works!")
|
53 |
+
except Exception as e:
|
54 |
+
print(f" β {voice} failed: {e}")
|
55 |
+
|
56 |
+
print("\nπ All tests completed successfully!")
|
57 |
+
return True
|
58 |
+
|
59 |
+
except Exception as e:
|
60 |
+
print(f"β Test failed: {e}")
|
61 |
+
return False
|
62 |
+
|
63 |
+
if __name__ == "__main__":
|
64 |
+
success = test_kittentts()
|
65 |
+
exit(0 if success else 1)
|