attempt to fix mic audio streaming

This commit is contained in:
Lucca Pirovano
2026-07-15 15:04:55 -04:00
parent 7fa946f185
commit e9719ff61e
3 changed files with 118 additions and 6 deletions
+101
View File
@@ -0,0 +1,101 @@
#!/usr/bin/env python
# -*- encoding: UTF-8 -*-
"""
Standalone NAO audio diagnostic - deliberately bypasses naowalk.py entirely.
Run this FIRST when troubleshooting "I can't hear the robot's mic". It tests
each link in the chain independently, so a failure tells you exactly where
the problem is instead of "somewhere in 300 lines of PyAudio/threading code":
TEST 1 - Front mic hardware energy.
Uses ALAudioDevice's built-in energy meter. No PyAudio, no
network audio streaming, no laptop audio stack involved at all.
This is the lowest-level check of "does the mic itself work".
TEST 2 - Local on-robot recording.
Records straight to a .wav file on the robot's own disk, then
you pull it off and play it normally. This bypasses the live
network stream, the SoundReceiver/queue/threading code, and
your laptop's PyAudio output path - all at once.
TEST 3 - Robot's own speaker.
Plays a tone through the ROBOT's speaker (not your laptop), to
confirm robot-side audio output is fine, independent of any of
the mic-listening code.
If TEST 1 shows no energy change when you make noise: mic hardware/mute/
environment issue, upstream of any code in this project.
If TEST 1 works but TEST 2's file is silent: something is wrong with the
recording/robot-audio-stack itself, still nothing to do with naowalk.py.
If TEST 2's file has clear audio: the mic and robot are fine, and the bug
is specifically in naowalk.py's live-streaming path (network delivery,
PyAudio device selection, etc.) - go back to the diagnostics already
built into naowalk.py (device list / test beep / peak level) to isolate it
further.
Usage:
python3 nao_audio_diagnostic.py --ip spike.local --port 9559
"""
import qi
import argparse
import time
parser = argparse.ArgumentParser()
parser.add_argument("--ip", type=str, default="127.0.0.1")
parser.add_argument("--port", type=int, default=9559)
args = parser.parse_args()
session = qi.Session()
session.connect(f"tcp://{args.ip}:{args.port}")
print(f"✅ Connected to {args.ip}")
audio = session.service("ALAudioDevice")
# --- TEST 1: mic hardware energy, all four channels ------------------------
print("\n=== TEST 1: Mic hardware energy (all 4 mics) ===")
print("Make noise near the robot's head (clap, talk right up close to it) for 10s...")
audio.enableEnergyComputation()
front_readings, rear_readings, left_readings, right_readings = [], [], [], []
for i in range(10):
f, r, l, rt = (audio.getFrontMicEnergy(), audio.getRearMicEnergy(),
audio.getLeftMicEnergy(), audio.getRightMicEnergy())
front_readings.append(f); rear_readings.append(r); left_readings.append(l); right_readings.append(rt)
print(f" t={i}s front={f:.2f} rear={r:.2f} left={l:.2f} right={rt:.2f}")
time.sleep(1)
audio.disableEnergyComputation()
results = {"front": front_readings, "rear": rear_readings, "left": left_readings, "right": right_readings}
flat = [name for name, vals in results.items() if max(vals) - min(vals) < 2]
if len(flat) == 4:
print("⚠️ ALL FOUR mics are flat. This points to something systemic - e.g. audio "
"inputs closed (closeAudioInputs() called somewhere and never reopened), "
"or a low-level hardware/driver fault - rather than one damaged mic.")
elif flat:
print(f"⚠️ Flat mic(s): {', '.join(flat)}. The others responded normally, which "
f"points to a fault specific to {', '.join(flat)} rather than the audio "
f"pipeline as a whole (that pipeline is clearly working for the others).")
else:
print("✅ All four mics responded to noise - hardware capture is fine across the board.")
# --- TEST 2: local on-robot recording ---------------------------------------
print("\n=== TEST 2: Local on-robot recording ===")
remote_path = "/home/nao/mic_test.wav"
print(f"Recording 5s directly to {remote_path} on the robot itself "
f"(this bypasses the network stream and your laptop's audio stack entirely)...")
audio.startMicrophonesRecording(remote_path)
time.sleep(5)
audio.stopMicrophonesRecording()
print(f"Done. Pull it off and play it with:")
print(f" scp nao@{args.ip}:{remote_path} .")
print(f" (then open mic_test.wav in any media player - it's 4-channel, so check all channels)")
print("If that file has clearly audible sound, the mic and robot are fine and the")
print("bug is specifically in naowalk.py's live-streaming path.")
# --- TEST 3: robot's own speaker, via TTS (version-agnostic) ---------------
print("\n=== TEST 3: Robot's own speaker ===")
input("Press Enter to have the robot say a test phrase out loud...")
session.service("ALTextToSpeech").say("Testing 1 2 3, can you hear me.")
print("If you heard the robot speak just now, its speaker output is fine "
"(this is unrelated to hearing its mic on your laptop, but rules out a robot-wide audio fault).")
print("\nDone. Report back which test(s) failed and we'll know exactly where to look.")