[solved] Play WAV-Files via Web-Frontend?

I’d like to use my musicbox also for outputs of my smarthome (e.g. reading calender-entries, doorbell, …).
For this I did make some WAVE-Files and also activated text-to-speech on my musicbox 0.6.0.

What would be the best way to invoke a shell-script (or aplay/pico2wave directly?) from the Web-Frontend?
I played around a bit with the fastcgi-php Plugin for lighttpd, but I guess I’m missing some rights on the scripts or players…?

Thanks for your help!

If I understand correctly, you intend for your smartphone system to signal
musicbox through http requests. You could probably hack something into the
the existing server-side code in musicbox-webclient, similar to the
handlers for shutdown and restart. But it’s not designed for people to do

If you want to run a separate php webserver then you’ll have to ensure you
configure it to listen on an available port. Mopidy uses 6680 and 80 is
redirected to 6680 through iptables. You’ll also have to ensure the
iptables firewall allows access to your chosen port.

Or you could look at something nice and simple such as

Also note that whilst mopidy is playing audio it blocks the sound device
from being used by other applications. Your separate script would have to
save the play state, stop (not pause) mopidy to release the audio device,
do it’s thing, and then restore the saved state. Or you can look into the
alsa dmix plugin which should allow multiple programs to access the audio
device. I think somebody wrote a mopidy extension which used text-to-speech
to announce things whilst mopidy was playing, you could look at how they
did that.

Thanks for your help!
I’ve come so far, that I can invoke “aplay” (for Wav-Files) and “pico2wave” (for text-to-speech) parallel to mopidy-streaming of spotify. This works fine.

for example - I invoke this bash-script with an text-argument:

# play Enterprise Intercom
aplay /media/wavs/enterprise_intercom_whistle.wav 
# take the argument (text), transform to Wave and play it, remove it
pico2wave --lang=de-DE --wave=/tmp/temp.wav "$1"; aplay /tmp/temp.wav;rm /tmp/temp.wav

Actually my problem is to call the shell-script via php, I guess, I’m confused with all the neccessary rights… :wink:
Perhaps someone knows, how to configure the scripts, the aplay/pico2wave and stuff?


Ha, I was getting a big step further!
Now I’m able to call the bash-script via PHP (system('sprachausgabe.sh "Es ist jemand vor der Türe"')!

after adding the www-data User to the audio group, there are no more errors, if I call the script locally as the www-data user. The script does all four: playing the whistle, making the temp.wav, playing the temp.wav and deleting the wav:

root@MusicBox:~# su www-data
$ /root/sprachausgabe.sh "test"
Playing WAVE '/media/wavs/enterprise_intercom_whistle.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono
Playing WAVE '/tmp/temp.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
User: www-data

If the script is called via PHP there are no errors on the console, but I can’t hear anything:

root@MusicBox:~# su www-data
$ curl localhost:81/bewegung.php
User: www-data

as you can see, the script is called to the end, the temp.wav is saved and deleted, but there’s no sound…

if the script is called directly via the PHP-interpreter sound is played:

root@MusicBox:~# su www-data
$ /usr/lib/cgi-bin/php /opt/defaultwebclient/bewegung.php
Playing WAVE '/media/wavs/enterprise_intercom_whistle.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Mono
Playing WAVE '/tmp/temp.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
X-Powered-By: PHP/5.4.45-0+deb7u1
Content-type: text/html

User: www-data

any hints? Thanks!

Can your web server access files in arbitrary locations such as /media/wavs/? Have you looked in your web server error log file?

thanks for your help…
yes, the web server is able to access the files (but I also tried with the WAV in the web-directory).
The strange thing is, there’s no entry in the webserver error.log or in the system error.log… :unamused:


to use aplay from a webserver, you also need to add the www-data-User to the video-group!! wtf!? :rage:
cost me hours in google but finally found it in some hidden part of the internet… geeez.