Play music from USB speakers using the ROS package (gx_sound_player)

Purpose

I played music from a USB speaker using the ROS package (gx_sound_player). There were some points that were stuck before playing, so I will summarize it in this article together with the confirmation procedure that was actually carried out.

The content of this article is based on the following articles.

Introduction of gx_sound_player and ROS package release procedure

Preparation

USB speaker: For example, here Ubuntu16.04 + ROS kinetic environment Test music file (.wav): For example, I will download it from here.

step1. Confirm that music can be played from the USB speaker

1. 1. Connect the USB speaker to your PC

2. Check that the sound device is visible
  $ ls -l /dev/snd/*
⇒ You should see pcmC1D0p etc.
(Hereafter, it is assumed that pcmC1D0p is the device file of the USB speaker)

3. 3. Play WAV files with aplay
  $ aplay -D hw:1,0 musicbox.wav
⇒ OK if you can play music from the USB speaker

If you cannot play music from the USB speaker, review the procedure.

step2. Test that WAV files can be played with the gx-sound package

Install the gx-sound package.

$ sudo apt install ros-kinetic-gx-sound
1. 1. Start roscore
$ source ~/catkin_ws/devel/setup.sh
$ roscore

2.gx-sound node start
$ roslaunch gx_sound_player sound_player.launch device_name:="hw:1,0"

3. 3. WAV playback
$ rosrun rulo sound-test.py
⇒ OK if you can play music from the USB speaker
Music files/home/ubuntu/Downloads/musicbox.Store in wav

sound-test.py


#! /usr/bin/env python
# -*- coding: utf-8 -*-

import actionlib
import os
import rospy

from gx_sound_msgs.msg import SoundRequestAction, SoundRequestGoal


def main():
    rospy.init_node('sound_request_client_node')
    client = actionlib.SimpleActionClient('/gx_sound_player/sound_player/sound_request', SoundRequestAction)
    client.wait_for_server()
    rospy.loginfo("connected to actionlib server")

    now = rospy.Time.now()

    #Audio3 after 0 seconds.play wav
    #Music files/home/ubuntu/Downloads/musicbox.Store in wav
    goal1 = SoundRequestGoal(stamp=now + rospy.Duration(0.0), file="/home/ubuntu/Downloads/musicbox.wav")

    rospy.loginfo("send request")
    client.send_goal(goal1)
    rospy.loginfo("send complete")
    #client.wait_for_result(rospy.Duration.from_sec(5.0))


if __name__ == '__main__':
    main()

How to stop voice

OK if you send a silent file The silent file will be downloaded from here.

Error countermeasures

If the gx-sound package cannot be found

gx-sound package installation
$ sudo apt install ros-kinetic-gx-sound
ros-kinetic-gx-sound not found

I updated the package list as follows and solved it.

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-get update

--

If an audio format error occurs

I solved it by converting the format with ffmpeg.

48000Hz audio file, 16bit LittleEndian,How to convert to stereo
$ sudo apt-get install ffmpeg
$ ffmpeg -i input.wav -ar 48000 -format S16_LE -channel 2 output.wav

reference

Introduction of gx_sound_player and ROS package release procedure Free Wave, MP3

Recommended Posts

Play music from USB speakers using the ROS package (gx_sound_player)
Call your own python module from the ROS package
Automatically organized mp3s downloaded from Google Play Music using Python
Download the file from S3 using boto.
Control the Matrix LED panel from ROS
Play with puns using the COTOHA API