attempt to fix mic audio streaming
This commit is contained in:
+17
-6
@@ -178,7 +178,7 @@ class SoundReceiver:
|
||||
# MAIN TELEOP CLASS
|
||||
# ==========================================
|
||||
class NaoTeleop:
|
||||
def __init__(self, session, audio_device_index=None):
|
||||
def __init__(self, session, audio_device_index=None, mic_channel=1):
|
||||
self.session = session
|
||||
self.motion = session.service("ALMotion")
|
||||
self.posture = session.service("ALRobotPosture")
|
||||
@@ -196,6 +196,7 @@ class NaoTeleop:
|
||||
self.audio_device = None
|
||||
self.audio_service_name = "SoundReceiver"
|
||||
self.audio_device_index = audio_device_index # which laptop output device to play the mic feed on
|
||||
self.mic_channel = mic_channel # which NAO mic to stream: LEFTCHANNEL(1)/RIGHTCHANNEL(2)/FRONTCHANNEL(3)/REARCHANNEL(4)
|
||||
|
||||
self.running = True
|
||||
self.head_yaw = 0.0
|
||||
@@ -261,10 +262,13 @@ class NaoTeleop:
|
||||
# 2. Add a tiny delay to let the network handshake complete
|
||||
time.sleep(0.5)
|
||||
|
||||
# 3. Use the IP of the machine running the code
|
||||
# We explicitly tell the robot the IP of your laptop (replace with your laptop IP if still failing)
|
||||
# '0' tells it to auto-discover, but sometimes we need to be explicit.
|
||||
self.audio_device.setClientPreferences(self.audio_service_name, 16000, 3, 0)
|
||||
# 3. Which physical mic to stream. FRONTCHANNEL(3) was the
|
||||
# original default, but on this robot the front and rear mics
|
||||
# test dead (flat energy readings even up close) while left
|
||||
# and right respond normally - see nao_audio_diagnostic.py.
|
||||
# Defaulting to LEFTCHANNEL(1) accordingly; override with
|
||||
# --mic-channel if you want to compare.
|
||||
self.audio_device.setClientPreferences(self.audio_service_name, 16000, self.mic_channel, 0)
|
||||
self.audio_device.subscribe(self.audio_service_name)
|
||||
|
||||
print("✅ Live Audio Stream ready")
|
||||
@@ -479,6 +483,8 @@ class NaoTeleop:
|
||||
pygame.quit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
MIC_CHANNELS = {"left": 1, "right": 2, "front": 3, "rear": 4}
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--ip", type=str, default="127.0.0.1")
|
||||
parser.add_argument("--port", type=int, default=9559)
|
||||
@@ -486,6 +492,10 @@ if __name__ == "__main__":
|
||||
help="Force a specific PyAudio output device index for the robot's "
|
||||
"mic feed (see the '🔈 Available output devices' list printed "
|
||||
"at startup) if the system default isn't your speakers.")
|
||||
parser.add_argument("--mic-channel", choices=MIC_CHANNELS.keys(), default="left",
|
||||
help="Which NAO mic to stream. Defaults to 'left' since "
|
||||
"nao_audio_diagnostic.py confirmed front/rear are dead on "
|
||||
"this unit while left/right respond normally.")
|
||||
args = parser.parse_args()
|
||||
|
||||
session = qi.Session()
|
||||
@@ -496,4 +506,5 @@ if __name__ == "__main__":
|
||||
print(f"❌ Connection failed: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
NaoTeleop(session, audio_device_index=args.audio_device_index).run()
|
||||
NaoTeleop(session, audio_device_index=args.audio_device_index,
|
||||
mic_channel=MIC_CHANNELS[args.mic_channel]).run()
|
||||
|
||||
Reference in New Issue
Block a user