Spaces:
Running
Running
File size: 2,185 Bytes
c8edd3d | 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 |
import sys
import os
import time
import numpy as np
# Ensure we can import the module
sys.path.append(os.getcwd())
from reachy_mini_danceml.audio_capture import LocalAudioCapture
def verify_fix():
print("Testing Audio Capture with 'Reachy Mini Audio'...")
# Initialize with the specific device name
capture = LocalAudioCapture(device_name="Reachy Mini Audio")
# Check if the device index resulted in a valid index (not None)
# The class prints "Selected audio device..." or "Warning..."
# We can inspect the internal property
if capture._device_index is None:
print("❌ Verification Failed: Device 'Reachy Mini Audio' not found.")
return
print(f"✅ Device found! Index: {capture._device_index}")
capture.start()
time.sleep(1) # Let it warm up
print("Capturing 2 seconds of audio...")
chunks = []
start_time = time.time()
while time.time() - start_time < 2:
chunk = capture.get_chunk()
if chunk:
chunks.append(chunk)
capture.stop()
total_chunks = len(chunks)
print(f"Total chunks captured: {total_chunks}")
if total_chunks == 0:
print("❌ Verification Failed: No audio chunks captured.")
return
# Concatenate all chunks
all_audio = b"".join(chunks)
audio_array = np.frombuffer(all_audio, dtype=np.int16)
max_amp = np.max(np.abs(audio_array))
print(f"Max Amplitude: {max_amp}")
if max_amp < 100:
print("⚠️ Warning: Amplitude is very low (Silence?). Check mic mute.")
else:
print("✅ Signal Detected! Amplitude looks good.")
# Check sample rate consistency
# 2 seconds * 24000 samples/sec = 48000 samples
expected_samples = 48000
actual_samples = len(audio_array)
print(f"Samples Captured: {actual_samples} (Expected ~{expected_samples})")
if abs(actual_samples - expected_samples) > 10000:
print("⚠️ Warning: Sample count deviation is high. Check specific timing/buffer issues.")
else:
print("✅ Sample rate looks consistent.")
if __name__ == "__main__":
verify_fix()
|