0

when a button is pressed i need to add(append) more grammars to the speech recognition at run time--

recog = New SpeechRecognitionEngine()
recog.SetInputToDefaultAudioDevice()
recog.RecognizeAsyncStop()
recog.UnloadAllGrammars()

Dim commandChoices As New Choices("wordpad", "notepad", "word")
Dim grammarBuilder As New GrammarBuilder(New Choices("open", "close", "Hello"))
grammarBuilder.Append(commandChoices)
Dim commandChoices1 As New Choices("google", "facebook", "yahoo", "apple")
Dim grammarBuilder1 As New GrammarBuilder(New Choices("goto"))
grammarBuilder1.Append(commandChoices1)
Dim grammarbuilder2 As New GrammarBuilder(New Choices("Calculator", "TaskManager", "MyComputer", "CommandPrompt", "C-Panel", "D-Drive", "C-Drive"))
Dim g As New Grammar(New Choices(grammarBuilder, grammarBuilder1, grammarbuilder2))
g.Name = "Available programs"
recog.LoadGrammarAsync(g)
recog.RecognizeAsync(RecognizeMode.Multiple)

AddHandler recog.AudioLevelUpdated, AddressOf Me.auevent
AddHandler recog.SpeechRecognized, AddressOf Me.recevent
AddHandler recog.SpeechRecognitionRejected, AddressOf Me.recfailevent

'My goal to achieve'

if a Button is pressed

add/append "paint" to the commandchoices at runtime. Please Help

3
  • Add a new GrammarBuilder, give or take as you're doing now, then call recog.RequestRecognizerUpdate() before recog.LoadGrammarAsync(g). You have to declare your Grammar as an instance Field (or use a custom manager class) if you have to add more strings to it somewhere else.
    – Jimi
    Oct 6 '19 at 16:39
  • can you give a sample code for me??
    – Ebixon
    Oct 7 '19 at 14:39
  • i've declared all of the above code in form load event
    – Ebixon
    Oct 7 '19 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.