Click here to Skip to main content
15,917,645 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionEmbeding flash player in Windows application Pin
pavya_Cool31-Jul-08 19:21
pavya_Cool31-Jul-08 19:21 
AnswerRe: Embeding flash player in Windows application Pin
Thomas Stockwell1-Aug-08 2:33
professionalThomas Stockwell1-Aug-08 2:33 
GeneralRe: Embeding flash player in Windows application Pin
pavya_Cool1-Aug-08 3:36
pavya_Cool1-Aug-08 3:36 
Questionelapsed time calculation b/w two click events Pin
chandrubngit31-Jul-08 16:00
chandrubngit31-Jul-08 16:00 
AnswerRe: elapsed time calculation b/w two click events Pin
AhsanS31-Jul-08 18:24
AhsanS31-Jul-08 18:24 
AnswerRe: elapsed time calculation b/w two click events Pin
Sam Xavier31-Jul-08 18:34
Sam Xavier31-Jul-08 18:34 
AnswerRe: elapsed time calculation b/w two click events Pin
Guffa31-Jul-08 22:31
Guffa31-Jul-08 22:31 
QuestionVoice Command using SAPI 5.1 [modified] Pin
cw342cw31-Jul-08 8:31
cw342cw31-Jul-08 8:31 
* I need help in learning how to set grammar in SAPI 5.1 to perform Voice command

The code I have is able to do dictation, now I just wanted to expand to do voice command with a preset XML grammar.

Please help up

Sample code will helps too. - boyzwong@gmail.com

Thank you


'Default Imports
Imports System
Imports System.Data
Imports System.Deployment
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Xml
Imports SpeechLib.SpeechGrammarWordType

'Custom Imports
Imports SpeechLib

Public Class Form1
    'Declares

    Dim WithEvents RecoContext As SpSharedRecoContext       'The Main Recognition Object Used throughout the whole program. -- Shared Object: More Info on this later.
    Dim Grammar As ISpeechRecoGrammar                       'The Grammar Object so the program knows what is going on. -- Instanced Object: More Info on this later.
    Dim CharCount As Integer                                'This is used to count the amount of chars that are in the text box.



    ''''Subs Start Here
    'Start Button. This will engage reco, and start the entire process.
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        
        
        If (RecoContext Is Nothing) Then

            RecoContext = New SpSharedRecoContextClass          'Create a new Reco Context Class
            Grammar = RecoContext.CreateGrammar             'Setup the Grammar
            'Grammar.DictationLoad()                             'Load the Grammar
            Grammar.CmdLoadFromFile("c:\gram.xml", SpeechLib.SpeechLoadOption.SLODynamic)

        End If

        lblstatus.Text = "Recognition Started"                  'Change the Label to let the user know whats up
        Grammar.DictationSetState(SpeechRuleState.SGDSActive)   'Turns on the Recognition. This is Vitally important

        'This is so the user doesn't break the program by 
        'trying to start the recognition after its already started.
        btnstart.Enabled = False
        btnstop.Enabled = True
    End Sub



    'Stop Button. This will stop stop the recoginition
    Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click

        Grammar.DictationSetState(SpeechRuleState.SGDSInactive) 'Turns off the Recognition. It will go dormant.
        lblStatus.Text = "Recognition Stopped"                  'Change the label to let the user know whats up

        'Again This is so the user doesn't go breaking things accidently
        btnStart.Enabled = True
        btnStop.Enabled = False
    End Sub



    'This is the hypothesis sub. The hypothesis is not the final recognition. This will fire many times per word. You do not want to print anything that is final from the hypothesis.
    'This is not required for the final recognition. But it is vital to understand it.
    Private Sub OnHypo(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal Result As ISpeechRecoResult) Handles RecoContext.Hypothesis

        btnStop.Enabled = False    'Don't allow the user to stop the recognition until it has completed.
        'The button will re-enable in the OnReco Event

        'This is so you don't kepp printing the same text over and over. It could take up just a tiny bit more processor power
        'Its good to not do un-needed things.
        If lblStatus.Text <> "Receiving" Then
            lblStatus.Text = "Receiving"
        End If
    End Sub

    'This sub is fired when the reco engine detects a set of words. This is what you want to use to print or sendkey.
    'Use this sub for the final printing of words.
    Private Sub OnReco(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult) Handles RecoContext.Recognition

        Dim recoResult As String = Result.PhraseInfo.GetText 'Create a new string, and assign the recognized text to it.

        'This block will print to the textbox built into the program
        'If you would prefer to use the SendKeys method, Comment out this entire block. And Uncomment the SendKeys Line.
        txtBox.SelectionStart = CharCount
        txtBox.SelectedText = recoResult & " "
        CharCount = CharCount + 1 + Len(recoResult)
        If txtbox.Text.Contains("testing") Then
            Beep()
        End If
        'Uncomment the next line if you want to send the text to the selected window rather than constrain it to the textbox.
        'SendKeys.Send(recoResult & " ") 'This line sends the result via SendKeys to the top window.

        lblStatus.Text = "Finished Dictating"
        btnStop.Enabled = True
    End Sub

End Class




XML
<!-- Language ID = British English -->
<GRAMMAR LANGID="413" LEXDELIMITER="|" WORDTYPE="LEXICAL">
  <RULE NAME="HelloWorld" TOPLEVEL="ACTIVE">
    <!-- when the user says the following pronunciation, "Hiya" will be displayed -->
    <P>Hello World</P>
  </RULE>
</GRAMMAR>


modified on Thursday, July 31, 2008 5:57 PM

AnswerRe: Voice Command using SAPI 5.1 Pin
Paul Conrad2-Aug-08 18:58
professionalPaul Conrad2-Aug-08 18:58 
QuestionHow to assign image to a unknown control Pin
AR Reddy31-Jul-08 5:28
AR Reddy31-Jul-08 5:28 
AnswerRe: How to assign image to a unknown control Pin
Thomas Stockwell31-Jul-08 6:35
professionalThomas Stockwell31-Jul-08 6:35 
GeneralRe: How to assign image to a unknown control Pin
AR Reddy31-Jul-08 6:40
AR Reddy31-Jul-08 6:40 
GeneralRe: How to assign image to a unknown control Pin
Thomas Stockwell31-Jul-08 6:42
professionalThomas Stockwell31-Jul-08 6:42 
GeneralRe: How to assign image to a unknown control Pin
AR Reddy31-Jul-08 6:56
AR Reddy31-Jul-08 6:56 
AnswerRe: How to assign image to a unknown control Pin
Gregory Gadow31-Jul-08 6:42
Gregory Gadow31-Jul-08 6:42 
GeneralRe: How to assign image to a unknown control Pin
Thomas Stockwell31-Jul-08 7:01
professionalThomas Stockwell31-Jul-08 7:01 
JokeRe: How to assign image to a unknown control Pin
Gregory Gadow31-Jul-08 7:18
Gregory Gadow31-Jul-08 7:18 
QuestionShowing 2 digits inc zeros after decimal point (VBA XL) Pin
Dalek Dave31-Jul-08 4:52
professionalDalek Dave31-Jul-08 4:52 
AnswerRe: Showing 2 digits inc zeros after decimal point (VBA XL) Pin
Tim Carmichael31-Jul-08 7:35
Tim Carmichael31-Jul-08 7:35 
GeneralRe: Showing 2 digits inc zeros after decimal point (VBA XL) Pin
Dalek Dave31-Jul-08 22:16
professionalDalek Dave31-Jul-08 22:16 
QuestionRename assembly? Pin
cstrader23231-Jul-08 4:22
cstrader23231-Jul-08 4:22 
AnswerRe: Rename assembly? Pin
Thomas Stockwell31-Jul-08 6:37
professionalThomas Stockwell31-Jul-08 6:37 
GeneralRe: Rename assembly? Pin
cstrader23231-Jul-08 8:04
cstrader23231-Jul-08 8:04 
QuestionList Box / Combo Box Pin
Riaz Ahmed31-Jul-08 3:55
Riaz Ahmed31-Jul-08 3:55 
AnswerRe: List Box / Combo Box Pin
Ajay.k_Singh31-Jul-08 4:37
Ajay.k_Singh31-Jul-08 4:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.