SAPI语音识别delphi

发布于 2024-09-01 23:03:33 字数 2191 浏览 3 评论 0原文

我需要使用delphi语言创建一个等价的编程...或者有人可以发布一个关于如何使用delphi在语音识别中进行语法的链接。或者任何在 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>

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

Ref: 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 Sample(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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

椵侞 2024-09-08 23:03:33

jedi 团队有一个针对语音 api 的直接包装器,您应该能够从这里找到代码 http://www.delphi-jedi.org/apilibrary.html 但是我刚刚检查过,sapi.zip 文件的链接似乎已损坏,也许发送给 jedi 团队的电子邮件会将其打开为你准备。

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

There is a direct wrapper for the speech api done by the jedi team, you should be able to find the code from here http://www.delphi-jedi.org/apilibrary.html however I just checked and the link to the sapi.zip file seems to be broken, perhaps an email to the jedi team will turn it up for you.

If you do get hold of the wrapper, and given this is direct wrap of the API, then the MDSN docs are what you want, just substitute Delphi syntax for C++ syntax 99% will be straight forward, that which isn't, just ask the specific question in here (or on the Embarcadero newsgroups)

影子的影子 2024-09-08 23:03:33

我终于得到答案了......
这可能对其他人有用...:)

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

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

请发表评论以供说明...祝您好运!

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;

Calling function...

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文