System.Speech.Recognition 的问题 - SpeechRecognitionEngine 不接收语音
Issues with System.Speech.Recognition - SpeechRecognitionEngine Doesn't Pick Up Speech
我在尝试实施 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 内置麦克风
- 视觉工作室 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.
...但似乎一切正常。
我在尝试实施 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 内置麦克风
- 视觉工作室 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.
...但似乎一切正常。