Note: This tutorial assumes that you have completed the previous tutorials: ROS tutorials.

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

Instructions for Ubuntu 10.04

  • Install ROS: Installation Instructions

  • Install mercurial
  • sudo aptitude install mercurial 
  • Download code
  • hg clone https://kforge.ros.org/audiocommon/audio_common audio_common
  • Add to ROS_PACKAGE_PATH
  • cd audio_common
    export ROS_PACKAGE_PATH=${PWD}:$ROS_PACKAGE_PATH
  • Install dependencies
  • rosdep install audio_common
  • Build the audio_common stack
  • rosmake

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 

The above command should play audio from the microphone through the speakers. If no audio is heard, make sure your system is setup to capture audio from the proper source. It may be helpful to debug this 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 change directory to the audio_common sources.

cd audio_common
export ROS_PACKAGE_PATH=${PWD}:$ROS_PACKAGE_PATH

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 2012-04-25 00:07:32 by LeilaTakayama)