speech-recognition - 使用微软语音识别,我能知道它开始和结束的时刻吗?

标签 speech-recognition

我正在使用 Microsoft 引擎进行语音识别。代码是这样的:

static ManualResetEvent _completed = null;
static void Main(string[] args)
{
     _completed = new ManualResetEvent(false);
     SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
     _recognizer.LoadGrammar(new Grammar(new GrammarBuilder("test")) Name = { "testGrammar" }); // load a grammar
     _recognizer.LoadGrammar(new Grammar(new GrammarBuilder("exit")) Name = { "exitGrammar" }); // load a "exit" grammar
     _recognizer.SpeechRecognized += _recognizer_SpeechRecognized; 
     _recognizer.SetInputToDefaultAudioDevice(); // set the input of the speech recognizer to the default audio device
     _recognizer.RecognizeAsync(RecognizeMode.Multiple); // recognize speech asynchronous
     _completed.WaitOne(); // wait until speech recognition is completed
     _recognizer.Dispose(); // dispose the speech recognition engine
} 
void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
     if (e.Result.Text == "test") // e.Result.Text contains the recognized text
     {
         Console.WriteLine("The test was successful!");
     } 
     else if (e.Result.Text == "exit")
     {
         _completed.Set();
     }
}

它似乎很酷。当我说“测试”或“退出”时,程序可能会得到。但是我能得到程序启动的确切时间以及程序完成测试并重新启动以测试另一个单词的时间吗?

最佳答案

RecognitionResult.Audio 具有音频的开始时间和持续时间。

void SpeechRecognizedHandler(object sender, SpeechRecognizedEventArgs e)
{
  if (e.Result == null) return;

  // Add event handler code here.

  // The following code illustrates some of the information available
  // in the recognition result.
      Console.WriteLine("Grammar({0}): {1}", e.Result.Grammar.Name, e.Result.Text);
      Console.WriteLine("Audio for result:");
      Console.WriteLine("  Start time: "+ e.Result.Audio.StartTime);
      Console.WriteLine("  Duration: " + e.Result.Audio.Duration);
      Console.WriteLine("  Format: " + e.Result.Audio.Format.EncodingFormat);
}

关于speech-recognition - 使用微软语音识别,我能知道它开始和结束的时刻吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24831933/

相关文章:

authentication - 有语音认证库吗?

javascript - 浏览器上的连续语音识别,例如 "ok google"或 "hey siri"

c# - 使用语音命令启用和禁用语音识别

python webrtc语音事件检测错误

Android 连续语音识别返回 ERROR_NO_MATCH 的速度太快

javascript - 我的 annyang 程序出错

android - 谷歌语音转文本 : Extra language set to "kn" but not working

speech-recognition - Microsoft.Speech.Synthesis 不适用于文本转语音但 System.Speech.Synthesis 有效。为什么?

python - 如何在 Python 程序中嵌入 Google Speech to Text API?

java - 将视频或音频转换为文本而不播放?