Microsoft Speech Recognition Platform

蓝咒 提交于 2020-01-20 19:29:47

问题


I wrote an app in C# for speech recognition using System.Speech which works fine on Windows 7. However I'm after creating the same app that will work on windows 2003 (x86).

My programming environment: Windows 7 x64 Pro Visual Studio 2008

In order to develop this application in my programming environment I installed:

1.Microsoft Speech Platform - Server Runtime (Version 10.1) (x86)

http://www.microsoft.com/downloads/details.aspx?FamilyID=674356C4-E742-4855-B3CC-FC4D5522C449&displaylang=en&displaylang=en

2.Microsoft Speech Platform - Software Development Kit (SDK) (Version 10.1) (x86)

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=4d36908b-3264-49ef-b154-f23bf7f44ef4

3.Microsoft Speech Platform - Server Runtime Languages (Version 10.1)

(here installed SR for en-GB)

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=f704cd64-1dbf-47a7-ba49-27c5843a12d5

In my program instead of System.Speech I used Microsoft.Speech.Recognition;

Pasted this code from SDK documentation:

using Microsoft.Speech.Recognition;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      // Create a new SpeechRecognitionEngine instance.
      sre = new SpeechRecognitionEngine();

      // 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);
    }

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

    SpeechRecognitionEngine sre;
  }
}

I also set platform target to x86 in project properties. Code compiles but once I run or debug it recognition doesn't work. Any idea what am I missing?


回答1:


You're creating a speech recognition engine without specifying an engine. Since you've installed the en-GB engine, you need to specify a cultureinfo (or a recognizerinfo):

sre = new SpeechRecognitionEngine(new CultureInfo("en-GB")); 


来源:https://stackoverflow.com/questions/3600390/microsoft-speech-recognition-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!