Brien King
Brien King

Reputation: 366

MS SpeechRecognitionEngine record underlying audio

I am using the Microsoft System.Speech SpeechRecognitionEngine for doing dictation and I need to be able to record all the audio that is being processed as well as perform speech recognition on it at the same time.

Right now I can do the speech recognition just fine, and I can get the audio for what was recognized. However, I need to be able to save the audio stream at the same time so I can use the metadata from the speech recognition to grab additional information from the entire audio stream later.

What would be the appropriate approach to doing so?

Upvotes: 3

Views: 521

Answers (2)

Travis
Travis

Reputation: 2135

Based on your comment @Brien King this is probably not exactly what you were looking for but I found Alan's answer useful but wanted to add that if you want to save audio from Rejected speech that can be done using an EventHandler for SpeechRecognitionRejected

I point this out because it wasn't obvious to me that it was possible to save audio from unsuccessful recognition. I had previously tried to use the Result object from a SpeechHypothesizedEventArgs which didn't have a lot of the data I was expecting to be available.

I am mostly adding this answer in case someone is confused about that like I was.

Upvotes: 1

alan turing
alan turing

Reputation: 463

You can save associated audio file to your disk as wave stream in the following way. For complete example see the link (http://msdn.microsoft.com/en-us/library/system.speech.recognition.recognizedaudio.writetowavestream.aspx).

 RecognizedAudio audio = e.Result.Audio;
TimeSpan start = e.Result.Words[3].AudioPosition;
TimeSpan duration = audio.Duration - start;

// Add code to verify and persist the audio.
string path = @"C:\temp\nameAudio.wav";
using (Stream outputStream = new FileStream(path, FileMode.Create))
{
  RecognizedAudio nameAudio = audio.GetRange(start, duration);
  nameAudio.WriteToWaveStream(outputStream);
  outputStream.Close();
}

Upvotes: 3

Related Questions