我将音频文件保存为test.wav,从下面
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();
当我尝试重新获取文件并将其转换为文本时,不同的
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 :(得分: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
,你会有两个好处。
Speech Sdk 5.1
的事实,不需要将.net framework(4, 3.5, 3.0)
重新分发给客户。