[Documentation] [TitleIndex] [WordIndex

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 Configure and Use Speakers with sound_play

Description: This tutorial is an introduction to setting up and using USB speakers connected to a desktop computer. After reading it, you should be able to bring up the speakers, configure the speakers, and play sounds.

Keywords: sound, speakers, driver

Tutorial Level: BEGINNER

Next Tutorial: How to Create a Sound Interface sound_play/Tutorials/How to Create a Sound Interface


$ rosdep install sound_play
$ rosmake sound_play

Powered On and Plugged In

Make sure that your USB speakers are connected to your desktop and powered on.

You can check that the speaker/sound card is recognized by the unix kernel by using:

$ cat /proc/asound/cards

You will see something similar to:

Configuring the Sound Driver to Use Your Speaker

To designate which sound card the driver uses, run:

$ asoundconf set-default-card [device #]

(i.e. In the above example, asoundconf set-default-card 0 would configure the driver to use the Intel card .)

This will create .asoundrc.asoundconf in your home directory. To make the driver use these settings, add the following line to ~/.asoundrc by using the command:

$ echo 'include ".asoundrc.asoundconf"' >> ~/.asoundrc

(Optional) To set this default to all users, copy this to the system-wide driver configuration file:

$ sudo cp ~/.asoundrc.asoundconf /etc/asound.conf

Starting a roscore

For sound_play to work properly, a ros core must be running. In a new terminal:

$ roscore

Starting the sound_play node

In another new terminal, start the sound_play node. This node will play sounds when it receives sound messages:

$ rosrun sound_play soundplay_node.py

You will see:

Playing Sound

In a new terminal, test that your speaker is configured properly and playing sound. Try saying "hello world":

$ rosrun sound_play say.py "hello world"

You will see:

And you should hear "Hello world"


If you encounter problems in this Tutorial, have a look at the Troubleshooting page, it may have a solution for you.

2020-01-18 13:12