Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 120,033 times

Contents

Related Categories

Speech Recognition - At last, some code!

John T Yung

At last, some code!

In the Load function of the form input the following code:

Private Sub Form_Load()
  Dim totaldata As String
  'define configuration
  '[Grammer], set language to english (1033)
  '[<Start>], define the words we are looking for
  totaldata = "[Grammar]" & vbCrLf & _
  "langid = 1033" & vbCrLf & _
  "type=cfg" & vbCrLf & _
  "[<Start>]" & vbCrLf & _
  "<start>=Notepad" & vbCrLf & _
  "<start>=Volume" & vbCrLf & _
  "<start>=Media Player" & vbCrLf

  DirectSR1.GrammarFromString (totaldata)
  DirectSR1.Activate

So this is how the string looks. For each line that contains a word, a tag "<start>=" is used to signify a word that follows for the DirectSR to recognize. In the sample code, three words are used, they are Notepad, Volume and Media Player. Guess what? Right, we will use these words for the voice command to load these programs. In addition, the DirectSR1.Activate is used to start the engine to begin recognizing voice commands. DirectSR1.Deactivate is used to stop the engine from recognizing voice commands.

We are almost set. All we have to do is return to the PhraseFinish procedure to parse the command.
From here on is pretty simple, remember that the Phrase parameter is all we need to be concern about. Just put the following code in the PhraseFinish procedure:

Dim sFile As String
Dim noth As Long

Select Case Phrase
Case "Notepad"
    sFile = "\system32\notepad.exe"
    noth = ShellExecute(0, "OPEN", Environ("SystemRoot") & sFile, "", "", 1)
Case "Volume"
    sFile = "\system32\sndvol32.exe"
    noth = ShellExecute(0, "OPEN", Environ("SystemRoot") & sFile, "", "", 1)

Case "Media Player:
    sFile = "C:\Program Files\Windows Media Player\mplayer2.exe"

    noth = ShellExecute(0, "OPEN", sFile, "", "", 1)

End Select

Here is the low down or lodown :). When the DirectSR recognizes a sound, it will process the sound into a word that may closely match the one you provided. If it matches, the Phrase variable will contain the matched word. And lo and behold, the code we use is a Select Case just for the Phrase variable for the words we fed in the engine in the load function. When a match occurs we will use an API function ShellExecute() to load the program.

John Yung is a MCSD Visual Basic programmer base in New York. He works for Webadviso Inc and also does consulting work for companies to develop programs in various areas such as ADO, MSXML, Voice Recognition, User interface design and etc. He develops h

Comments

  • Doubt

    Posted by sandeepravi on 01 Aug 2008

    hi i am Sandeep


     I am doing a project on Speech recognition and my code is quite different from this one mentioned here...i would like to know one ...

  • Re: source code

    Posted by indikasira on 02 Jan 2008


    My Friend if u have that voice reconzing cord... can you please kindly send me that cord to me? i'm indika from sri lanka..
    my email address is indikasampath@gmail.com
    thank you very much

  • Re: [1598] Speech Recognition

    Posted by Sadiqq on 31 Mar 2007


    hi...


  • Re: [1598] Speech Recognition

    Posted by bhupi4u on 16 Mar 2007

    sir please tell me how can i use speech recognition engine tool in visual basic express edition 2005

  • Speech Recognition in vb.net plzz help

    Posted by isha_workholic on 14 Apr 2006

    hello sr, i have been writing u from so many days , actually the problem exist becoz i am making the same project in vb.net , witch take diffrent parameters in phrase_finish function


    can u ...