我试图启动一个简单的语音识别程序,但是它不起作用,我已经安装了某些语言(en-GB和en-US),但是每当我使用以下语言时:
SpeechRecognitionEngine.InstalledRecognizers
它返回一个空集合。即使我只是尝试启动识别器,它也会返回“ 未安装识别器 ”。但是当我重新安装一种语言时,它说它已经被安装了。
using ( SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))
{
// Create and load a dictation grammar.
recognizer.LoadGrammar(new DictationGrammar());
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure input to the speech recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start asynchronous, continuous speech recognition.
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Keep the console window open.
while (true)
{
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud)
由于什么原因无法找到已安装的识别器?
编辑:
例外是:{System.ArgumentException:找不到所需ID的识别器。参数名称:System.Speech.Recognition.SpeechRecognitionEngine..ctor的区域性(CultureInfo文化)
和:var recognizers = SpeechRecognitionEngine.InstalledRecognizers();返回计数为0的集合
我遇到了一些奇怪的东西,我创建了一个带有反射的类的实例,它传递了几个参数,一个是变量:ipAddress,当在构造函数中创建实例时,变量存储在一个字段中,但是一旦构造函数完成后,我(在调试器中)返回到我创建实例的行,我在类中检查并且字段'ipAddress'已更改为null.这怎么可能?
这是课程的一部分:
public class moxa_nport_5110
{
string instanceName;
Delegate triggerCallBackMethod;
private BPUConsole bpuConsole { get; set; }
TcpIpServer server;
string ipAddress;
public moxa_nport_5110(Delegate TriggerCallBackMethod, Delegate Callback, params object[] CtorParam)
{
#region Initialize
triggerCallBackMethod = TriggerCallBackMethod;
instanceName = (string)CtorParam[0];
string ipAddress = (string)CtorParam[1];
int Port = (int)CtorParam[2];
bpuConsole = new BPUConsole(Callback, instanceName);
#endregion
server = new TcpIpServer("10.100.184.140", 8888, false);
server.OnDataReceived += new TcpIpServer.ReceiveEventHandler(server_OnDataReceived);
server.OnClientConnected += new TcpIpServer.InfoEventHandler(server_OnClientConnected);
server.OnClientDisconnected += new TcpIpServer.InfoEventHandler(server_OnClientDisconnected);
server.OnAbnormalConnectionDisconnect += new TcpIpServer.InfoEventHandler(server_OnAbnormalConnectionDisconnect);
server.AddClient(ipAddress, 1);
}
public void SendData(byte[] …Run Code Online (Sandbox Code Playgroud)