none
Speech recognition Nested Cases RRS feed

  • Question

  • My goal is to about cases.

    i want other cases to work only if the first cases statement is satisfied 

    And  i don't know what to do about declaring another variable for .result.text.toupper

    please help

    Imports System.Speech
    Imports System.Speech.Recognition
    Imports System.Speech.Recognition.SrgsGrammar
    Imports System.Runtime.InteropServices
    Imports System.Reflection

    Public Class Form1

        Dim synth As New Synthesis.SpeechSynthesizer

        Dim WithEvents reco As New Recognition.SpeechRecognitionEngine
        Dim QuestionEvent As String


        

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal x As System.EventArgs) Handles MyBase.Load



            reco.SetInputToDefaultAudioDevice()


            Dim gram As New GrammarBuilder()
            gram.Append(New Choices(System.IO.File.ReadAllLines("loob.txt")))


            reco.LoadGrammar(New Recognition.Grammar(gram))
            reco.RecognizeAsync()





        End Sub




        Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal x As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted

            reco.RecognizeAsync()


        End Sub




        Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal x As System.Speech.Recognition.SpeechRecognizedEventArgs) Handles reco.SpeechRecognized







            Select Case x.Result.Text.ToUpper


                Case Is = "WAKE UP JARVIS"



                    Select Case x.Result.Text.ToUpper
                        Case Is = "HEY JARVIS", "HELLO JARVIS"
                            synth.Speak("HELLO MASTER")


                    End Select


            End Select



        End Sub






    End Class


    Saturday, May 6, 2017 9:14 AM

All replies

  • Hello Stark,

    If you have a problem like yours then do what we do as well. 

    Create a small program which contains the problem. Mostly you can in that way find  the solution for your problem.

    Also you are then able to ask others how the problem can be solved by showing that small program.

    If you don't then find it yourself you can ask a Question here in the forum.

    You can then copy and paste the code by using the button in <> which is above the text which you are then typing.

    Now your code contains to much variables which we don't have so helping you is in fact senseless,


    Success
    Cor


    Saturday, May 6, 2017 10:09 AM
  • dude i edit it now for a simplier program. please help me. i'm stuck on it right now. thanks in advance
    Saturday, May 6, 2017 2:43 PM
  • If I run it, it tells direct is needs a file. 

    Make something that the file is not needed. 

    However, your code is now that in the Case the name is "Whatever" there is tested if the name is "WhatElse".

    No that never goes. 


    Success
    Cor

    Saturday, May 6, 2017 4:11 PM
  • make a txt file named loob.txt

    put it in the file in your projects. name/bin/debug

    Saturday, May 6, 2017 4:38 PM
  • dude where are you?

    Saturday, May 6, 2017 4:44 PM
  • dude
    Saturday, May 6, 2017 4:52 PM

  • Success
    Cor

    Saturday, May 6, 2017 5:08 PM
  • any facebook account? so we can talk better
    Saturday, May 6, 2017 5:26 PM
  • PUT WORDS THERE. LIKE THIS

    HELLO JARVIS
    WAKE UP JARVIS


    Saturday, May 6, 2017 5:30 PM
  • put it in txt
    Saturday, May 6, 2017 5:39 PM
  • I did it, but the event did never happen. 

    You should make your sample in a way it runs. 

    Now the Case Select is never reached.

    Be aware that I've no intention to make your program. I'm not in the mood for that.  


    Success
    Cor


    Saturday, May 6, 2017 7:48 PM
  • sorry dude just got depressed and so desperate  last night. 

    thanks on your advice and time :)

    Sunday, May 7, 2017 12:39 AM
  • i want other cases to work only if the first cases statement is satisfied 

    The code you have won't work because one variable cannot have two different values.

    Select Case x.Result.Text.ToUpper
        Case Is = "WAKE UP JARVIS"
            Select Case x.Result.Text.ToUpper
                 Case Is = "HEY JARVIS", "HELLO JARVIS"
                     synth.Speak("HELLO MASTER")
    

    In this case x.result.text.toupper cannot be "WAKE UP JARVIS" at the same time as it is "HEY JARVIS" so that the speak statement would never be executed.

    What you need is a static variable, so you know what the previous message was.  Then use that variable to determine which phrase was the previous one, and select the correct case statement for that phrase.  Something like this:

    Static State as Integer = 0 Select Case State Case Is 0 ' No current conversation Select Case x.Result.Text.ToUpper Case Is = "WAKE UP JARVIS" State = 1
    ... Case Else State = 0 End Select Case Is 1 ' Previous phrase must have been "WAKE UP JARVIS" Select Case x.Result.Text.ToUpper Case Is = "HEY JARVIS", "HELLO JARVIS" synth.Speak("HELLO MASTER") State = 0 'End of conversation ... Case Else State = 0 End Select End Select

    Sunday, May 7, 2017 2:24 AM
  • thanks a lot bro. your a life saver :D
    Tuesday, May 9, 2017 4:36 AM
  • Hi Stark122233,

    Please remember to close your thread by marking helpful answer, it is very beneficial to the other communities who face the same issue.

    If you still have issue, please share your entire sample that can reproduce this issue here, it is very helpful to us to analyze your issue.

    Thanks for your understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 18, 2017 7:31 AM
    Moderator