problem with Speech Sdk 5.1?

2019-09-06 10:46发布

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

        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?

标签: c# sapi
1条回答
Viruses.
2楼-- · 2019-09-06 11:22

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.
查看更多
登录 后发表回答