Adas
Adas

Reputation: 65

Access to samples of speech recognized signal in C#?

How can i get acces to samples of signal that is processed by 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)
{
   ...
}

Basically my program recognizes speech well, but how can i get access to particular samples of the recognized signal? I know i can go with:

RecognizedAudio audio = e.Result.Audio;

but it doesn't give me the data i want. I want a vector of int's or something. Please help

Upvotes: 0

Views: 80

Answers (1)

Joseph Mawer
Joseph Mawer

Reputation: 298

Looks like the methods you should be using are WriteToAudioStream() and/or WriteToWavStream().

See the microsoft page for more details WriteToAudioStream Example

something like this might get you started

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

Upvotes: 1

Related Questions