Spaces:
Build error
Build error
File size: 3,943 Bytes
1be582a |
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 |
#!/usr/bin/env python3
"""Test script for STT migration."""
import sys
import logging
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_provider_availability():
"""Test that providers can be imported and checked for availability."""
try:
from infrastructure.stt import STTProviderFactory, WhisperSTTProvider, ParakeetSTTProvider
print("β Successfully imported STT providers")
# Test factory
available_providers = STTProviderFactory.get_available_providers()
print(f"Available providers: {available_providers}")
# Test individual providers
whisper = WhisperSTTProvider()
print(f"Whisper available: {whisper.is_available()}")
print(f"Whisper models: {whisper.get_available_models()}")
print(f"Whisper default model: {whisper.get_default_model()}")
parakeet = ParakeetSTTProvider()
print(f"Parakeet available: {parakeet.is_available()}")
print(f"Parakeet models: {parakeet.get_available_models()}")
print(f"Parakeet default model: {parakeet.get_default_model()}")
return True
except Exception as e:
print(f"β Error testing providers: {e}")
import traceback
traceback.print_exc()
return False
def test_legacy_compatibility():
"""Test legacy compatibility functions."""
try:
from infrastructure.stt import transcribe_audio, ASRFactory
print("β Successfully imported legacy compatibility functions")
# Test ASRFactory
try:
model = ASRFactory.get_model("whisper")
print(f"β ASRFactory created model: {model.provider_name}")
except Exception as e:
print(f"ASRFactory test failed (expected if dependencies missing): {e}")
return True
except Exception as e:
print(f"β Error testing legacy compatibility: {e}")
import traceback
traceback.print_exc()
return False
def test_domain_integration():
"""Test integration with domain models."""
try:
from domain.models.audio_content import AudioContent
from domain.models.text_content import TextContent
from domain.exceptions import SpeechRecognitionException
print("β Successfully imported domain models")
# Create test audio content
test_audio = AudioContent(
data=b"fake audio data for testing",
format="wav",
sample_rate=16000,
duration=1.0,
filename="test.wav"
)
print(f"β Created test AudioContent: {test_audio.filename}")
return True
except Exception as e:
print(f"β Error testing domain integration: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
print("Testing STT migration...")
print("=" * 50)
tests = [
("Provider Availability", test_provider_availability),
("Legacy Compatibility", test_legacy_compatibility),
("Domain Integration", test_domain_integration)
]
results = []
for test_name, test_func in tests:
print(f"\n{test_name}:")
print("-" * 30)
result = test_func()
results.append((test_name, result))
print("\n" + "=" * 50)
print("Test Results:")
for test_name, result in results:
status = "β PASS" if result else "β FAIL"
print(f"{test_name}: {status}")
all_passed = all(result for _, result in results)
print(f"\nOverall: {'β ALL TESTS PASSED' if all_passed else 'β SOME TESTS FAILED'}")
sys.exit(0 if all_passed else 1) |