gpt4 book ai didi

c# - 如何使用PC扬声器发出哔哔声?

转载 作者:太空狗 更新时间:2023-10-29 18:16:32 24 4
gpt4 key购买 nike

我想在 C# 中使用 PC 扬声器发出哔声。使用以下代码时:

[DllImport("kernel32.dll", EntryPoint = "Beep", SetLastError = true,
ExactSpelling = true)]
public static extern bool Beep(uint frequency, uint duration);

static void Main()
{
while (true)
{
Beep(1000, 500);
Thread.Sleep(2000);
}
}

它不是通过 PC 扬声器发出哔哔声,而是简单地将给定频率和持续时间的声音输出到默认声音设备(例如耳机)。使用 Console.Beep() 时也会发生同样的事情。

为什么?

注意事项:

  • PC 扬声器已打开。当我启动电脑时,它会发出哔哔声。

  • 操作系统为 Windows 8。

最佳答案

从 Windows 7 开始,您无法再通过内置扬声器轻松发出声音。

For Windows 7, we resolved the issue completely – we moved all the functionality that used to be contained in Beep.Sys into the user mode system sounds agent – now when you call the Beep() API instead of manipulating the 8254 chip the call is re-routed into a user mode agent which actually plays the sounds.

[…]

There were also some unexpected consequences. The biggest was that people started noticing when applications called Beep(). They had placed their PCs far enough away (or there was enough ambient noise) that they had never noticed when their PC was beeping at them until the sounds started coming out their speakers.

详情请看这里

https://learn.microsoft.com/en-us/archive/blogs/larryosterman/whats-up-with-the-beep-driver-in-windows-7

关于c# - 如何使用PC扬声器发出哔哔声?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12794846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com