如何让PHP输出声音(嘟嘟声)?
这个 python 代码的 PHP 版本是什么?
import winsound
winsound.Beep(537, 2000)
What's the PHP verson of this python code?
import winsound
winsound.Beep(537, 2000)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
php主要用在网络服务器上,所以在那里发出蜂鸣声有什么用,而且你不能通过php在用户计算机上发出蜂鸣声,因为php被翻译成HTML,没有这样的方法。
如果您想进行 Win32 调用,请查看:How do我从 PHP 进行 Win32 API 调用?
还有 Win32 蜂鸣功能
但是如果您希望在用户浏览器上更好地将音频嵌入 HTML 本身。
编辑: 另一种仅发出蜂鸣声的方法:
运行时不会执行任何操作通过浏览器,如果通过 shell 运行,它将产生 $int_beeps 次的蜂鸣声。这应该适用于 Windows、Unix 等。
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:
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.
这适用于标准/内置蜂鸣声。 (更多的是“doink”声音)
也适用于任何平台。
超级简单,复制粘贴代码。
This one works with the standard/built-in beep sound. (more of a 'doink' sound)
Also works on any platform.
Super simple, copy-paste code.
我尝试了 Tor Valamo 的建议,但仍然无法播放声音。
我只会在屏幕上得到 chr(7) 的表示,但在使用时没有声音:
如果我使用,我什么也得不到:
相反,我使用了以下任何一个:
唯一的副作用是 cmd.exe 确实flash,因此 /MIN 确保它只闪烁到任务栏。
I tried what Tor Valamo suggested, but I still couldn't get the sound to play.
I would simply get a representation of the chr(7) on my screen but no sound when I used:
And I would get nothing at all if I used:
Instead i used either of:
the only side effect is that a cmd.exe does flash, so the /MIN ensures that it only flashes to the taskbar.
更新:没关系,我以为你只是想要“嘟嘟”声,而不是提示音。
老帖子,没有回答问题:
您需要制作一个 .bat 文件,所以:
打开 cmd
这看起来像:
现在您只需通过 exec() 或 system() 或其他方式从 PHP 调用 go.bat 即可。不过,您需要通过 cmd 创建 go.bat,以使 Ctrl+G 字符正确。
Update: Never mind, I thought you just wanted a 'beep', not a TONE.
Old post, not answering the question:
You'd need to make a .bat file, so:
Open cmd
This looks like:
Now you just call go.bat from PHP through exec() or system() or something. You need to make go.bat through cmd though, in order for the Ctrl+G character to be correct.
当然,人们用 PHP 编写 GUI 应用程序——这就是 wxPHP 的用途。
安装 mpg321 - 一个小型声音应用程序:
Of course people write GUI apps in PHP - that's what wxPHP is for.
Install mpg321 - a tiny sound app:
EZ way
EZ way????:
you can get help from html :
这会产生蜂鸣声,但与winsound不同的是,它不允许您指定
频率、持续时间
..this generates a beep, but unlike winsound, does not allow you to specify
frequency, duration
..