在C#中访问语音样本识别信号?

时间:2018-01-04 20:23:25

标签: c# speech-recognition speech sfspeechrecognizer

如何访问由speechRecognitionEngine处理的信号样本? [C#]

private void Form1_Load(object sender, EventArgs e)
{                                                    
    SpeechRecognitionEngine engine = new SpeechRecognitionEngine();

    Choices choices = new Choices();
    choices.Add(new string[] {"example", "example2"};

    GrammarBuilder grammarBuilder = new GrammarBuilder();
    grammarBuilder.Append(choices);
    Grammar grammar = new Grammar(grammarBuilder);

    engine.LoadGrammarAsync(grammar);
    engine.SetInputToDefaultAudioDevice();
    engine.SpeechRecognized += engine_SpeechRecognized;
    ...
}

private void engine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
   ...
}

基本上我的程序可以很好地识别语音,但是如何才能访问识别信号的特定样本?我知道我可以选择:

RecognizedAudio audio = e.Result.Audio;

但它没有给我我想要的数据。我想要一个int或其他东西的向量。请帮忙

1 个答案:

答案 0 :(得分:1)

看起来你应该使用的方法是WriteToAudioStream()和/或WriteToWavStream()。

有关详细信息,请参阅microsoft页面WriteToAudioStream Example

这样的事情可能会让你开始

        MemoryStream audioStream = new MemoryStream();
        e.Result.Audio.WriteToAudioStream(audioStream);
        //write to file
        FileStream file = new FileStream("d:\\file.txt", FileMode.Create, FileAccess.Write);
        audioStream.WriteTo(file);
        audioStream.Close();
        file.Close();