语音识别程序不捕获语音/命令

Speech Recognition Program does not capture voice / command

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Speech.Recognition;

namespace ConsoleApp2
{
  class Program
  {
     static SpeechRecognitionEngine recEngine = new 
     SpeechRecognitionEngine();
     bool keyHold = false;

     static void Main(string[] args)
     {
        Choices commands = new Choices();
        commands.Add(new string[] { "Current dollar value", "Current euro value" });
        GrammarBuilder gBuilder = new GrammarBuilder();
        gBuilder.Append(commands);
        Grammar grammar = new Grammar(gBuilder);

        recEngine.LoadGrammarAsync(grammar);
        recEngine.SetInputToDefaultAudioDevice();
        recEngine.RecognizeAsync(RecognizeMode.Multiple);
     }

     void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
     {
         switch (e.Result.Text)
         {
            case "Current dollar value":
                Console.WriteLine("10kr");
                break;

            case "Current euro value":
                Console.WriteLine();
                break;
        }
     }
  }
}

程序刚启动就关闭了,并没有录下我的声音,我试过在代码recEngine.RecognizeAsync(RecognizeMode.Multiple);的这一行下面加一个console.readkey();。它阻止了程序并且没有自动关闭 ofc 但程序仍然没有记录我收到的语音命令。
这是为什么?

语音识别是事件驱动的。
您需要定义必要的事件处理程序。
SpeechRecognitionEngine.SpeechRecognized Even 必须订阅才能收到识别结果。
另见 SpeechRecognitionEngine.AudioStateChanged Event

此外,在开始识别之前必须使用新设置更新引擎:
参见 SpeechRecognitionEngine.RequestRecognizerUpdate Method

Note:
I used only "dollar" and "euro" as Grammar items as a hint: try to use the less key words possible in you grammars, otherwise they become very difficult to handle. You can pronounce the whole "Current dollar value" phrase, the recognized key word, however, is "dollar".

using System.Speech.Recognition;

  static void Main(string[] args)
  {
    using (SpeechRecognitionEngine recEngine = new SpeechRecognitionEngine())
    {
       recEngine.SpeechRecognized += 
             new EventHandler<SpeechRecognizedEventArgs>(recEngine_SpeechRecognized);
       recEngine.AudioStateChanged += 
             new EventHandler<AudioStateChangedEventArgs>(recEngine_AudioStateChange);

       Choices commands = new Choices();
       commands.Add(new string[] { "dollar", "euro" });
       GrammarBuilder gBuilder = new GrammarBuilder();
       gBuilder.Append(commands);
       Grammar grammar = new Grammar(gBuilder);

       recEngine.SetInputToDefaultAudioDevice();
       recEngine.LoadGrammarAsync(grammar);
       recEngine.RequestRecognizerUpdate();

       recEngine.RecognizeAsync(RecognizeMode.Multiple);

       Console.ReadKey();
       recEngine.SpeechRecognized -= recEngine_SpeechRecognized;
       recEngine.AudioStateChanged -= recEngine_AudioStateChange;
    }
  }

  internal static void recEngine_AudioStateChange(object sender, AudioStateChangedEventArgs e)
  {
     Console.WriteLine("Current AudioLevel: {0}", e.AudioState);
  }

  internal static void recEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
  {
     switch (e.Result.Text)
     {
        case "dollar":
           Console.WriteLine("10kr");
           break;
        case "euro":
           Console.WriteLine("A lot more");
           break;
     }
  }

Note2:
On Windows 7, System.Speech.Recognition is not working.
Speech Recognition and TTS (Text To Speech) can be enabled using the free development tools of Microsoft Speech Platform. Download and install the SDK, Runtime and desidered languages. This is the server speech recognition implementation, developed to support speech recognition through telephone lines. So it features a very good native filter for noises and a good tolerance in regard to pronunciation quirks.