Posts: 1
Joined: Sun Nov 10, 2019 6:18 pm

Problem with streaming ALSA with script.

Sun Nov 10, 2019 6:26 pm


I created a webserver using apache and php on the raspberry. Would like to stream the USB mic or webcam mic attached to the raspberry to the user accessing the server.

I tried using arecord -D plughw:1,0 -f dat | ssh -C user@host aplay -f dat on the command line it works perfectly.
I tried created a bash script where I would sh the file on the command line it works well.
I tried manually "php audio.php" on the command line it works.

But when I tries opening with a php script from the client browser. it seems to have problem, it doesn't work.

Code: Select all

shell_exec('arecord -D plughw:1,0 -f dat | ssh -C user@host aplay -f dat');


Code: Select all


Does anyone knows how can I solve this?

Posts: 227
Joined: Tue Oct 15, 2019 3:56 pm

Re: Problem with streaming ALSA with script.

Fri Nov 22, 2019 9:56 am

For seven years I have not written programs in php, so my advice can be just advice.
It seems to me that you have problems with the rights to execute the script (this can be seen in the settings of the Apache web server - is it allowed to execute external scripts).
In addition, I advise you to use another program to run ssh
This is sshpass program
sudo apt-get install sshpass
sshpass -f <(printf '% s \ n' user) ssh user @ 192. *. *. 8 command

There may also be bans on executing a script with ssh from a user
Perhaps you should start by checking rights and then checking other solutions.
 I once had a funny problem: ssh did not run an external script because it was necessary to “clear” the keys. For half an hour I could not find what was the reason for the script working poorly, because I did not see the ssh output

Return to “Graphics, sound and multimedia”