首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SAPI语音识别delphi

SAPI语音识别delphi
EN

Stack Overflow用户
提问于 2010-05-17 01:28:03
回答 2查看 3.8K关注 0票数 1

我需要用delphi语言创建一个程序上的等价物。或者有人可以发布一个链接,说明如何使用delphi在peech识别中使用语法。或在Delphi中具有编程等效的XML语法的任何示例。对不起我的英语。

代码语言:javascript
复制
**Programmatic Equivalent ** 

参考文献:http://msdn.microsoft.com/en-us/library/ms723634(v=VS.85).aspx

代码语言:javascript
复制
        SPSTATEHANDLE hsHelloWorld;
        hr = cpRecoGrammar->GetRule(L"HelloWorld", NULL,
                        SPRAF_TopLevel | SPRAF_Active, TRUE,
                        &hsHelloWorld);
        hr = cpRecoGrammar->AddWordTransition(hsHelloWorld, NULL,
                L"hello world", L" ",
                SPWT_LEXICAL, NULL, NULL);
        hr = cpRecoGrammar->AddWordTransition(hsHelloWorld, NULL,
                L"hiya|there", L"|",
                SPWT_LEXICAL, NULL, NULL);
        hr = cpRecoGrammar->Commit(NULL);

XML语法示例:

代码语言:javascript
复制
    <GRAMMAR>
        <!-- Create a simple "hello world" rule -->
        <RULE NAME="HelloWorld" TOPLEVEL="ACTIVE">
            <P>hello world</P>
        </RULE>
        <RULE NAME="HelloWorld_Disp" TOPLEVEL="ACTIVE">
            <P DISP="Hiya there!">hello world</P>
        </RULE>
        <RULE NAME="Question_Pron" TOPLEVEL="ACTIVE">
            <P DISP="I don't understand" PRON="eh">what</P>
        </RULE>
        <RULE NAME="NurseryRhyme" TOPLEVEL="ACTIVE">
            <P>hey</P>
            <P MIN="2" MAX="2">diddle</P>
        </RULE>
        <RULE NAME="UseWeights" TOPLEVEL="ACTIVE">
            <LIST>
                <P WEIGHT=".95">recognize speech</P>
                <P WEIGHT=".05">wreck a nice beach</P>
            </LIST>
        </RULE>
        <RULE NAME="UseProps" TOPLEVEL="ACTIVE">
            <P PROPNAME="NOVALUE">one</P>
            <P PROPNAME="NUMBER" VAL="2">two</P>
            <P PROPNAME="STRING" VALSTR="three">three</P>
        </RULE>
    </GRAMMAR>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-05-28 01:22:59

Guy‘我终于能得到答案了.

这可能对其他人有用..。:)

这是我创建的实际组件。只需根据你的需要修改它。

代码语言:javascript
复制
Function TSRRule.AddWord (Word : String; Value : string = ''; Separator : char = '|') : integer;
var
  OleValue : OleVariant;
begin
  result := 0;
  if Fwordlist.IndexOf(Word) = -1 then
     begin
       OleValue := Value;
       Fwordlist.Add(Word);
       FRule.InitialState.AddWordTransition(nil,  word, Separator, SPWT_LEXICAL, FRuleName+'_value',Fwordlist.Count, OleValue, 1.0);
       FWordCount := Fwordlist.Count;
       result := FWordCount;
     end;
end;

调用函数.

代码语言:javascript
复制
FSpRunTimeGrammar := SpInProcRecoContext.CreateGrammar(2); // we assign  another grammr on index 2

   SrRule1 := TSRRule.Create(1,'Rule1',FSpRunTimeGrammar);
   with SrRule1 do
      begin
         AddWord('Maxtor');
         AddWord('Open NotePad','Notepad.exe');
         AddWord('Maxtor Dexter TrandPack','',' ');
         commit;
      end;
   SrRule2 := TSRRule.Create(2,'Rule2',FSpRunTimeGrammar);
   with SrRule1 do
      begin
         AddWord('the box');
         AddWord('WeLcOmE SaPi');
         AddWord('Halo World');
         commit;
      end;
   FSpRunTimeGrammar.CmdSetRuleState('Rule1',SGDSActive);
   FSpRunTimeGrammar.CmdSetRuleState('Rule2',SGDSActive);

请留下评论以便澄清..。祝好运!

票数 1
EN

Stack Overflow用户

发布于 2010-05-17 02:01:14

绝地团队所做的语音api有一个直接的包装器,你应该可以从这里找到http://www.delphi-jedi.org/apilibrary.html的代码,但是我刚刚检查过了,指向sapi.zip文件的链接似乎被破坏了,也许给绝地小队的一封电子邮件会帮你打开。

如果您确实掌握了包装器,并且考虑到这是API的直接包装,那么MDSN文档就是您想要的,只需将C++语法替换为Delphi语法99%就可以了,这不是,只需在这里(或者在Embarcadero新闻组上)询问具体的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2846222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档