Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#语音识别视景问题_C#_Speech Recognition - Fatal编程技术网

C#语音识别视景问题

C#语音识别视景问题,c#,speech-recognition,C#,Speech Recognition,我在尝试运行项目时遇到以下错误: A timeout occurred starting the SAPI Server. System.InvalidOperationException was unhandled Message="A timeout occurred starting the SAPI Server." Source="System.Speech" StackTrace: at System.Speech.Internal.SapiInterop.SapiRecogniz

我在尝试运行项目时遇到以下错误:

A timeout occurred starting the SAPI Server.

System.InvalidOperationException was unhandled
Message="A timeout occurred starting the SAPI Server."
Source="System.Speech"
StackTrace:
at System.Speech.Internal.SapiInterop.SapiRecognizer..ctor(RecognizerType type)
at System.Speech.Recognition.SpeechRecognizer..ctor()
at testdan.Form1..ctor() in C:\Users\Dany\Documents\Visual Studio 2008\Projects\testdan\testdan\Form1.cs:line 17
at testdan.Program.Main() in C:\Users\Dany\Documents\Visual Studio 2008\Projects\testdan\testdan\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
表格1代码:

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;
using System.Speech.Recognition;
using System.Threading;


namespace testdan
{
    public partial class Form1 : Form
    {
        SpeechRecognizer rec = new SpeechRecognizer();

        public Form1()
        {
            InitializeComponent();
            rec.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(rec_SpeechRecognized);
        }

        void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {

            lblLetter.Text = e.Result.Text;
            MessageBox.Show(e.Result.Text);
        }

        void Form1_Load(object sender, EventArgs e)
        {
            var c = new Choices();
            c.Add("close");
            c.Add("stop");
            c.Add("pause");
            var gb = new GrammarBuilder(c);
            var g = new Grammar(gb);
            rec.LoadGrammar(g);
            rec.Enabled = true;
        }

    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用系统语音识别;
使用系统线程;
名称空间testdan
{
公共部分类Form1:Form
{
SpeechRecognizer rec=新的SpeechRecognizer();
公共表格1()
{
初始化组件();
rec.speechrecogned+=新事件处理程序(rec_speechrecogned);
}
void rec_SpeechRecognized(对象发送方,SpeechRecognizedEventArgs e)
{
lblLetter.Text=e.Result.Text;
MessageBox.Show(如Result.Text);
}
void Form1\u加载(对象发送方,事件参数e)
{
var c=新选择();
c、 添加(“结束”);
c、 添加(“停止”);
c、 添加(“暂停”);
var gb=新的语法生成器(c);
var g=新语法(gb);
记录加载语法(g);
记录启用=真;
}
}
}

也许SAPI使用的驱动程序丢失了?这可能会导致它在加载期间超时。

我也看到了。如果我从“开始”菜单手动启动桌面识别器,然后运行代码,它工作正常,但似乎没有自动加载共享识别器-我不确定原因。

WSR UI显示需要多长时间?我怀疑可能发生的情况是,WSR UI的显示时间比平常长,代理超时

您可以尝试捕获异常并重试构造函数。如果幸运的话,WSR UI仍然会启动,您将能够完成构造函数