用VB.NET实现一个语音播报功能
用vb.net,从数据库里查询出一条数据,然后写一个语音播报功能,把这条数据读一遍。并在实现一个窗体上。类似与银行的报号机一样
[解决办法]
Imports DotNetSpeech '(你得去网上下载)
#Region "语音识别http://www.microsoft.com/speech/download/sdk51/ ing"
' Dim WithEvents Rc As SpeechLib.SpSharedRecoContext
' Dim RG As ISpeechRecoGrammar
Public Sub SpeechRead(ByVal Str As String)
Dim voice As SpVoice = New SpVoice
Dim spFlags As SpeechVoiceSpeakFlags = SpeechVoiceSpeakFlags.SVSFDefault
voice.Voice = voice.GetVoices(String.Empty, String.Empty).Item(3) '024 E////3 chinese
voice.Speak(Str, SpeechVoiceSpeakFlags.SVSFDefault)
End Sub
Public Sub SpeechtoWave(ByVal Str As String)
Dim voice As SpVoice = New SpVoice
voice.Voice = voice.GetVoices(String.Empty, String.Empty).Item(3)
Dim SFd As New SaveFileDialog
SFd.Filter = "All files (*.*)
[解决办法]
*.*
[解决办法]
wav files (*.wav)
[解决办法]
*.wav"
SFd.Title = "Save to a wave File"
SFd.FilterIndex = 2
SFd.RestoreDirectory = True
If SFd.ShowDialog = DialogResult.OK Then
Dim spfileMode As SpeechStreamFileMode = SpeechStreamFileMode.SSFMCreateForWrite
Dim sfstream As SpFileStream = New SpFileStream
sfstream.Open(SFd.FileName, spfileMode, False)
voice.AudioOutputStream = sfstream
voice.Speak(Str, SpeechVoiceSpeakFlags.SVSFDefault)
voice.WaitUntilDone(Timeout.Infinite)
sfstream.Close()
End If
End Sub
'Public Sub tingMyspeech()
' RG = Rc.CreateGrammar
' RG.CmdSetRuleIdState(0, SpeechRuleState.SGDSActive)
'End Sub
'Private Sub hearCMD(ByVal streamNumber As Integer, ByVal streamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Shengyin As ISpeechRecoResult) Handles Rc.Recognition
' 'Rc.Voice.Speak("I hear " & Shengyin.PhraseInfo.GetText, 11)
'End Sub
#End Region