0

我正在使用 microsoft 语音识别器[Microsoft.Speech.Recognition] 开发语音识别程序

SpeechRecognitionEngine sre;
private void button1_Click(object sender, EventArgs e)
{
  sre = new SpeechRecognitionEngine(new   CultureInfo(CultureInfo.CurrentCulture.Name.ToString())); //exception occurred here 
 // Create a simple grammar that recognizes “red”, “green”, or “blue”.
        Choices colors = new Choices();
        colors.Add("red");
        colors.Add("green");
        colors.Add("blue");

        GrammarBuilder gb = new GrammarBuilder();
        gb.Append(colors);

        // Create the actual Grammar instance, and then load it into the speech recognizer.
        Grammar g = new Grammar(gb);
        sre.LoadGrammar(g);

        // Register a handler for the SpeechRecognized event.
        sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
        sre.SetInputToDefaultAudioDevice();
        sre.RecognizeAsync(RecognizeMode.Multiple);
        //string str;
        ////RecognizerInfo rf = SpeechRecognitionEngine.InstalledRecognizers();
        //SpeechRecognitionEngine spe = new SpeechRecognitionEngine ();
        //str = spe.RecognizerInfo.Id;
        //string cul = spe.RecognizerInfo.Culture.NativeName ;
    }

    // Simple handler for the SpeechRecognized event.
    void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        MessageBox.Show(e.Result.Text);
    }
}

当我运行这个程序时从接受的答案复制粘贴我在重新初始化对象“sre”时遇到异常

附加信息:未找到所需 ID 的识别器。

异常 - {“未找到所需 ID 的识别器。\r\n参数名称:区域性”}

at Microsoft.Speech.Recognition.SpeechRecognitionEngine..ctor(CultureInfo culture)
at Text_To_Speech.SpeechToText.SpeechToText_Load(Object sender, EventArgs e) in F:\VSTest\ProjeTest\form\Text To Speech\Text To Speech\Text To Speech\SpeechToText.cs:line 41
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

开发环境

视窗服务器 2012 X86

视觉工作室 2015

MicrosoftSpeechPlatformSDK - 版本 11.0 X86

语音平台运行时

4

0 回答 0