pymumble
pymumble copied to clipboard
sound_received_handler callback not triggered for Opus packets on Raspberry Pi (Python 3.11)
Environment:
pymumble version: (Please specify - e.g., 1.6.1, or the version after running pip install --upgrade pymumble) opuslib version: (Please specify - e.g., 3.0.1, or the version after pip install --upgrade opuslib) protobuf version: 3.12.2 (Installed as dependency) numpy version: (Please specify if known - installed for sounddevice initially) Python version: 3.11.2 Operating System: Raspberry Pi OS (Debian based) Kernel: Linux 6.6.51+rpt-rpi-2712 Hardware: Raspberry Pi (ARM architecture) Bug Description:
I am attempting to use pymumble on a Raspberry Pi to simply receive and process (initially just print a debug message) audio from a Mumble channel.
The script successfully connects to the Mumble server and joins the target channel (e.g., "Root"). When another user speaks in the channel, the pymumble debug logs (with debug=True) clearly show repeated messages like DEBUG-audio packet received from [session_id], sequence ..., type:4, target:0, length:... and DEBUG-Audio frame : time:..., last:..., size:100, type:4, target:0, pos:.... This confirms that Opus audio packets (type:4) are being received from the network by the library.
However, the callback function registered using mumble.callbacks.set_callback(pymumble.constants.PYMUMBLE_CLBK_SOUNDRECEIVED, sound_received_handler) is never executed. My debug print() statement inside this handler never appears in the output.
This issue persists even when all audio output code (using the sounddevice library in my original attempts) is completely commented out from the script, strongly suggesting the problem lies within pymumble's internal handling of received Opus packets (potentially decoding) or the subsequent callback dispatch mechanism on this specific platform setup.
Troubleshooting Steps Already Taken:
Confirmed successful Mumble server connection and channel join. Ensured the libopus0 system library is installed via sudo apt install libopus0. Tried reinstalling the opuslib Python package using pip. Tried upgrading pymumble and opuslib to the latest versions using pip install --upgrade. Resolved an initial TypeError: Cannot set MumbleProto.Authenticate.password to None by using MUMBLE_PASSWORD = "" for password-less connections. Used debug=True extensively to monitor internal library logs. Tested with audio output code (using sounddevice) completely commented out to isolate the issue. Minimal Code Example to Reproduce:
(Please replace placeholders for MUMBLE_HOST, MUMBLE_USER, MUMBLE_PASSWORD, MUMBLE_CHANNEL with valid details)
import pymumble_py3 as pymumble
# import sounddevice as sd # Commented out for testing
import numpy as np # Keep numpy import as it might be implicitly needed somewhere? Or remove if sure.
import time
import threading
# ------ Mumble Connection Settings (Replace placeholders!) ------
MUMBLE_HOST = "YOUR_MUMBLE_HOST"
MUMBLE_PORT = 64738
MUMBLE_USER = "RPi_Listener_Test"
MUMBLE_PASSWORD = "" # Use "" if no password
MUMBLE_CHANNEL = "Root" # Or your target channel, or None
# ------------------------------------------------------------
# Audio settings (not used currently)
SAMPLE_RATE = 48000
CHANNELS = 1
# Sound output stream - Disabled
# stream = sd.OutputStream(samplerate=SAMPLE_RATE, channels=CHANNELS, dtype='int16')
stream_started = False
stream_lock = threading.Lock()
def start_stream_if_needed():
# Disabled
pass
def stop_stream():
# Disabled
pass
# Callback function for received sound
def sound_received_handler(user, sound_chunk):
""" This should be called when sound is received """
# ---- THIS PRINT STATEMENT NEVER APPEARS ----
print(f"DEBUG: Sound received from {user['name']}, data length: {len(sound_chunk.pcm)} bytes.")
# --------------------------------------------
# ---- Audio playback code disabled ----
# ... (commented out sounddevice code) ...
# ------------------------------------
print(f"Connecting to {MUMBLE_HOST}:{MUMBLE_PORT}...")
# Enable debug mode
mumble = pymumble.Mumble(MUMBLE_HOST, MUMBLE_USER, port=MUMBLE_PORT, password=MUMBLE_PASSWORD, debug=True)
# Set the callback
mumble.callbacks.set_callback(pymumble.constants.PYMUMBLE_CLBK_SOUNDRECEIVED, sound_received_handler)
# Connect and start
mumble.start()
mumble.is_ready()
print("Connected to Mumble.")
# Join channel if specified
if MUMBLE_CHANNEL:
try:
target_channel = mumble.channels.find_by_name(MUMBLE_CHANNEL)
if target_channel:
print(f"Joining channel '{MUMBLE_CHANNEL}'...")
target_channel.move_in()
else:
if MUMBLE_CHANNEL not in [None, ""]:
print(f"Warning: Channel '{MUMBLE_CHANNEL}' not found. Staying in Root.")
except Exception as e:
print(f"Error joining channel: {e}")
# Keep the script running
try:
while mumble.is_alive():
time.sleep(1)
except KeyboardInterrupt:
print("\nCtrl+C detected, exiting...")
finally:
# stop_stream() # Commented out
print("Mumble connection closed.")
Relevant Log Output Snippet (When another user speaks):
2025-04-27 01:01:20,226-PyMumble-DEBUG-read control connection 2025-04-27 01:01:20,226-PyMumble-DEBUG-dispatch control message 2025-04-27 01:01:20,226-PyMumble-DEBUG-audio packet received from 23, sequence 52165, type:4, target:0, length:106 2025-04-27 01:01:20,226-PyMumble-DEBUG-Audio frame : time:1745704880.226577, last:True, size:100, type:4, target:0, pos:5 2025-04-27 01:01:20,249-PyMumble-DEBUG-read control connection
... (more similar messages) ...
NOTE: The print statement from sound_received_handler is missing here
Expected Behavior:
The sound_received_handler function should be called whenever audio packets are received from the Mumble server (as indicated by the audio packet received debug logs), and the print() statement inside it should appear in the console output.
Actual Behavior:
The pymumble debug logs show audio packets being received, but the sound_received_handler callback is never triggered.
Any help or insights into why the callback might not be firing on this Raspberry Pi (ARM / Python 3.11) setup would be greatly appreciated. Thank you!