Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """Test script to verify TTS provider migration.""" | |
| import sys | |
| import os | |
| # Add src to path | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) | |
| def test_provider_imports(): | |
| """Test that all providers can be imported.""" | |
| print("Testing provider imports...") | |
| try: | |
| from src.infrastructure.tts import TTSProviderFactory, DummyTTSProvider | |
| print("β Core TTS components imported successfully") | |
| except Exception as e: | |
| print(f"β Failed to import core TTS components: {e}") | |
| return False | |
| try: | |
| from src.domain.models.text_content import TextContent | |
| from src.domain.models.voice_settings import VoiceSettings | |
| from src.domain.models.speech_synthesis_request import SpeechSynthesisRequest | |
| print("β Domain models imported successfully") | |
| except Exception as e: | |
| print(f"β Failed to import domain models: {e}") | |
| return False | |
| return True | |
| def test_dummy_provider(): | |
| """Test the dummy provider functionality.""" | |
| print("\nTesting dummy provider...") | |
| try: | |
| from src.infrastructure.tts import DummyTTSProvider | |
| from src.domain.models.text_content import TextContent | |
| from src.domain.models.voice_settings import VoiceSettings | |
| from src.domain.models.speech_synthesis_request import SpeechSynthesisRequest | |
| # Create provider | |
| provider = DummyTTSProvider() | |
| print(f"β Created dummy provider: {provider.provider_name}") | |
| # Check availability | |
| if provider.is_available(): | |
| print("β Dummy provider is available") | |
| else: | |
| print("β Dummy provider is not available") | |
| return False | |
| # Check voices | |
| voices = provider.get_available_voices() | |
| print(f"β Available voices: {voices}") | |
| # Create a synthesis request | |
| text_content = TextContent(text="Hello, world!", language="en") | |
| voice_settings = VoiceSettings(voice_id="default", speed=1.0, language="en") | |
| request = SpeechSynthesisRequest( | |
| text_content=text_content, | |
| voice_settings=voice_settings | |
| ) | |
| print("β Created synthesis request") | |
| # Test synthesis | |
| audio_content = provider.synthesize(request) | |
| print(f"β Generated audio: {len(audio_content.data)} bytes, {audio_content.duration:.2f}s") | |
| return True | |
| except Exception as e: | |
| print(f"β Dummy provider test failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| def test_provider_factory(): | |
| """Test the provider factory.""" | |
| print("\nTesting provider factory...") | |
| try: | |
| from src.infrastructure.tts import TTSProviderFactory | |
| factory = TTSProviderFactory() | |
| print("β Created provider factory") | |
| available = factory.get_available_providers() | |
| print(f"β Available providers: {available}") | |
| if 'dummy' not in available: | |
| print("β Dummy provider should always be available") | |
| return False | |
| # Test creating dummy provider | |
| provider = factory.create_provider('dummy') | |
| print(f"β Created provider via factory: {provider.provider_name}") | |
| # Test fallback logic | |
| provider = factory.get_provider_with_fallback() | |
| print(f"β Got provider with fallback: {provider.provider_name}") | |
| return True | |
| except Exception as e: | |
| print(f"β Provider factory test failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| def main(): | |
| """Run all tests.""" | |
| print("=== TTS Provider Migration Test ===\n") | |
| tests = [ | |
| test_provider_imports, | |
| test_dummy_provider, | |
| test_provider_factory | |
| ] | |
| passed = 0 | |
| for test in tests: | |
| if test(): | |
| passed += 1 | |
| print() | |
| print(f"=== Results: {passed}/{len(tests)} tests passed ===") | |
| if passed == len(tests): | |
| print("π All tests passed! TTS provider migration successful.") | |
| return 0 | |
| else: | |
| print("β Some tests failed. Check the output above.") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) |