Reputation: 10144
Is it possible to have a vb.net program sound the PC's internal speaker? you know the one that produces C's \a
BELL
I have tried beep()
, but this only produces the error sound on the sound card.
I have also tried
<Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint:="Beep", SetLastError:=True, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, ExactSpelling:=True, _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall)> _
Public Shared Function _
aBeep(ByVal dwFreq As Integer, ByVal dwDuration As Integer) _
As Boolean
End Function
With no joy apparently its only good on Vista and above. Any suggestions?
Upvotes: 5
Views: 4564
Reputation: 12589
Using the My
namespace in VB.NET, you can get access to audio by going through My.Computer.Audio
. This has a Play
method with a number of overloads that allow you to pass in a .wav sound by file location or as a Byte array or Stream, but it also has a PlaySystemSound
method which takes an enum, one of which is Beep
. So the full line to play this sound is:
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
No guarantees but as it's part of the .Net framework I think this should work on XP and Vista...
Upvotes: 3