-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_voices.py
More file actions
59 lines (49 loc) · 2.12 KB
/
Copy pathtest_voices.py
File metadata and controls
59 lines (49 loc) · 2.12 KB
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
import numpy as np
import soundfile as sf
from fastrtc import get_tts_model, KokoroTTSOptions
def test_voice(name, options, text="Hello, this is a test of the voice settings."):
"""Test a voice configuration and save the output."""
print(f"\nTesting voice: {name}")
print(f"Settings: speed={options.speed}, lang={options.lang}")
try:
# Get TTS model
tts_model = get_tts_model("kokoro")
# Generate speech
sample_rate, audio_data = tts_model.tts(text, options=options)
# Ensure audio is in float32 format
if audio_data.dtype != np.float32:
audio_data = audio_data.astype(np.float32)
# Normalize audio
max_val = np.max(np.abs(audio_data))
if max_val > 0:
audio_data = audio_data / max_val
# Save audio file
filename = f"test_voice_{name.lower()}.wav"
sf.write(filename, audio_data, sample_rate)
print(f"✓ Successfully saved to {filename}")
print(f"Audio stats - min: {np.min(audio_data):.3f}, max: {np.max(audio_data):.3f}, mean: {np.mean(audio_data):.3f}")
except Exception as e:
print(f"✗ Error testing voice {name}: {str(e)}")
def main():
# Test extreme speed variations
print("\nTesting speed variations...")
speeds = [
("very_slow", KokoroTTSOptions(speed=0.5, lang="en-us")),
("slow", KokoroTTSOptions(speed=0.75, lang="en-us")),
("normal", KokoroTTSOptions(speed=1.0, lang="en-us")),
("fast", KokoroTTSOptions(speed=1.5, lang="en-us")),
("very_fast", KokoroTTSOptions(speed=2.0, lang="en-us")),
]
for name, options in speeds:
test_voice(name, options)
# Test different languages/accents
print("\nTesting different languages...")
languages = [
("us_english", KokoroTTSOptions(speed=1.0, lang="en-us")),
("british", KokoroTTSOptions(speed=1.0, lang="en-gb")),
("australian", KokoroTTSOptions(speed=1.0, lang="en-au")),
]
for name, options in languages:
test_voice(name, options)
if __name__ == "__main__":
main()