File size: 2,559 Bytes
69427f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Debug script to test audio transcription functionality
"""
import os
import sys
import logging

# Add the src directory to the Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))

from fitness_gradio.ui.handlers import UIHandlers

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def test_audio_message_processing():
    """Test the add_message_with_audio function"""
    
    # Mock message with audio file (you'd need to provide a real audio file path to test)
    test_audio_file = "test_audio.wav"  # Replace with actual audio file path
    
    # Test case 1: Audio only message
    mock_audio_message = {
        "files": [test_audio_file],
        "text": ""
    }
    
    # Test case 2: Text only message
    mock_text_message = {
        "files": [],
        "text": "Hello, this is a test message"
    }
    
    # Test case 3: Combined audio and text
    mock_combined_message = {
        "files": [test_audio_file],
        "text": "Additional text content"
    }
    
    initial_history = []
    
    print("Testing audio message processing...")
    
    # Test text message
    print("\n=== Testing text-only message ===")
    try:
        history, input_state = UIHandlers.add_message_with_audio(initial_history.copy(), mock_text_message)
        print(f"History after text message: {history}")
        print(f"Input state: {input_state}")
    except Exception as e:
        print(f"Error with text message: {e}")
    
    # Test audio message (only if audio file exists)
    if os.path.exists(test_audio_file):
        print("\n=== Testing audio-only message ===")
        try:
            history, input_state = UIHandlers.add_message_with_audio(initial_history.copy(), mock_audio_message)
            print(f"History after audio message: {history}")
            print(f"Input state: {input_state}")
        except Exception as e:
            print(f"Error with audio message: {e}")
    else:
        print(f"\n=== Skipping audio test (file {test_audio_file} not found) ===")
    
    # Test is_audio_file function
    print("\n=== Testing audio file detection ===")
    test_files = [
        "test.wav",
        "test.mp3", 
        "test.m4a",
        "test.txt",
        "test.jpg",
        "test.webm"
    ]
    
    for test_file in test_files:
        is_audio = UIHandlers.is_audio_file(test_file)
        print(f"{test_file}: {'Audio' if is_audio else 'Not audio'}")

if __name__ == "__main__":
    test_audio_message_processing()