ROS 2 package for detecting doorbell-like sounds using YAMNet.
This node was added for the RoboCup HRI task, where the robot waits for a doorbell-like sound before continuing the interaction. It can detect sounds such as bell, chime, ding-dong, buzzer, knock, and ding.
The node supports two audio sources:
alsa -> read directly from a local microphone using sounddevice
ros -> subscribe to a ROS audio topic
For our current RoboCup setup, the tested and recommended mode is:
--source alsa --device pulse
This uses the microphone selected in the laptop’s PulseAudio settings.
The node listens for doorbell-like sounds and publishes a ROS event when the aggregated YAMNet confidence passes the configured threshold.
/doorbell/listen
Type:
std_msgs/msg/Bool
Usage:
True -> start listening / open microphone
False -> stop listening / release microphone
Example:
ros2 topic pub --once /doorbell/listen std_msgs/msg/Bool "{data: true}"/doorbell/event
Type:
std_msgs/msg/Bool
Usage:
True -> doorbell-like sound detected
Monitor detections:
ros2 topic echo /doorbell/eventCreate and activate a virtual environment:
python3 -m venv --system-site-packages ~/venvs/doorbell_detector
source ~/venvs/doorbell_detector/bin/activateInstall dependencies:
pip install -r requirements.txtIf sounddevice fails:
sudo apt install portaudio19-dev
pip install -r requirements.txtUseful audio tools:
sudo apt install alsa-utils pulseaudio-utils pavucontrolBuild:
cd ~/ros2_ws
colcon build --packages-select doorbell_detector
source install/setup.bashWhen running the node, remember to activate the venv first:
source ~/venvs/doorbell_detector/bin/activate
source ~/ros2_ws/install/setup.bashFirst list the available audio devices:
ros2 run doorbell_detector doorbell_node --source alsa --list-devicesExample:
0 HD-Audio Generic: HDMI 0 (hw:0,3), ALSA (0 in, 8 out)
1 hdmi, ALSA (0 in, 8 out)
2 pulse, ALSA (32 in, 32 out)
* 3 default, ALSA (32 in, 32 out)
Use a device with input channels. Avoid devices with 0 in.
For our setup, use:
pulse
Before testing the detector, verify that the microphone records sound:
arecord -D pulse -f S16_LE -c 1 -r 16000 -d 5 -vv /tmp/mic_test.wav
aplay /tmp/mic_test.wavIf the recording is silent, open:
pavucontrolThen go to Input Devices, select the correct microphone, and check that the input level moves when speaking.
Use this to quickly verify that the detector works:
ros2 run doorbell_detector doorbell_node \
--source alsa \
--device pulse \
--top-k 10 \
--threshold 0.2 \
--consecutive 1 \
--inference-hz 0.25 \
--window-sec 1.5In another terminal:
ros2 topic echo /doorbell/eventPlay a doorbell sound close to the microphone.
A successful detection should print something like:
DOORBELL DETECTED
and /doorbell/event should publish:
data: trueAfter the basic test works, use a slightly safer configuration:
ros2 run doorbell_detector doorbell_node \
--source alsa \
--device pulse \
--top-k 5 \
--threshold 0.2 \
--consecutive 2 \
--inference-hz 0.5 \
--window-sec 1.5This requires two positive inference windows before publishing the event, reducing false positives.
Audio source.
Options:
ros
alsa
Recommended:
--source alsaROS audio topic used only with:
--source rosDefault:
/audio/in
Example:
--source ros --audio /audio/inFor the current RoboCup setup, this mode was not the main tested path.
Audio input device used with:
--source alsaExamples:
--device pulse
--device default
--device 2Recommended:
--device pulseLists available audio devices and exits:
ros2 run doorbell_detector doorbell_node --source alsa --list-devicesDetection output topic.
Default:
/doorbell/event
Command topic used to enable or disable listening.
Default:
/doorbell/listen
Doorbell confidence threshold.
Lower values are more sensitive but may create false positives. Higher values are safer but may miss quiet doorbells.
Tested value:
--threshold 0.2Number of positive inference windows required before detection.
For testing:
--consecutive 1For competition:
--consecutive 2Maximum YAMNet inference rate.
Lower values use less CPU but react slower.
Tested values:
--inference-hz 0.25
--inference-hz 0.5Seconds of audio used per inference.
Tested value:
--window-sec 1.5Number of top YAMNet classes printed in the logs.
Useful for debugging:
--top-k 10For normal use:
--top-k 5Software gain applied before inference.
Default:
--gain 1.0Use this only if the microphone is too quiet.
Minimum time between detections.
Default:
--cooldown-sec 5.0By default, the node releases the microphone after detection.
This is useful for HRI because the speech pipeline may need the microphone after the doorbell event.
Recommended:
--release-on-fireThe HRI state machine should:
- Publish
Trueto/doorbell/listen. - Wait for
Trueon/doorbell/event. - Continue the task.
- Let the detector release the microphone after detection.
- Start or resume speech recognition if needed.
Expected flow:
WAIT_FOR_DOORBELL
-> publish /doorbell/listen=True
-> wait for /doorbell/event=True
DOORBELL_DETECTED
-> detector publishes /doorbell/event=True
-> detector releases microphone
CONTINUE_HRI_TASK
To listen again later:
ros2 topic pub --once /doorbell/listen std_msgs/msg/Bool "{data: true}"First check the microphone:
arecord -D pulse -f S16_LE -c 1 -r 16000 -d 5 -vv /tmp/mic_test.wav
aplay /tmp/mic_test.wavIf the recording is silent, fix the input device in:
pavucontrolThe node is running, but YAMNet is not hearing doorbell-like audio.
Check that:
- the microphone records sound;
- the selected input in
pavucontrolis correct; - the doorbell sound is loud enough;
- the node is using
--device pulse.
Another process is using the microphone.
Check:
sudo fuser -v /dev/snd/*If PulseAudio is using the device, prefer:
--device pulseinstead of opening raw hardware devices.
The selected device is not available.
Re-list devices:
ros2 run doorbell_detector doorbell_node --source alsa --list-devicesThen use pulse, default, or another valid input device.
Warnings about missing GPU/CUDA libraries are usually not fatal. TensorFlow falls back to CPU, which is acceptable for this detector.
The node loads YAMNet from TensorFlow Hub. Run the node once before the competition to make sure the model is cached on the laptop.