简体   繁体   English

如何在非英语Win Vista Business上使用System.Speech

[英]How to use System.Speech on non-English Win Vista Business

I´d like to try Speech recognition to controlling program. 我想尝试语音识别来控制程序。 I wrote test program in C# and when I´m debugging this, an error occurred every time - 我用C#编写了测试程序,调试时每次都会发生错误-

System.Runtime.InteropServices.COMException (0x80004005): Calling part of COM return error HRESULT E_FAIL.* 
in System.Speech.Recognition.RecognizerBase.Initialize(SapiRecognizer recognizer, Boolean inproc)
in System.Speech.Recognition.SpeechRecognitionEngine.get_RecoBase()
in System.Speech.Recognition.SpeechRecognitionEngine.LoadGrammar(Grammar grammar)

It looks the error is caused by engine.LoadGrammar(new DictationGrammar()); 看来错误是由engine.LoadGrammar(new DictationGrammar());引起的engine.LoadGrammar(new DictationGrammar()); On my notebook I installed CZECH OS Vista, and maybe this is the problem that speech recognition language is not the same as OS language. 在我的笔记本上,我安装了CZECH OS Vista,这也许是语音识别语言与OS语言不同的问题。

Is there a way how to developing with system.speech in non english OS, or am I wrong in some step? 有没有一种方法可以在非英语操作系统中使用system.speech进行开发,还是我在某些步骤上错了? There is no problem in language, I´d like use english for speech recognizing, but, I cannot get english Vista or MUI language pack. 语言没有问题,我想使用英语进行语音识别,但是我无法获得英语Vista或MUI语言包。

Full code is below. 完整代码如下。

Thanks a lot! 非常感谢!

using System;
using System.Windows;
using System.Speech.Recognition;

namespace rozpoznani_reci_WPF
{
   public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            SpeechRecognitionEngine engine = new SpeechRecognitionEngine();

            try
                {
                    engine.LoadGrammar(new DictationGrammar());
                    engine.SetInputToDefaultAudioDevice();
                    engine.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
                }

            catch(Exception e)
                {
                    //MessageBox.Show(e.ToString());
                    textBox1.Text = e.ToString();
                 }
            }

        void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (e.Result != null)
            {
                textBox1.Text = e.Result.Text + "  ";
            }
        }
      }
    }

According to the MSDN documentation on DictationGrammar , the argument-free constructor 根据DictationGrammar的MSDN文档,无参数构造函数

Initializes a new instance of the DictationGrammar class for the default dictation grammar provided by Windows Desktop Speech Technology. 为Windows桌面语音技术提供的默认听写语法初始化DictationGrammar类的新实例。

Is there a Czech language DicationGrammar class available on your machine? 您的机器上是否有捷克语DicationGrammar类? If not, you need to create one and use the other constructor DictationGrammar(String) and load one from a URI. 如果不是,则需要创建一个并使用其他构造函数DictationGrammar(String)并从URI中加载一个。 You can also use GrammarBuilder to construct your own and load it instead using SpeechRecognizer.LoadGrammar() . 您也可以使用GrammarBuilder构造自己的文件并加载它,而不是使用SpeechRecognizer.LoadGrammar()

You might also find this link useful; 您可能还会发现此链接有用。 it's from 2008, but you did ask about Vista. 是从2008年开始的,但您确实询问过Vista。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM