【问题标题】:C# Speech Recognition VISTA ProblemC#语音识别VISTA问题
【发布时间】:2009-12-02 10:00:04
【问题描述】:

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

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()

Form1 代码:

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

    }
}

【问题讨论】:

    标签: c# speech-recognition


    【解决方案1】:

    可能缺少 SAPI 使用的驱动程序?这可能会导致它在加载期间超时。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        WSR 用户界面显示需要多长时间?我怀疑可能发生的情况是 WSR UI 的显示时间比平时要长,并且代理正在超时。

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多