Skip to content

Using a USB Microphone with ROS2

Effie Daum edited this page Feb 4, 2024 · 1 revision

Disclaimer: This tutorial was made using an Audio-Technica ATR4650-USB microphone. This may not work perfectly with other microphones.

Clone ROS Package

The required ROS package (audio-common) has been forked and slightly modified here:

cd $HOME/ros2_ws/src
git clone git@github.com:norlab-ulaval/audio_common.git

Make sure you use the ros2 branch with git status.

Install dependencies

Install required dependencies using:

sudo apt install -y pulseaudio alsa-base alsa-tools alsa-utils
sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-*

Tesing installation

Compile your workspace with the new package installed with:

cd $HOME/ros2_ws
colcon build --symlink-build
source install/local_setup.bash

Launch the audio_capture node using:

ros2 launch audio_capture capture.launch.py

In another terminal, run:

ros2 topic echo /audio/audio

You should see arrays of integers coming in with changing values. If there is no topic or the data is always the same, following the debugging steps below. Otherwise, you can validate the functionality of the recording by launching:

ros2 launch audio_capture capture_to_file.launch.py

Which will create a file called output.mp3 in /tmp. Download this file on your machine and listen to your "bee boop bee boop" sounds.

Debugging

If the driver is not working, first check if the microphone is detected by Ubuntu in Settings->Sound. You should see you microphone in the "Input" section, with the line moving when you make noise.

If the topic /audio/audio is sending the same message over and over, edit the file /etc/modprobe.d/alsa-base.conf so the end looks like this:

# Keep snd-usb-audio from being loaded as first soundcard
#options snd-usb-audio index=-2

options snd-hda-intel index=0
options snd-usb-audio index=1 vid=0x0909 pid=0x004f

Note1: Make sure to comment the first line which is already present in the file.

Note2: Replace the vid and pid with the values for your microphone (found using lsusb).

More ressources here: https://help.ubuntu.com/community/UbuntuStudio/UsbAudioDevices

Clone this wiki locally