File size: 4,382 Bytes
1f9c751
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/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())