Reputation: 41
please tell me how to play a sound file(.wav) using php script. I need to get the values from DB and Depending upon the values i should play a sound file. thanks in advance.iam using linux operating system.
Upvotes: 1
Views: 34683
Reputation: 1884
You need to embed player in HTML, if you have to do it dynamically using PHP, do something like this...
$myAudioFile = "myAudiofile.wav";
echo '<EMBED SRC="'.$myAudioFile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>';
Update: As per the new HTML5 standard we can use the built-in audio player
$myAudioFile = "myAudiofile.wav";
echo '<audio autoplay="true" style="display:none;">
<source src="'.$myAudioFile.'" type="audio/wav">
</audio>';
Upvotes: 7
Reputation: 577
And on Ubuntu Linux install something like play
sudo apt install sox
(from https://askubuntu.com/a/920542/355766)
Then in php
exec('/usr/bin/play /path/to/audio.wav');
Upvotes: 3
Reputation: 1199
On Windows we can use powershell
:
exec('powershell -c (New-Object Media.SoundPlayer "C:\Windows\Media\notify.wav").PlaySync();');
Upvotes: 1
Reputation: 9382
PHP is only a processing language, it cannot play audio for the user, It can display HTML/Javascript code that will play the wav sound though.
Upvotes: 7