Spaces:
Sleeping
Sleeping
| #!/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) |