c# - 微软语音识别平台

标签 c# sdk speech-recognition microsoft-speech-platform

我用 C# 编写了一个应用程序,用于使用 System.Speech 进行语音识别,它在 Windows 7 上运行良好。 但是,我正在创建可在 Windows 2003 (x86) 上运行的相同应用程序。

我的编程环境: Windows 7 x64 专业版 Visual Studio 2008

为了在我的编程环境中开发这个应用程序,我安装了:

1.Microsoft Speech Platform - 服务器运行时(版本 10.1)(x86)

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

2.Microsoft Speech Platform - 软件开发工具包 (SDK)(版本 10.1)(x86)

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

3.Microsoft Speech Platform - 服务器运行时语言(版本 10.1)

(这里安装了 en-GB 的 SR)

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

在我的程序中,我使用了 Microsoft.Speech.Recognition 而不是 System.Speech;

从 SDK 文档粘贴此代码:

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

我还在项目属性中将平台目标设置为 x86。代码编译但一旦我运行或调试它识别不起作用。知道我错过了什么吗?

最佳答案

您正在创建语音识别引擎,但未指定引擎。由于您已经安装了 en-GB 引擎,因此您需要指定一个 cultureinfo (或 recognizerinfo ):

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

关于c# - 微软语音识别平台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3600390/

相关文章:

c# - WPF Metro 窗口全屏

c# - .NET 实例方法中的 this == null - 为什么这可能?

iphone - 如何修复我的应用程序的 SIGABRT 错误?

SDK 管理器中不存在 Android 支持包

google-api - Google Speech API 的正确识别结果

google-api - Google Speech Recognition API 结果为空

c# - 如何为多个服务创建事务 'Wrapper'?

C# 失败的协变转换

iphone - 具有多个 UIViewController 的 UIScrollView

stream - C# - 捕获 RTP 流并发送到语音识别