If you do this (and it would work) it would play an audio file on the server, not on the client.
It triggers the script on the server, and then on the server aplay gets executed. Buw how ill the client will hear this? It’s impossible.
You would need something like this:
If you really want that somebody clicks the button and then a sound gets played on the server machine, you would need to use the php function shell_exec() or exec(). So somebody clicks the button and then a shell command (aplay -D bluealsa /var/www/html/cgi-bin/warning.wav)is executed on the server. https://www.php.net/manual/en/function.shell-exec.php
Edit 2:
If you want to execute it in cgi-bin, the script needs a content type header:
i want the audio file to play back on the speaker connected to the server via bluetooth. for some reason, aplay doesn’t execute. tried adding content header - no change.
Hm maybe it’s a permission issue. With what user did you try vom CLI?
The webserver uses the user www-data. Maybe the server logs can give you some hints.
all html/cgi owned by www-data. all 755
cli run by me - alizard user
www-data is inaccessible.
i tried changing lighttpd user to www, created earlier as user account with logon.
www@DietPi:/var/www/html/cgi-bin$ groups www
www : www mail voice audio bluetooth
when i ran voice.sh:
www@DietPi:/var/www/html/cgi-bin$ ./voice.sh
Content-Type: text/plain
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5222:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM bluealsa
aplay: main:830: audio open error: No such file or directory
warning
Yes, this is intended, for security reasons. I wonder where the group www comes from, did you create it?
Unfortunately I can not help you with the errors you are facing.
But I did some similiar thing in the past with php, instead of CGI-bin.
I had a webpage to start a game server, when users clicked the button an ssh-connection got invoked to the game server and then executed a bash command. In your case you would not need the ssh part. It could looke something like this:
HTML-Button:
<a href="#" onclick="start();">
do something
</a>
php function start():
function start() {
$.get("start.php");
return false;
}