How do I make the computer's internal speaker beep in C# without external speakers?
6 Answers
In .Net 2.0, you can use Console.Beep().
// Default beep
Console.Beep();
You can also specify the frequency and length of the beep in milliseconds.
// Beep at 5000 Hz for 1 second
Console.Beep(5000, 1000);
For more information refer http://msdn.microsoft.com/en-us/library/8hftfeyw%28v=vs.110%29.aspx
-
11I just tested in Win 7 x64 RC, and although the internal speaker didn't beep, there was a beep through speakers when I had them plugged in and on. I guess it's just the internal (mobo) speaker that won't beep. Thanks for the info @Lck.– a_hardinOct 13, 2009 at 14:38
-
22And here is why: blogs.msdn.com/larryosterman/archive/2010/01/04/…– Michael Stum ♦Apr 23, 2010 at 23:24
-
3It should work on x64, but the sound will come out trough the normal speakers (which can be muted). blogs.msdn.com/larryosterman/archive/2010/01/04/… Apr 23, 2010 at 23:27
-
1@LorenzCK That's... not 100% true? I have Win7 64 and I am able to hear a full range of
Beep()
's frequencies through external speakers. However, +1 for the internal part, I never realized that.– B.K.Mar 7, 2014 at 20:59 -
1The default is Beep(800,200). docs.microsoft.com/en-us/dotnet/api/system.console.beep Nov 5, 2021 at 20:29
You can also use the relatively unused:
System.Media.SystemSounds.Beep.Play();
System.Media.SystemSounds.Asterisk.Play();
System.Media.SystemSounds.Exclamation.Play();
System.Media.SystemSounds.Question.Play();
System.Media.SystemSounds.Hand.Play();
Documentation for this sounds is available in http://msdn.microsoft.com/en-us/library/system.media.systemsounds(v=vs.110).aspx
-
Unfortunately these system sounds require external speakers, which can't always be counted on. It's definitely good to know these, though!– a_hardinDec 1, 2008 at 14:59
-
1Now knowing that x64 versions of Windows requires speakers to hear the Console.Beep(), these options will work just as well.– a_hardinOct 13, 2009 at 14:41
-
4My Vista x64 on laptop with inbuilt speakers doesn't play Console.Beep() but these are fine. Feb 8, 2010 at 8:29
It is confirmed that Windows 7 and newer versions (at least 64bit or both) do not use system speaker and instead they route the call to the default sound device.
So, using system.beep()
in win7/8/10 will not produce sound using internal system speaker. Instead, you'll get a beep sound from external speakers if they are available.
-
But there's no guarantee it works/beeps through sound card. On my Windows 10 machine there's no beep - sound card works of course Jan 19, 2017 at 9:59
I just came across this question while searching for the solution for myself. You might consider calling the system beep function by running some kernel32 stuff.
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
public static extern bool Beep(int freq, int duration);
public static void TestBeeps()
{
Beep(1000, 1600); //low frequency, longer sound
Beep(2000, 400); //high frequency, short sound
}
This is the same as you would run powershell:
[console]::beep(1000, 1600)
[console]::beep(2000, 400)