Audio - how to transfer ogg/wav audio format files between two ROS topics

1,136 views
Skip to first unread message

Maksym Figat

unread,
Oct 16, 2014, 11:19:28 AM10/16/14
to ros-sig-...@googlegroups.com
Audio - how to transfer ogg/wav audio format files between two ROS topics

I dont know how to create message structure to pass through Ros Topic frame from wav file. 

I've found audio_common package where there is audio_common_msgs and audio_capture. Do you know how to use it? I want to send frames recorded by nao.

Thanks a lot for your help

Maksym Figat




Vincent Rabaud

unread,
Oct 17, 2014, 1:35:19 AM10/17/14
to ros-sig-...@googlegroups.com
what problem are you trying to solve exactly ? You want to record audio from NAO and you want to replay it on NAO ? Or locally on your machine ?

--
You received this message because you are subscribed to the Google Groups "ROS Sig Aldebaran" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ros-sig-aldeba...@googlegroups.com.
To post to this group, send email to ros-sig-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ros-sig-aldebaran.
To view this discussion on the web visit https://groups.google.com/d/msgid/ros-sig-aldebaran/921cc365-a76b-459f-a75b-322ac31ad97f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maksym Figat

unread,
Oct 20, 2014, 11:08:37 AM10/20/14
to ros-sig-...@googlegroups.com
I want to record audio on a robot and then send it to a ROS node. Using topic. Is it possible, whatdo you think?

Vincent Rabaud

unread,
Oct 21, 2014, 3:53:13 AM10/21/14
to ros-sig-...@googlegroups.com

Sam Pfeiffer

unread,
Dec 4, 2014, 1:02:03 PM12/4/14
to ros-sig-...@googlegroups.com
I would like to play the stream of audio reported by the topic published in the link you posted Vincent:

I haven't found any example of that. I've made this little repo:

With a rosbag from a Nao from the audio topic and I made a very dummy converting script from AudioBuffer Naoqi message to audio_common AudioData message:

Which, obviously, does not work as the audio_play node from audio_common does not actually do anything (at least on my machine).

So my question is, is there any example of anything that plays whatever is published in that topic? Or, writes it to an audio file? (Probably a lot easier because you don't need to deal with acquiring audio cards and so).

Have a nice day!

samb...@aldebaran-robotics.com

unread,
Dec 5, 2014, 5:32:09 AM12/5/14
to ros-sig-...@googlegroups.com

Hello !

I did that once to listen the audio messages in a bag. But only in Python on Ubuntu :(. Hope this will work for you as well.

I used the python package ossaudiodev (you might need to install osspd).

Then you need to create a device and set it up:

import ossaudiodev
self.device = ossaudiodev.open('w')
self.device.setfmt(format) # format corresponding to the buffers in the bag => if you use nao_sensors node, format = ossaudiodev.AFMT_S16_LE

# Let's assume msg is a ros AudioBuffer message
self.device.channels(numberOfChannelsUsed) # correspond to len(msg.channelMap)
self.device.speed(rate) # correspond to msg.frequency

# the setting (format, channels, rate) can be done only once

Then you can play the data in the message after turning it into raw data:

tmp = list(msg.data)
dataBuff = ""

for i in range (0,len(tmp)) :
    if tmp[i]<0 :
        tmp[i]=tmp[i]+65536
    dataBuff = dataBuff + chr(tmp[i]%256)
    dataBuff = dataBuff + chr( (tmp[i] - (tmp[i]%256)) /256)

self.device.write(dataBuff)


Hope this help :)

Best,
Surya

This email and any attachment thereto are confidential and intended solely for the use of the individual or entity to whom they are addressed.
If you are not the intended recipient, please be advised that disclosing, copying, distributing or taking any action in reliance on the contents of this email is strictly prohibited. In such case, please immediately advise the sender, and delete all copies and attachment from your system.
This email shall not be construed and is not tantamount to an offer, an acceptance of offer, or an agreement by Aldebaran Robotics on any discussion or contractual document whatsoever. No employee or agent is authorized to represent or bind Aldebaran Robotics to third parties by email, or act on behalf of Aldebaran Robotics by email, without express written confirmation by Aldebaran Robotics’ duly authorized representatives.


Ce message électronique et éventuelles pièces jointes sont confidentiels, et exclusivement destinés à la personne ou l'entité à qui ils sont adressés.

Si vous n'êtes pas le destinataire visé, vous êtes prié de ne pas divulguer, copier, distribuer ou prendre toute décision sur la foi de ce message électronique. Merci d'en aviser immédiatement l'expéditeur et de supprimer toutes les copies et éventuelles pièces jointes de votre système.

Ce message électronique n'équivaut pas à une offre, à une acceptation d’offre, ou à un accord d'Aldebaran Robotics sur toute discussion ou document contractuel quel qu’il soit, et ne peut être interprété comme tel. Aucun employé ou agent d’Aldebaran Robotics n'est autorisé à représenter ou à engager la société par email, ou à agir au nom et pour le compte de la société par email, sans qu’une confirmation écrite soit donnée par le représentant légal d’Aldebaran Robotics ou par toute autre personne ayant reçu délégation de pouvoir appropriée.

Sam Pfeiffer

unread,
Dec 5, 2014, 5:35:57 AM12/5/14
to ros-sig-...@googlegroups.com
It's actually very awesome it's Python!

I'll give a try soon, thank you!

--
You received this message because you are subscribed to a topic in the Google Groups "ROS Sig Aldebaran" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ros-sig-aldebaran/M7Q3P51Akv8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ros-sig-aldeba...@googlegroups.com.

To post to this group, send email to ros-sig-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ros-sig-aldebaran.

Sam Pfeiffer

unread,
Dec 5, 2014, 6:58:03 AM12/5/14
to ros-sig-...@googlegroups.com
Hey!

I tried to use the code you posted but it does not work for me. I've made a script with some comments on what I've been trying here:


The thing is I get this error to start off:
IOError: [Errno 2] No such file or directory: '/dev/dsp'

Which, by googling a bit, seems to be normal as that's kind of deprecated as my ubuntu 12.04 uses PulseAudio.
Then I tried using "aoss python play_stream.py" as suggested in some Ubuntu questions thingy. But it didn't do anything.

Then I tried using the tool "padsp ./play_stream.py" which actually gives an interface that works but the commands like:
self.device.setfmt(ossaudiodev.AFMT_S16_LE)
self.device.channels(len(msg.channelMap))
self.device.speed(msg.frequency)

Fail miserably with:
IOError: [Errno 22] Invalid argument

I just commented them out and tried anyways and I can hear beautiful random noise. So, yeah, I can't configure the virtual-hackish device provided by "padsp". I've googled a bit about Python libraries to access low level audio but it seems it's not too working out of the box.

I'll keep trying some other stuff but I don't have any experience playing with audio to tell the truth.

Surya Ambrose

unread,
Dec 5, 2014, 7:31:35 AM12/5/14
to ros-sig-...@googlegroups.com
Hi again!

Yes /dev/dsp is indeed deprecated, but installing osspd should have emulated it. Did you install this package ?

I don't know how padsp works, maybe it is normal that configuration lines fail.. About the random noise you get, is it expected ?

Please tell me if osspd is installed, if not try
sudo apt-get install osspd

If installing this package does not solve your issues, we will have to find something else :)


For more options, visit https://groups.google.com/d/optout.

Sam Pfeiffer

unread,
Dec 5, 2014, 10:09:13 AM12/5/14
to ros-sig-...@googlegroups.com
Hey!

2014-12-05 13:31 GMT+01:00 Surya Ambrose <samb...@aldebaran.com>:
Hi again!

Yes /dev/dsp is indeed deprecated, but installing osspd should have emulated it. Did you install this package ?
 
I don't know how padsp works, maybe it is normal that configuration lines fail.. About the random noise you get, is it expected ?

Well, there is audio getting out, is better than nothing. I'm giving it an array of audio without knowing what configuration does the device have. Probably not the same than the audio I'm giving it from the rosbag of Nao.
 
 
Please tell me if osspd is installed, if not try
sudo apt-get install osspd
I tried doing that but:

sudo apt-get install osspd
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package osspd

And as I could simply import the python library
import ossaudiodev

I thought I was safe.
 

If installing this package does not solve your issues, we will have to find something else :)

So I found out osspd in ubuntu 12.04 has some kind of bug that makes it not work it seems in this thread:

From there, they point to someone that actually made a debian of a patched version:

So, just for the sake of trying it, I tried to isntall the debian for my system:
sudo dpkg -i osspd_1.3.2-6_amd64.deb 
Selecting previously unselected package osspd.
dpkg: regarding osspd_1.3.2-6_amd64.deb containing osspd:
 osspd conflicts with oss-compat
  oss-compat (version 1) is present and installed.
dpkg: error processing osspd_1.3.2-6_amd64.deb (--install):
 conflicting packages - not installing osspd
Errors were encountered while processing:
 osspd_1.3.2-6_amd64.deb


I don't really want to uninstall that because it will uninstall other packages (like pygame) so... I would say I'm stuck :P
 

Sam Pfeiffer

unread,
Dec 5, 2014, 10:25:46 AM12/5/14
to ros-sig-...@googlegroups.com
By the way the topic from where I'm recording is being published by the microphone node (I believe), and there is a funny comment:

# get data directly with the _getInputBuffer() function because inputBuff is corrupted in python

Which is not actually being done, the code uses inputBuff. Albeit not being the problem I'm fighting, someone may fall in it.

Surya Ambrose

unread,
Dec 5, 2014, 10:28:07 AM12/5/14
to ros-sig-...@googlegroups.com
All right. I did not know osspd was not available for 12.04. Forget it, it is better to fnd a solution compatible with your system :)
I made a version of the sound message player using python-alsaaudio, which should be available on your system. but I did not keep it because the sound was not nice. But let's give a try shall we :) ?

First, install python-alsaaudio. For 12.04, you should have version 0.5. I am using version 0.7, let's hope they did not change their API too much, I could not find the doc of 0.5 :(.

Then the behavior is similar to ossaudiodev

import alsaaudio
self.device = alsaaudio.PCM()
self.device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
self.device.setchannels(channels)
self.device.setrate(rate)
self.device.write(data)




For more options, visit https://groups.google.com/d/optout.

Surya Ambrose

unread,
Dec 5, 2014, 10:33:38 AM12/5/14
to ros-sig-...@googlegroups.com
About the comment, I will check, but this is probably an old thing.

Sam Pfeiffer

unread,
Dec 5, 2014, 11:50:06 AM12/5/14
to ros-sig-...@googlegroups.com
Hey!

Thank you very much, I got it to work, with this script:


It plays every message happily. I made some numbers and I see every message has 1/5s of audio. Cool.

Well, now some friends will maybe use this to feed the audio to something else. If you wanna use the script as an example somewhere, feel free to do it. The worst thing is that it's not very pleasant to listen to. Maybe buffering a bit to make the sound continuous would help, I don't know (but being python I doubt the realtimeness of it will work).

So, once again, thank you very much! I'll have a happier wekeend feeling this was accomplished haha

Surya Ambrose

unread,
Dec 5, 2014, 12:14:15 PM12/5/14
to ros-sig-...@googlegroups.com
Glad I could help :).
Yeah the sound is not pleasant at all with this, that is why I used ossaudiodev, it sounds much better. I will try to find a more portable option someday :).

Have a nice week-end !


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages