2011-06-20 63 views
0

我從節約的音頻文件作爲test.wav下面Speech Sdk 5.1的問題?

 SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync; 
     SpVoice Voice = new SpVoice(); 

     SaveFileDialog sfd = new SaveFileDialog(); 

     sfd.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav"; 
     sfd.Title = "Save to a wave file"; 
     sfd.FilterIndex = 2; 
     sfd.RestoreDirectory = true; 

     SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite; 

     SpFileStream SpFileStream = new SpFileStream(); 
     SpFileStream.Open(sfd.FileName, SpFileMode, false); 

     Voice.AudioOutputStream = SpFileStream; 
     Voice.Speak(txtSpeakText.Text, SpFlags); 
     Voice.WaitUntilDone(Timeout.Infinite); 
     SpFileStream.Close();    

當我嘗試reteive文件,並轉換爲文本的不同

 SpeechRecognitionEngine RecognitionEngine = new SpeechRecognitionEngine(new CultureInfo("en-US", true)); 
     RecognitionEngine.LoadGrammar(new DictationGrammar()); 
     RecognitionEngine.SetInputToWaveFile("test.wav"); 
     RecognitionResult result = RecognitionEngine.Recognize(); 
     Grammar g = result.Grammar; 
     txt_vtc.Text = result.Text; 

爲什麼它得到這樣呢?

回答

0

此答案不是您問題的原因,但我想推薦您使用SpeechSynthesizer Class,如下面的代碼。

 using (var speechSynthesizer = new SpeechSynthesizer()) 
     { 
      speechSynthesizer.SelectVoice("Please enter your TTS engine name..."); 
      speechSynthesizer.SetOutputToWaveFile("test.wav"); 
      speechSynthesizer.Speak("test"); 
     } 

對於使用SpeechSynthesizer Class,您將有兩個好處。

  1. 並不需要重新分配Speech Sdk 5.1給客戶由於已經包含在.net framework(4, 3.5, 3.0)的事實。
  2. 比你剛纔提到的更簡單。