Usage of MP3 conversion in audiosink (evolution for pulseaudio binding)

Hello all,

In my understanding, the pulseaudio binding does not provide an Audio Sink for openhab. (I hope so, or I’ve lost several hours of my life trying to fix some non-existant issue :sweat_smile:).

So on my dev installation, I extended the binding capabilities by allowing it to connect to a loaded module-simple-protocol-tcp (a pulseaudio server side module exposing audio sink), thus providing a real Audio Sink for openhab.
It works, except that the module-simple-protocol-tcp only accept raw pcm data, which is kind of a serious limitation for a modern installation.

So, in order to allow the Audio Sink to use MP3, I plan to do some conversion/decode inside the pulseaudio binding exposing my Audio Sink (mp3 → pcm).

First : Does it sound a good idea ?
Second : I already did a proof of concept by adding a dependency inside the binding (com.googlecode.soundlibs) and using it to convert mp3 to pcm. Does is sound a good idea ?
Third : I wonder if I can use some bundle already existing in openHab. (openHab has ‘enhancedjavasound’, which is if I understand correctly a decoder for mp3). Can someone provide me some guidance on how to use it, if it’s possible ? (And if it’s a good idea, of course…)

Thanks

I have no experience with the audio part. But there are indeed audio sinks. It’s probably best to look add the voice bindings to get an idea of how to use it. I expect that the preferred way will be to use the openHAB audio sink. Maybe @Kai can give some input, as he has done some implementations.

I forgot to thank you for your reply, sorry.

So as you suggested, I checked how the default “speaker” audio sink could play MP3, and I found the library it uses.
Unfortunately, the actual code seems to use a direct approach, with a Player object, responsible for playing sound directly on the speaker, and not a converter as I hoped to find.
The code alongside in the dependency did actually define a convert method, but it uses a File as an output. And I think it’s ugly for my use case (I want to directly send audio over the network).
So I made a PR with my first attempt , which use com.googlecode.soundlibs to convert mp3 inputstream to another raw pcm stream I then send to a pulseaudio server over the network. I hope this is a valid approach.

Thanks

1 Like