我正在创建一个区间识别程序,我真的希望输出的声音稍微。。。比console.bleep输出的要好——最好是钢琴声或类似的声音。这是我用console.bleap做的,这样你就可以知道我需要做什么:
Imports System.Threading
Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
IntervalClass.PlayInterval(11, 5)
End Sub
End Class
Class IntervalClass
Protected Shared Sub Play(interval() As Note)
Dim n As Note
For Each n In interval
If n.NoteTone = Tone.REST Then
Thread.Sleep(CInt(n.NoteDuration))
Else
Console.Beep(CInt(n.NoteTone), CInt(n.NoteDuration))
End If
Next n
End Sub
Public Shared Sub PlayInterval(ByRef StartingNote As Integer, ByRef EndingNote As Integer)
Dim Notes() As String = {Tone.C3, Tone.Cs3, Tone.D3, Tone.Ds3, Tone.E3, Tone.F3, Tone.Fs3, Tone.G3, Tone.Gs3, Tone.A3, Tone.As3, Tone.B3, Tone.C4, Tone.Cs4, Tone.D4, Tone.Ds4, Tone.E4, Tone.F4, Tone.Fs4, Tone.G4, Tone.Gs4, Tone.A4, Tone.As4, Tone.B4, Tone.C5, Tone.Cs5, Tone.D5, Tone.Ds5, Tone.E5, Tone.F5, Tone.Fs5, Tone.G5, Tone.Gs5, Tone.A5, Tone.As5, Tone.B5, Tone.C6}
Dim PlayInterval As Note() = {
New Note(Notes(StartingNote), Duration.HALF), New Note(Notes(EndingNote), Duration.HALF)}
Play(PlayInterval)
End Sub
Protected Enum Tone
REST = 0
C3 = 130.81
Cs3 = 138.59
D3 = 146.83
Ds3 = 155.56
E3 = 164.81
F3 = 174.61
Fs3 = 185
G3 = 196
Gs3 = 207.65
A3 = 220
As3 = 233.08
B3 = 246.94
C4 = 261.63
Cs4 = 277.18
D4 = 293.66
Ds4 = 311.13
E4 = 329.63
F4 = 349.23
Fs4 = 369.99
G4 = 392
Gs4 = 415.3
A4 = 440
As4 = 466.16
B4 = 493.88
C5 = 523.25
Cs5 = 554.37
D5 = 587.33
Ds5 = 622.25
E5 = 659.25
F5 = 698.46
Fs5 = 739.99
G5 = 783.99
Gs5 = 830.61
A5 = 880
As5 = 932.33
B5 = 987.77
C6 = 1046.5
End Enum
Protected Enum Duration
WHOLE = 1600
HALF = WHOLE / 2
QUARTER = HALF / 2
EIGHTH = QUARTER / 2
SIXTEENTH = EIGHTH / 2
End Enum
Protected Structure Note
Private toneVal As Tone
Private durVal As Duration
Public Sub New(frequency As Tone, time As Duration)
toneVal = frequency
durVal = time
End Sub
Public ReadOnly Property NoteTone() As Tone
Get
Return toneVal
End Get
End Property
Public ReadOnly Property NoteDuration() As Duration
Get
Return durVal
End Get
End Property
End Structure
End Class
有没有什么方法可以获得更好的声音,无论是使用console.bleap还是其他方法?(最好我也能把它们放在一个数组中,因为需要索引来调用正确的音符(感谢
如果您想使用预加载的声音,那么您可以利用SystemSound类:https://learn.microsoft.com/en-us/dotnet/api/system.media.systemsound
据我所知,您可以访问:
- 星号
- Beep
- 感叹
- 手
- 问题
例如:
Dim sounds = {SystemSounds.Asterisk, SystemSounds.Beep, SystemSounds.Exclamation, SystemSounds.Hand, SystemSounds.Question}
sounds(0).Play() ' play asterisk sound
如果你想播放自定义文件,那么你可以利用SoundPlayer类:https://learn.microsoft.com/en-us/dotnet/api/system.media.soundplayer
例如:
Dim sounds = {New SoundPlayer("file1.wav"), New SoundPlayer("file2.wav"), New SoundPlayer("file3.wav")}
sounds(0).Play() ' play file1.wav