Play mp3 file no sound


(Chen Mosko) #1

Hello,
i running openhab on raspberry pi 3
I’m trying to play sound from mp3 file
i create this rule:

rule "Audio Test"
when
Item test_mp3 changed from OFF to ON
then
sendCommand(test_mp3, ON)
playSound("barking.mp3")
end

pressing the switch play no Sound !
if i run the command via linux cli ( omxplayer barking.mp3), it play sound no problem
if i change the audio setting in Default Sink from “system speaker with mp3 support” to "web audio"
it play sound on my browser no problems

What i’m doing wrong ?


(Robert) #2

Hi Chen,

A few things you need to do:

sudo raspi-config
in the menu: > 7 Advanced Options > A4 Audio > 1 Force 3.5mm > Save
sudo adduser openhab audio
sudo reboot

The first two lines ensure that the 3.5mm plug has precedence.
The 3rd line ensure openhab is allowed to access the audio I/O.

On my old RPi3 (Jessie) this was sufficient.
On my new RPi3 (Stretch) this was not sufficient; I haven’t found the solution yet. :frowning:


Addition:
In the openHAB rule I execute the following command:

executeCommandLine("/usr/bin/amixer cset numid=1 100%");

This ensure the volume is set to 100%.


Addition 2:
Of course there is another way, but that would be giving in and admitting that we can’t get the internal functionality working. (Where is a good description, that simply works?!?)

Instead of PlaySound() you can install mpg123

sudo apt install mpg123

and use the following command in your openhab rule to play the sound:

executeCommandLine("/usr/bin/mpg123 /etc/openhab2/sounds/doorbell.mp3");

Of course I assume you’ll have the sound files (eg, mp3 files) in the default openhab sounds folder. :slight_smile:

Cheers,
Robert.


(Mihai Badea) #3

You should also se java sound.properties - see this post: How to select audio output device?


(Robert) #4

Thanks.
That did the trick for me.

Strangely enough I’m very sure that I didn’t make that change on the old RPi (with OH2.0 instead of 2.2 and Jessie instead of Stretch).

I think a good next step is to get this from the community area into the documentation area. :wink: