在 SAPI 5.1 中加载多个语法文件

发布于 2024-08-04 10:30:00 字数 176 浏览 2 评论 0原文

我正在使用 XML 语法文件来开发命令和控制应用程序。由于语法中有大约 4000 个条目,我无法将所有内容都放在一个文件中(当我尝试加载它时会出现错误)。我已经编写了多个 XML 语法文件,但是当我尝试加载多个文件时,它会替换先前加载的文件。也就是说,程序只识别第二个语法文件中的短语。谁能告诉我如何在单个语音识别应用程序中加载多个语法?

I'm using an XML grammar file to develop a Command and Control application. Since there are around 4000 entries in the grammar I can't have it all in one file (it gives an error when I try to load it). I have written multiple XML grammar files, but when I try to load more than one file it replaces the previously loaded file. that is the program only recognizes the phrases in the second grammar file. Can anyone tell me how to load multiple grammars in a single speech recognition application?

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

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

发布评论

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

评论(1

画中仙 2024-08-11 10:30:00

你可以创建多个语法,你必须给它们不同的ID。
这些片段位于 Delphi 中,但您可以改编:

  // init
  FGrammar1 := SpSharedRecoContext1.CreateGrammar(1); // ID 1
  FGrammar1.CmdLoadFromFile('CommandMemo1.xml', SLODynamic);
  FGrammar2 := SpSharedRecoContext1.CreateGrammar(2); // ID 2
  FGrammar2.CmdLoadFromFile('CommandMemo2.xml', SLODynamic);
  // start
  FGrammar1.CmdSetRuleIdState(0, SGDSActive);
  FGrammar2.CmdSetRuleIdState(0, SGDSActive);
...
  // in the onRecognition event, test the grammar Id
  case Result.PhraseInfo.GrammarId of
    1: if SameText(Txt, 'erase memo') then
         Memo1.Text := ''
       else
       if SameText(Txt, 'select memo') then
         Memo1.SelectAll;  
    2: if SameText(Txt, 'copy memo') then
         CopyToClipboard(Memo1.Text)
       else
       if SameText(Txt, 'paste memo') then
         Memo1.Text := PasteFromClipboard;
    else
      raise Exception.Create('bad GrammarId');
  end;

You can create multiple grammar, you have to give them different IDs.
These snippets are in Delphi, but you can adapt:

  // init
  FGrammar1 := SpSharedRecoContext1.CreateGrammar(1); // ID 1
  FGrammar1.CmdLoadFromFile('CommandMemo1.xml', SLODynamic);
  FGrammar2 := SpSharedRecoContext1.CreateGrammar(2); // ID 2
  FGrammar2.CmdLoadFromFile('CommandMemo2.xml', SLODynamic);
  // start
  FGrammar1.CmdSetRuleIdState(0, SGDSActive);
  FGrammar2.CmdSetRuleIdState(0, SGDSActive);
...
  // in the onRecognition event, test the grammar Id
  case Result.PhraseInfo.GrammarId of
    1: if SameText(Txt, 'erase memo') then
         Memo1.Text := ''
       else
       if SameText(Txt, 'select memo') then
         Memo1.SelectAll;  
    2: if SameText(Txt, 'copy memo') then
         CopyToClipboard(Memo1.Text)
       else
       if SameText(Txt, 'paste memo') then
         Memo1.Text := PasteFromClipboard;
    else
      raise Exception.Create('bad GrammarId');
  end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文