| |
| """ |
| Quick test script to verify the TTS system works |
| """ |
| import sys |
| import os |
|
|
| |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
|
|
|
| def test_basic(): |
| """Basic functionality test""" |
| print("=" * 50) |
| print("🧪 Testing Voice Tech for All TTS System") |
| print("=" * 50) |
|
|
| |
| print("\n1. Testing imports...") |
| try: |
| from src.config import LANGUAGE_CONFIGS, get_available_voices |
| from src.tokenizer import TTSTokenizer, CharactersConfig, TextNormalizer |
| from src.downloader import ModelDownloader |
| from src.engine import TTSEngine |
|
|
| print(" ✅ All imports successful") |
| except ImportError as e: |
| print(f" ❌ Import error: {e}") |
| return False |
|
|
| |
| print("\n2. Testing configuration...") |
| voices = get_available_voices() |
| print(f" ✅ Found {len(voices)} voice configurations") |
| print(f" Languages: {set(v['code'] for v in voices.values())}") |
|
|
| |
| print("\n3. Testing tokenizer...") |
| config = CharactersConfig( |
| characters="abcdefghijklmnopqrstuvwxyz", punctuations="!.,? " |
| ) |
| tokenizer = TTSTokenizer(config) |
| ids = tokenizer.text_to_ids("hello world") |
| text_back = tokenizer.ids_to_text(ids) |
| print(f" ✅ Tokenizer works: 'hello world' -> {len(ids)} tokens") |
|
|
| |
| print("\n4. Testing text normalizer...") |
| normalizer = TextNormalizer() |
| test_text = "Price is {100}{एकसो} rupees" |
| normalized = normalizer.clean_text(test_text) |
| print(f" ✅ Normalized: '{test_text}' -> '{normalized}'") |
|
|
| |
| print("\n5. Testing model downloader...") |
| downloader = ModelDownloader() |
| downloaded = downloader.list_downloaded_models() |
| print(f" ✅ Downloaded models: {downloaded if downloaded else 'None yet'}") |
|
|
| |
| print("\n6. Testing TTS engine...") |
| try: |
| engine = TTSEngine() |
| print(f" ✅ Engine initialized on device: {engine.device}") |
| except Exception as e: |
| print(f" ⚠️ Engine init warning: {e}") |
|
|
| print("\n" + "=" * 50) |
| print("✅ All basic tests passed!") |
| print("=" * 50) |
|
|
| print("\n📋 Next steps:") |
| print(" 1. Download a model: python -m src.cli download --voice hi_male") |
| print( |
| " 2. Synthesize: python -m src.cli synthesize --text 'नमस्ते' --voice hi_male" |
| ) |
| print(" 3. Start server: python -m src.cli serve") |
|
|
| return True |
|
|
|
|
| def test_synthesis(): |
| """Test actual synthesis (requires downloaded model)""" |
| from src.engine import TTSEngine |
| from src.downloader import ModelDownloader |
|
|
| downloader = ModelDownloader() |
| downloaded = downloader.list_downloaded_models() |
|
|
| if not downloaded: |
| print("\n⚠️ No models downloaded yet.") |
| print("Run: python -m src.cli download --voice hi_male") |
| return |
|
|
| voice = downloaded[0] |
| print(f"\n🎤 Testing synthesis with voice: {voice}") |
|
|
| engine = TTSEngine() |
|
|
| |
| test_texts = { |
| "hi": "नमस्ते, मैं आपकी कैसे मदद कर सकता हूं?", |
| "en": "Hello, how can I help you today?", |
| "bn": "নমস্কার, আজ আমি আপনাকে কীভাবে সাহায্য করতে পারি?", |
| } |
|
|
| |
| from src.config import LANGUAGE_CONFIGS |
|
|
| lang = LANGUAGE_CONFIGS[voice].code |
|
|
| text = test_texts.get(lang, test_texts["en"]) |
|
|
| print(f" Text: {text}") |
| output = engine.synthesize(text, voice) |
| print(f" ✅ Generated {output.duration:.2f}s of audio") |
|
|
| |
| test_output = "test_output.wav" |
| engine.synthesize_to_file(text, test_output, voice) |
| print(f" ✅ Saved to: {test_output}") |
|
|
|
|
| if __name__ == "__main__": |
| if len(sys.argv) > 1 and sys.argv[1] == "--full": |
| test_basic() |
| test_synthesis() |
| else: |
| test_basic() |
|
|