开发者

problem with Speech Sdk 5.1?

开发者 https://www.devze.com 2023-03-14 13:03 出处:网络
I am saving an audio file as test.wav from below SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;

I am saving an audio file as test.wav from below

        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();            

When i try to reteive the file and convert to text its different

  开发者_StackOverflow中文版      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;   

Why its getting like that?


This answer is not why your problem is, but I would like to recommend you to use the SpeechSynthesizer Class like the following code.

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

For using SpeechSynthesizer Class, you would have two advantages.

  1. not to need redistribute the Speech Sdk 5.1 to clients due to the fact already included at the .net framework(4, 3.5, 3.0).
  2. simpler to get the goal than you mentioned.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号