如何加载使用 SAPI 5.3 标签的 Grammar xml 文件?

发布于 2024-07-14 03:50:58 字数 1930 浏览 5 评论 0原文

我的问题是如何加载使用 MSDN 文档中列出的标签的语法文件? 我想使用 MSDN 中语法格式标签 (SAPI 5.3) 标题下记录的格式标签。

http://msdn.microsoft.com/en-us /library/ms723634(VS.85).aspx

其中列出了 DEFINE、LIST、OPT 等标签。但是,每当我尝试在 Grammar.xml 文件中使用这些标签时,都会收到一条错误消息,指出该标签是不支持。

如果使用仅使用 MSDN 中列出的标签 one-of、item 等的语法文件; 语法文件加载。

http://msdn.microsoft.com/en-us/library/ms870140。 aspx

我知道这可能很简单,但我似乎无法弄清楚...

语法文件...有效

  <grammar xmlns="http://www.w3.org/2001/06/grammar"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.w3.org/2001/06/grammar
                                http://www.w3.org/TR/speech-grammar/grammar.xsd"
            xml:lang="en-US" version="1.0" root="command">


  <rule id="command" scope="public">

    <one-of>
      <item>nail</item>
      <item>hammer</item>
      <item>saw</item>
    </one-of>
  </rule>

   </grammar>

代码清单------------------ -

    public Form1()
    {

        InitializeComponent();

        // set up the recognizer
        _speechRecognizer = new SpeechRecognizer();
        _speechRecognizer.Enabled = false;
        _speechRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_speechRecognizer_SpeechRecognized);

        // set up the command and control grammar
        Grammar commandGrammar = new Grammar(@"grammar.xml");
        commandGrammar.Name = "main command grammar";
        commandGrammar.Enabled = true;

        // activate the command grammer
        _speechRecognizer.LoadGrammar(commandGrammar);

        _speechRecognizer.Enabled = true;
    } 

My question is how can I load a grammar file that uses the tags they list in the MSDN docs?
I want to use the format tags that are documented in MSDN under the heading Grammar Format Tags (SAPI 5.3).

http://msdn.microsoft.com/en-us/library/ms723634(VS.85).aspx

There it lists tags like DEFINE, LIST, OPT etc. However whenever I try to use those tags in the grammar.xml file I get an error saying that that tag is not supported.

If use a grammar file that only uses the tags one-of, item, etc. That are listed here in the MSDN; the grammar file loads.

http://msdn.microsoft.com/en-us/library/ms870140.aspx

I know it is probably something simple but I cant seem to figure it out...

Grammar file...that works

  <grammar xmlns="http://www.w3.org/2001/06/grammar"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.w3.org/2001/06/grammar
                                http://www.w3.org/TR/speech-grammar/grammar.xsd"
            xml:lang="en-US" version="1.0" root="command">


  <rule id="command" scope="public">

    <one-of>
      <item>nail</item>
      <item>hammer</item>
      <item>saw</item>
    </one-of>
  </rule>

   </grammar>

Code listing-------------------

    public Form1()
    {

        InitializeComponent();

        // set up the recognizer
        _speechRecognizer = new SpeechRecognizer();
        _speechRecognizer.Enabled = false;
        _speechRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_speechRecognizer_SpeechRecognized);

        // set up the command and control grammar
        Grammar commandGrammar = new Grammar(@"grammar.xml");
        commandGrammar.Name = "main command grammar";
        commandGrammar.Enabled = true;

        // activate the command grammer
        _speechRecognizer.LoadGrammar(commandGrammar);

        _speechRecognizer.Enabled = true;
    } 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻了热茶 2024-07-21 03:50:58

您似乎使用的是 c#,因此使用的是语音系统的 .NET 接口。 据我所知,.NET 接口仅明确支持 W3C SRGS XML 语法格式,
http://www.w3.org/TR/speech-grammar/。 虽然您链接到的语法格式是 MS 特定格式,他们似乎将其称为 CFG。 只有较低层的 COM API 提供了 CFG 格式的详细信息。

您应该能够在 SRGS 中执行与 CFG 中相同的操作。

使用 SDK 工具编译 CFG 后,您也许能够加载 CFG 的二进制版本。

You appear to be using c#, and therefore the .NET interface to the speech system. As far as I can tell the .NET interface only explicitly supports the W3C SRGS XML grammar format,
http://www.w3.org/TR/speech-grammar/. While the grammar format you link to is an MS specific format, which they seem to call CFG. Only the lowerlevel COM API gives details of the CFG format.

You should be able to do the same things in SRGS as in CFG.

You may be able to load the binary version of CFG after compiling it using the SDK tools.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文