Note: This tutorial assumes that you have completed the previous tutorials: ROS tutorials.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

How to capture, stream, and play audio using audio_capture and audio_play.

Description: This tutorial covers the audio_capture and audio_play packages. The audio_capture package records audio from a microphone and publishes audio messages on the /audio topic. The audio_play package listens to /audio and outputs the audio messages to speakers.

Keywords: audio, sound, stream

Tutorial Level: BEGINNER

Next Tutorial: For remote robot teleoperators, learn how to remotely listen through robot ears

Installation

  • Install ROS: Installation Instructions

  • Instructions for Ubuntu
    • Install from debs; replace <distro> with the ROS distribution you're using (eg. fuerte)

    • sudo apt-get install ros-<distro>-audio-common
  • Instructions for other Linux distributions
    • Install git
    • sudo aptitude install git 
    • Download code
    • cd ~/catkin_ws/src
      git clone https://github.com/ros-drivers/audio_common.git
    • Install dependencies
    • rosdep install audio_common
    • Build audio_common along with your other ROS packages
    • cd ~/catkin_ws
      catkin_make
      source ~/catkin_ws/devel/setup.bash

Testing Your Setup

Test that gstreamer is working successfully with ALSA by capturing audio from your microphone and playing it back through your speakers.

Before executing the following command, make sure your microphone is enabled and selected as your default audio input device. You may want to turn down your volume as well.

gst-launch-0.10 alsasrc ! audioconvert ! audioresample ! alsasink 

If the above command doesn't work, try using the command "gst-launch-1.0" instead of the command "gst-launch-0.10".

The above command should play audio from the microphone through the speakers. If no audio is heard, make sure your system settings take audio input from your intended source as default. It may be helpful to debug whether audio from your source is being received using an external audio recording program such as audacity.

Once it is working, control-c the script to stop it.

Capturing sounds

Start capturing audio data using the following command

roslaunch audio_capture capture.launch

This will produce an /audio topic. Check for its existence using:

rostopic list

Check to see if it is streaming any data:

rostopic hz /audio

Do not kill this node, and continue to the next section.

Listening to captured sounds

Once the audio_capture node is running, we can use the audio_play node to listen to the output.

Open a new terminal, and source your ROS workspace variables.

source ~/catkin_ws/devel/setup.bash

Now launch the audio_play node.

roslaunch audio_play play.launch

This will start a new node that listens to the /audio topic, and plays the incoming messages.

Wiki: audio_common/Tutorials/Streaming audio (last edited 2021-08-26 17:22:25 by MikeRoss)