错误"未安装识别器"承认演讲

时间:2014-12-24 04:07:23

标签: c# .net speech-recognition

我尝试用C#识别语音,但开始很糟糕。我曾在YouTube上关注过一些教程,但每次都会出现此错误。所以我得到了Microsoft MSDN代码,我试图在Google中找到一些解决方案。这是我正在使用的代码:

public Form1()
    {
        InitializeComponent();
        Initialize();
    }

    private void Initialize()
    {

        // Create a new SpeechRecognitionEngine instance.
        SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
        // Configure the input to the recognizer.
        //sre.SetInputToWaveFile(@"c:\Test\Colors.wav");
        sre.SetInputToDefaultAudioDevice();

        // Create a simple grammar that recognizes "red", "green", or "blue".
        Choices colors = new Choices();
        colors.Add(new string[] { "red", "green", "blue" });

        // Create a GrammarBuilder object and append the Choices object.
        GrammarBuilder gb = new GrammarBuilder();
        gb.Append(colors);

        // Create the Grammar instance and load it into the speech recognition engine.
        Grammar g = new Grammar(gb);
        sre.LoadGrammar(g);

        // Register a handler for the SpeechRecognized event.
        sre.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);

        // Start recognition.
        sre.Recognize();
    }

    // Create a simple handler for the SpeechRecognized event.
    void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        MessageBox.Show("Speech recognized: " + e.Result.Text);
    }

我已经下载了Microsoft Speech Platform SDKRuntime Languages(美国)。错误仍然存​​在。

我也已经使用过此代码,正如我在StackOverflow中的主题中所看到的那样:

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

它不起作用,所以我尝试使用它(正如我在MSDN中看到的那样):

 SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));

当我尝试使用这些代码时,错误会更改并说:“找不到所需ID的识别器”。 我使用Windows 7(Home Basic,x64),Microsoft Visual C#2010 Express。我的默认语言(系统语言也是)是葡萄牙语(巴西),也许这是错误的原因? 嗯,就是这样,我希望我写的所有详细信息都可以让你理解。对不起我的英语我正在训练这个,哈哈:P

1 个答案:

答案 0 :(得分:1)

运行以下命令以确定您已安装的识别器,断点/调试并检查是否需要

foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
{
    System.Diagnostics.Debug.WriteLine(ri.Culture.Name);
}

使用SpeechRecognitionEngine构造函数中列出的文化之一