title: SAPI Speech recognition delphi
body: <p>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.</p>
  
  <pre><code>**Programmatic Equivalent ** 
  </code></pre>
  
  <p>Ref: <a href="http://msdn.microsoft.com/en-us/library/ms723634(v=VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms723634(v=VS.85).aspx</a></p>
  
  <pre><code>        SPSTATEHANDLE hsHelloWorld;
          hr = cpRecoGrammar-&gt;GetRule(L"HelloWorld", NULL,
                          SPRAF_TopLevel | SPRAF_Active, TRUE,
                          &amp;hsHelloWorld);
          hr = cpRecoGrammar-&gt;AddWordTransition(hsHelloWorld, NULL,
                  L"hello world", L" ",
                  SPWT_LEXICAL, NULL, NULL);
          hr = cpRecoGrammar-&gt;AddWordTransition(hsHelloWorld, NULL,
                  L"hiya|there", L"|",
                  SPWT_LEXICAL, NULL, NULL);
          hr = cpRecoGrammar-&gt;Commit(NULL);
  </code></pre>
  
  <p><strong>XML Grammar Sample(s):</strong></p>
  
  <pre><code>    &lt;GRAMMAR&gt;
          &lt;!-- Create a simple "hello world" rule --&gt;
          &lt;RULE NAME="HelloWorld" TOPLEVEL="ACTIVE"&gt;
              &lt;P&gt;hello world&lt;/P&gt;
          &lt;/RULE&gt;
          &lt;RULE NAME="HelloWorld_Disp" TOPLEVEL="ACTIVE"&gt;
              &lt;P DISP="Hiya there!"&gt;hello world&lt;/P&gt;
          &lt;/RULE&gt;
          &lt;RULE NAME="Question_Pron" TOPLEVEL="ACTIVE"&gt;
              &lt;P DISP="I don't understand" PRON="eh"&gt;what&lt;/P&gt;
          &lt;/RULE&gt;
          &lt;RULE NAME="NurseryRhyme" TOPLEVEL="ACTIVE"&gt;
              &lt;P&gt;hey&lt;/P&gt;
              &lt;P MIN="2" MAX="2"&gt;diddle&lt;/P&gt;
          &lt;/RULE&gt;
          &lt;RULE NAME="UseWeights" TOPLEVEL="ACTIVE"&gt;
              &lt;LIST&gt;
                  &lt;P WEIGHT=".95"&gt;recognize speech&lt;/P&gt;
                  &lt;P WEIGHT=".05"&gt;wreck a nice beach&lt;/P&gt;
              &lt;/LIST&gt;
          &lt;/RULE&gt;
          &lt;RULE NAME="UseProps" TOPLEVEL="ACTIVE"&gt;
              &lt;P PROPNAME="NOVALUE"&gt;one&lt;/P&gt;
              &lt;P PROPNAME="NUMBER" VAL="2"&gt;two&lt;/P&gt;
              &lt;P PROPNAME="STRING" VALSTR="three"&gt;three&lt;/P&gt;
          &lt;/RULE&gt;
      &lt;/GRAMMAR&gt;
  </code></pre>