There are a couple of FAQs I often hear about using speech with audio files:
This can be done with SAPI, but judging by the frequency of these FAQs in the newsgroups, it's not exactly straight forward.
By contrast, we've tried to make it really easy with the WinFX speech API.
Here's some sample code that works with the Avalon & Indigo Beta 1 RC1 bits. There's a form with a couple of text boxes on it: txtPath where you type in the full path of a file name (e.g. "c:\test.wav"), and txtContent that either contains the recognized text or the text to be synthesized. There's a button called btnSynth. When you click it, we tell the synthesizer that its output is the filepath from txtPath, then tell the synthesizer to render the contents of txtContent. There's a button called btnReco. When you click it, we tell the recognizer to get input from the filepath in txtPath, then we load a dictation grammar (a built-in grammar provided by the recognizer that will listen for unconstrained speech), then we tell the recognizer to do a recognition.
Imports
Public
Dim WithEvents reco As New SpeechRecognizer
Dim WithEvents synth As New SpeechSynthesizer
Private Sub btnReco_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReco.Click
Me.txtContent.Text = ""
reco.LoadGrammar(New DictationGrammar())
reco.SetInput(Me.txtPath.Text)
reco.RecognizeAsync()
End Sub
Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
Me.txtContent.Text = "Recognized: " & e.Result.Text
Private Sub btnSynth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSynth.Click
synth.SetOutput(Me.txtPath.Text)
synth.SpeakAsync(Me.txtContent.Text)
Private Sub synth_SpeakCompleted(ByVal sender As Object, ByVal e As System.Speech.Synthesis.SpeakCompletedEventArgs) Handles synth.SpeakCompleted
Me.txtContent.Text = "done!"
synth.Dispose()
End Class
Some other points to note: