-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquick_test_chatterbox.py
More file actions
75 lines (59 loc) · 2.06 KB
/
quick_test_chatterbox.py
File metadata and controls
75 lines (59 loc) · 2.06 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""Quick test script to generate audio with Chatterbox Turbo"""
import os
import sys
from datetime import datetime
# Test if chatterbox is available
try:
from chatterbox_engine import ChatterboxTurboEngine, is_chatterbox_available
import soundfile as sf
except ImportError as e:
print(f"Error: Missing dependencies - {e}")
print("Install with: pip install chatterbox-tts soundfile")
sys.exit(1)
def main():
# Check if Chatterbox is available
if not is_chatterbox_available():
print("Error: chatterbox-tts not installed")
print("Install with: ./venv/bin/pip install chatterbox-tts")
return 1
# Sample text
text = "Hello! This is a test of the Chatterbox Turbo text-to-speech engine. It uses voice cloning to match a reference speaker."
# Use default male voice sample
reference_audio = "voice_samples/en_us_male_warm.wav"
if not os.path.exists(reference_audio):
print(f"Error: Reference audio not found: {reference_audio}")
print("Run: ./venv/bin/python generate_voice_samples.py")
return 1
print("=" * 60)
print("Chatterbox Turbo Quick Test")
print("=" * 60)
print(f"\nText: {text}")
print(f"Reference: {reference_audio}")
print()
# Initialize engine
print("Loading Chatterbox Turbo engine...")
engine = ChatterboxTurboEngine(device="cuda")
engine.load()
# Generate audio
print("Generating audio...")
audio = engine.generate_audio(text, reference_audio)
# Save output
os.makedirs("output", exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output_path = f"output/chatterbox_test_{timestamp}.wav"
sf.write(output_path, audio, engine.sr)
# Stats
duration = len(audio) / engine.sr
print("\n" + "=" * 60)
print("Success!")
print("=" * 60)
print(f"Output: {output_path}")
print(f"Duration: {duration:.1f} seconds")
print(f"Sample rate: {engine.sr} Hz")
print()
# Cleanup
engine.cleanup()
return 0
if __name__ == "__main__":
sys.exit(main())