3

这个 python 代码的 PHP 版本是什么?

import winsound
winsound.Beep(537, 2000)
4

6 回答 6

8

php主要用在webservers上,那哔哔有什么用,通过php不能在用户电脑上哔哔,因为php是翻译成html的,没有这种方法。

如果您想要 Win32 调用,请查看:如何从 PHP 进行 Win32 API 调用? 还有Win32 哔声功能

但是,如果您想在用户浏览器上发出哔声,最好将音频嵌入 HTML本身。

编辑:另一种只发出哔哔声的方法

<?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;
  }
?>

当通过浏览器运行时,这不会做任何事情,如果通过 shell 运行,它将产生一个可听见的哔哔声 $int_beeps 次。这应该适用于 Windows、Unix 等。

于 2009-12-17T06:23:24.157 回答
2

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:

system('cmd /k go.bat')

And I would get nothing at all if I used:

exec('cmd /k go.bat')

Instead i used either of:

exec('start /MIN go.bat')
exec('cmd.exe /k start /MIN go.bat')

the only side effect is that a cmd.exe does flash, so the /MIN ensures that it only flashes to the taskbar.

于 2011-02-11T15:34:20.933 回答
1

更新:没关系,我以为你只想要“哔”声,而不是音调。

老帖子,不回答问题:

你需要制作一个 .bat 文件,所以: 打开 cmd

copy con go.bat [Enter]
@echo off [Enter]
echo [Ctrl+G] [Enter]
[Ctrl+Z] [Enter]

这看起来像:

C:\DEV\test>copy con go.bat
@echo off
echo ^G
^Z
    1 file(s) copied.

现在您只需通过 exec() 或 system() 或其他方式从 PHP 调用 go.bat。不过,您需要通过 cmd 制作 go.bat,以使 Ctrl+G 字符正确。

于 2009-12-17T06:56:09.737 回答
1

这个适用于标准/内置哔声。(更多的是“doink”的声音)

也适用于任何平台。

超级简单,复制粘贴代码。

function beep()
{
    fprintf ( STDOUT, "%s", "\x07" );
}

于 2020-05-21T21:10:20.367 回答
1

EZ方式:

您可以从 html 获得帮助:

echo "<audio src='http://freesoundeffect.net/sites/default/files/incorrect-answer--6-sound-effect-99679566.mp3' autoplay ></audio>"; 

此代码在后台播放哔声,您可以更改 .mp3 文件

于 2022-01-01T16:19:42.740 回答
0

当然,人们用 PHP 编写 GUI 应用程序——这就是 wxPHP 的用途。

安装 mpg321 - 一个小巧的声音应用程序:

exec("mpg321 --quiet --gain 10 /path/to/beep.mp3");
于 2015-03-23T02:54:54.983 回答