2010-05-17 219 views
1

我需要创建一个使用delphi语言编程的等价物......或者有人可以发布关于如何使用delphi语言识别语法的链接。或者在Delphi中具有相同编程等级的XML语法的任何示例。对不起我的英语不好。SAPI语音识别delphi

**Programmatic Equivalent ** 

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

 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语法样品(S):

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

回答

1

盖伊的我终于可以得到答案....
这可能是有用的人...... :)

这是我创建的实际组件。只需修改它以满足您的需求。

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; 

调用函数...

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

没有为绝地的团队,你应该做的语音API直接包装能够从这里找到代码http://www.delphi-jedi.org/apilibrary.html但是我刚刚检查并链接到sapi.zip文件似乎被破坏,可能是一封电子邮件到t他绝地球队会为你提供帮助。

如果你确实掌握了包装,并且这是API的直接包装,那么MDSN文档就是你想要的,只需用Delphi语法代替C++语法99%将是直截了当的, T,只是问的具体问题,在这里(或在Embarcadero公司新闻组)

+0

感谢蒂姆先生!我试图替换所有参数。它没有错误。但是两者有不同的结果。我想知道'L'是如何在参数中做的。 {GetRule(L“HelloWorld”....)}我没有把它包含在我的参数中。这是否意味着一个列表? – XBasic3000 2010-05-17 02:51:57

+1

L“Hello World”表示“Hello World”是一个“宽”(或Unicode)字符串。 – 2010-05-17 23:33:39

+0

是的,埃里克的权利。 – 2010-05-18 00:15:50