2010-05-17 162 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