#!/usr/bin/env python3 """ Test script to verify TTS service core functionality is preserved after logging fixes. This can be run in the Hugging Face environment to verify everything works. """ def test_tts_functionality(): """Test core TTS functionality without actually running synthesis""" print("๐Ÿงช Testing TTS Service Core Functionality") print("=" * 60) try: # Test imports and basic setup print("1๏ธโƒฃ Testing imports...") import torch import numpy as np print(" โœ… Core dependencies imported successfully") # Test device detection print("2๏ธโƒฃ Testing device detection...") device = torch.device("cuda" if torch.cuda.is_available() else "cpu") print(f" โœ… Device detected: {device}") # Test logging functions print("3๏ธโƒฃ Testing logging functions...") from app import safe_log, logging_ok print(f" โœ… Logging status: {'OK' if logging_ok else 'FALLBACK'}") safe_log("info", "Test message from functionality test") print(" โœ… Safe logging works") # Test MCP availability print("4๏ธโƒฃ Testing MCP integration...") from app import MCP_AVAILABLE print(f" โœ… MCP Available: {'Yes' if MCP_AVAILABLE else 'No'}") # Test voice presets print("5๏ธโƒฃ Testing voice presets...") from app import VOICE_PRESETS print(f" โœ… Voice presets loaded: {len(VOICE_PRESETS)} options") for i, (code, desc) in enumerate(VOICE_PRESETS[:3]): # Show first 3 print(f" {i+1}. {code}: {desc}") if len(VOICE_PRESETS) > 3: print(f" ... and {len(VOICE_PRESETS)-3} more") print("\n๐ŸŽ‰ All functionality tests passed!") return True except Exception as e: print(f"\nโŒ Functionality test failed: {e}") import traceback traceback.print_exc() return False def test_synthesis_stub(): """Test synthesis function structure without actual model loading""" print("\n๐ŸŽค Testing Synthesis Function Structure") print("=" * 60) try: from app import synthesize_speech print("โœ… synthesize_speech function imported successfully") # Test with empty input (should return error gracefully) result = synthesize_speech("", "v2/en_speaker_6") if result[0] is None and "Please enter some text" in result[1]: print("โœ… Empty input handling works correctly") else: print("โš ๏ธ Empty input handling might need review") print("โœ… Synthesis function structure is correct") return True except Exception as e: print(f"โŒ Synthesis function test failed: {e}") return False def test_gradio_interface(): """Test that Gradio interface can be created""" print("\n๐Ÿ–ฅ๏ธ Testing Gradio Interface Creation") print("=" * 60) try: # This would normally create the interface # We'll just verify the imports work import gradio as gr print("โœ… Gradio imported successfully") # Test that our app structure is compatible from app import VOICE_PRESETS, get_system_info info = get_system_info() print("โœ… System info function works") print(f" System info preview: {info[:100]}...") print("โœ… Gradio interface structure is compatible") return True except ImportError: print("โš ๏ธ Gradio not available (expected in local environment)") return True # This is expected locally except Exception as e: print(f"โŒ Gradio interface test failed: {e}") return False if __name__ == "__main__": print("๐Ÿ”ง TTS Service Functionality Verification") print("๐ŸŽฏ Testing that logging fixes preserve core functionality") print("=" * 80) success = True # Run all tests if not test_tts_functionality(): success = False if not test_synthesis_stub(): success = False if not test_gradio_interface(): success = False print("\n" + "=" * 80) if success: print("๐ŸŽ‰ ALL FUNCTIONALITY TESTS PASSED!") print("โœ… TTS service core functionality is preserved") print("โœ… Logging fixes don't break existing features") print("โœ… Ready for deployment with improved logging") else: print("โŒ SOME FUNCTIONALITY TESTS FAILED!") print("โŒ Review the errors above before deployment") print(f"\n๐Ÿ“‹ Test Summary:") print(f" โ€ข Core imports and device detection: {'โœ…' if success else 'โŒ'}") print(f" โ€ข Logging system integration: {'โœ…' if success else 'โŒ'}") print(f" โ€ข MCP compatibility: {'โœ…' if success else 'โŒ'}") print(f" โ€ข Voice presets and synthesis: {'โœ…' if success else 'โŒ'}") print(f" โ€ข Interface compatibility: {'โœ…' if success else 'โŒ'}")