Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make PHP output a sound (beep)?

What's the PHP verson of this python code?

import winsound
winsound.Beep(537, 2000)
like image 390
user198729 Avatar asked Oct 22 '25 15:10

user198729


1 Answers

php is mostly used on webservers, so what the use beeping there, and you can't beep on user computer through php, as php is translated into HTML, which has no such method.

If you want to have Win32 calls have a look at: How do I make Win32 API calls from PHP? also the Win32 Beep Function

But if you want to have beep sound on user browser better embed audio into the HTML itself.

Edit: Another method for just the beep:

<?php
  function beep ($int_beeps = 1) {
    for ($i = 0; $i < $int_beeps; $i++): $string_beeps .= "\x07"; endfor;
    isset ($_SERVER['SERVER_PROTOCOL']) ? false : print $string_beeps;
  }
?>

This will not do anything when running through a browser, if running through a shell it will produce an audible beep $int_beeps times. This should work on Windows, Unix, etc.

like image 137
Priyank Bolia Avatar answered Oct 25 '25 05:10

Priyank Bolia