-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_audio.py
More file actions
130 lines (104 loc) · 3.93 KB
/
Copy pathtest_audio.py
File metadata and controls
130 lines (104 loc) · 3.93 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
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
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
"""
Simple test script for audio recording and transcription
"""
import numpy as np
import time
from audio_record import record_vbcable_audio, test_audio_devices
from audio_transcribe import transcribe_audio_numpy, append_transcript
def test_audio_recording():
"""Test audio recording functionality"""
print("=== AUDIO RECORDING TEST ===")
try:
print("Recording 5 seconds of audio...")
audio = record_vbcable_audio(duration=5)
if audio is not None:
print(f"✅ Audio recorded successfully!")
print(f" Shape: {audio.shape}")
print(f" Type: {audio.dtype}")
# Check audio levels
rms = np.sqrt(np.mean(audio**2))
peak = np.max(np.abs(audio))
print(f" RMS level: {rms:.6f}")
print(f" Peak level: {peak:.6f}")
if rms > 0.001:
print(" ✅ Audio has good levels")
return audio
else:
print(" ❌ Audio is too quiet")
return None
else:
print("❌ Audio recording failed")
return None
except Exception as e:
print(f"❌ Error during audio recording: {e}")
return None
def test_transcription(audio):
"""Test transcription functionality"""
print("\n=== TRANSCRIPTION TEST ===")
if audio is None:
print("❌ No audio to transcribe")
return False
try:
print("Transcribing audio...")
text = transcribe_audio_numpy(audio)
print(f"✅ Transcription successful!")
print(f" Text: '{text}'")
if isinstance(text, str) and text.strip():
print(" ✅ Transcription contains text")
return True
else:
print(" ❌ Transcription is empty")
return False
except Exception as e:
print(f"❌ Transcription failed: {e}")
return False
def test_transcript_file():
"""Test transcript file operations"""
print("\n=== TRANSCRIPT FILE TEST ===")
try:
# Test appending to transcript
test_text = f"Test transcription at {time.strftime('%H:%M:%S')}"
append_transcript(test_text)
print(f"✅ Appended to transcript: '{test_text}'")
# Read and display transcript
import os
transcript_path = "transcript.txt"
if os.path.exists(transcript_path):
with open(transcript_path, 'r', encoding='utf-8') as f:
content = f.read()
print(f"✅ Transcript file content:")
print(f" {content}")
else:
print("❌ Transcript file not found")
except Exception as e:
print(f"❌ Transcript file test failed: {e}")
def main():
print("🔊 AUDIO RECORDING & TRANSCRIPTION TEST")
print("=" * 50)
# Test audio devices
print("Testing all audio devices...")
test_audio_devices()
# Test audio recording
audio = test_audio_recording()
# Test transcription if audio was recorded
if audio is not None:
transcription_ok = test_transcription(audio)
if transcription_ok:
# Test transcript file operations
test_transcript_file()
print("\n" + "=" * 50)
print("📋 TEST SUMMARY")
print("=" * 50)
if audio is not None:
print("✅ Audio recording: WORKING")
else:
print("❌ Audio recording: FAILED")
print(" Please check your audio device configuration")
print("\n💡 NEXT STEPS:")
print("1. If audio recording failed, check VB-Cable installation")
print("2. Set 'CABLE Input' as your default audio output")
print("3. Enable 'Stereo Mix' in Windows sound settings")
print("4. Run this test again after playing some audio")
if __name__ == "__main__":
main()