c# - System.Speech.Recognition 的问题 - SpeechRecognitionEngine 不接收语音

标签 c# .net windows-8 speech-recognition system.speech.recognition

我在尝试实现 Microsoft 提供的有关如何使用 SpeechRecognitionEngine (https://msdn.microsoft.com/en-us/library/system.speech.recognition.speechrecognitionengine.speechdetected(v=vs.110).aspx) 的示例时遇到了重大问题。

示例代码如下:

using System;
using System.Speech.Recognition;

namespace SampleRecognition
{
class Program
{
    static void Main(string[] args)

    // Initialize an in-process speech recognition engine.
    {
        using (SpeechRecognitionEngine recognizer =
           new SpeechRecognitionEngine())
        {

            // Create a grammar.
            Choices cities = new Choices(new string[] { 
            "Los Angeles", "New York", "Chicago", "San Francisco", "Miami", "Dallas" });

            GrammarBuilder gb = new GrammarBuilder();
            gb.Culture = new System.Globalization.CultureInfo("en-GB");
            gb.Append("I would like to fly from");
            gb.Append(cities);
            gb.Append("to");
            gb.Append(cities);

            // Create a Grammar object and load it to the recognizer.
            Grammar g = new Grammar(gb);
            g.Name = ("City Chooser");
            recognizer.LoadGrammarAsync(g);

            // Attach event handlers.
            recognizer.LoadGrammarCompleted +=
              new EventHandler<LoadGrammarCompletedEventArgs>(recognizer_LoadGrammarCompleted);
            recognizer.SpeechDetected +=
              new EventHandler<SpeechDetectedEventArgs>(recognizer_SpeechDetected);
            recognizer.SpeechRecognized +=
              new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

            // Set the input to the recognizer.
            recognizer.SetInputToDefaultAudioDevice();

            // Start recognition.
            recognizer.RecognizeAsync();

            // Keep the console window open.
            Console.ReadLine();
        }
    }

    // Handle the SpeechDetected event.
    static void recognizer_SpeechDetected(object sender, SpeechDetectedEventArgs e)
    {
        Console.WriteLine("  Speech detected at AudioPosition = {0}", e.AudioPosition);
    }

    // Handle the LoadGrammarCompleted event.
    static void recognizer_LoadGrammarCompleted(object sender, LoadGrammarCompletedEventArgs e)
    {
        Console.WriteLine("Grammar loaded: " + e.Grammar.Name);
    }

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        Console.WriteLine("  Speech recognized: " + e.Result.Text);
    }
  }
}

似乎没有任何效果,我尝试了很多不同的例子,并花了一整天的时间试图让它发挥作用。例如,如果我将 RecognizeAsync() 替换为 EmulateRecognizeAsync("I would like to fly from Chicago to Miami"),它会按预期工作。但程序似乎没有从我的麦克风获得任何输入。

这里有更多的细节:

  • Windows 8.1
  • .NET 4.0
  • Lenovo ThinkPad 内置麦克风
  • Visual Studio 2012
  • 值得一提的是,程序的输出有这条在加载语法时写出的信息消息:

    ConsoleApplication1.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection.
    

我错过了什么吗?我需要更好的麦克风吗?除了将麦克风设置为默认麦克风之外,我还需要设置硬件吗?我需要为 Windows 8 使用不同的库吗?我没主意了。

先谢谢你!

最佳答案

原来 - 笔记本电脑内置的麦克风根本不能用于 Windows 语音识别...

我今天刚收到一副新耳机,一切正常。我仍然收到信息消息

ConsoleApplication1.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection.

...但似乎一切正常。

关于c# - System.Speech.Recognition 的问题 - SpeechRecognitionEngine 不接收语音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31256176/

相关文章:

c# - 覆盖 Autofac 注册 - 使用 DI 进行集成测试

c# - 如何在我自己的应用程序中创建一个 “Open with” 列表,如 Explore

c# - 异步命令和 Task.WhenAny 在 StackExchange.Redis 中等待后出现超时异常

c# - 在c#.net中的Array.indexof中使用正则表达式查找元素的索引

windows-8 - 如何使用 WinJS 以编程方式关闭 Win8 应用程序中的 MessageDialog?

C# - 将 xls 文件转换为 xlsx,无需 Office 组件

c# - ASP.NET 中的全局错误处理

.net - 是否有支持 dotnet 或 com 互操作的 lisp 实现或第 3 方库

c# - 相同类型的多个框架 Windows 8 c#

animation - 在 Windows 8/Metro/Store 中对 RectangleGeometry(在 Image.Clip 内)进行动画处理