SAPI语音识别delphi

时间:2010-05-17 01:28:03

标签: delphi speech-recognition sapi voice-recognition

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

**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语法示例:

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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分: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);

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