SAPI语音识别德尔福 [英] SAPI Speech recognition delphi

查看:86
本文介绍了SAPI语音识别德尔福的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Delphi语言创建一个程序化等效项...或者有人可以发布有关如何使用Delphi在语音识别中执行语法的链接。或在Delphi中具有程序等效的XML语法的任何示例。抱歉,我的英语。

I to need create a programmatic equivalent using delphi language... or could someone post a link on how to do grammars in peech recogniton using the delphi. Or any examples of XML grammar that has programmatic equivalent in Delphi. sorry for my english.

**Programmatic Equivalent ** 

参考: http://msdn.microsoft.com/zh-cn/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>


推荐答案

我终于可以得到答案了....

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


这是我创建的实际组件。

Guy's I finally able to get the Answer ....
This might be useful to others... :)

this is the actual component that i created. just modify it for your needs.

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

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

Please Leave comment for clarifications.... good luck!

这篇关于SAPI语音识别德尔福的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆