forked from rahat15/AI-Interview-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_audio_processing.py
More file actions
69 lines (54 loc) · 2.4 KB
/
test_audio_processing.py
File metadata and controls
69 lines (54 loc) · 2.4 KB
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
#!/usr/bin/env python3
"""
Test script for audio processing functionality
Tests speech-to-text conversion and voice analysis
"""
import asyncio
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from interview.speech_to_text import speech_converter
from interview.voice_analyzer import VoiceAnalyzer
def test_audio_processing():
"""Test audio processing with sample data"""
print("🎤 Testing Audio Processing Functionality")
print("=" * 50)
# Initialize components
voice_analyzer = VoiceAnalyzer()
# Test with empty audio (fallback behavior)
print("\n1. Testing fallback behavior (no audio):")
try:
# Test speech-to-text fallback
transcribed_text = speech_converter.convert_audio_to_text(b"")
print(f" Speech-to-Text: {transcribed_text}")
# Test voice analysis fallback
voice_analysis = voice_analyzer.analyze_voice(audio_data=b"")
print(f" Voice Analysis: {voice_analysis}")
print(" ✅ Fallback behavior working correctly")
except Exception as e:
print(f" ❌ Error in fallback: {e}")
# Test with sample audio bytes (simulated)
print("\n2. Testing with sample audio data:")
try:
# Create some dummy audio data
sample_audio = b"dummy_audio_data_for_testing" * 100
# Test speech-to-text
transcribed_text = speech_converter.convert_audio_to_text(sample_audio)
print(f" Speech-to-Text: {transcribed_text}")
# Test voice analysis
voice_analysis = voice_analyzer.analyze_voice(audio_data=sample_audio)
print(f" Voice Scores: {voice_analysis.get('voice_scores', {})}")
print(f" Voice Metrics: {voice_analysis.get('voice_metrics', {})}")
print(" ✅ Audio processing pipeline working")
except Exception as e:
print(f" ❌ Error in audio processing: {e}")
print("\n" + "=" * 50)
print("🎯 Audio Processing Test Complete")
print("\nFeatures implemented:")
print("✅ Speech-to-Text conversion")
print("✅ Voice analysis (confidence, tone, fluency, clarity, pace)")
print("✅ Fallback handling for missing/invalid audio")
print("✅ API endpoints for audio upload")
print("✅ Integration with session management")
if __name__ == "__main__":
test_audio_processing()