Trying to play white noise, controlled by PHP on Speaker pHAT


#1

I get the following error in my Apache error.log.

ALSA lib pcm_hw.c:1713:(_snd_pcm_hw_open) Invalid value for card

When running play -q -V0 --single-threaded -t sl - synth 00:00:05 whitenoise band -n 1200 200 tremolo 20 .1 < /dev/zero & from PHP, using exec() or shell_exec().

The identical command works perfectly when run directly on the CLI.

Any assistance will be greatly appreciated!


#2

Is the PHP user in the group “audio”? Although I’d expect some flavour of “Permission Denied” error if it were not.

Perhaps it’s attempting to access the wrong audio device. Does the play command accept a switch for specifying an ALSA output device?


#3

I added the www-data user to the audio group just in case, but it didn’t help.

I added the -d option (‘Use the default audio device (where available)’) to my play command, but it didn’t help, and I can’t see any other option to change the device it uses.