none
Sound Command that can intercept the Active Thread RRS feed

  • Question

  • Good Day all  

    In my Kinect Project , the User can use Kinect Gestures  or Voice Commands. The Gestures work nicely its like one is using a mouse. i have a challenge with the Voice Commands which follow a certain Process. Please note that this functionality works well when one is not using voice commands.  

    Let me make a simple example. 

    i have a 3 Buttons 

    Button 1  = "System Ok " 

    Button 2  = " View Error" 

    Button 3  = "System Reboot" 

    Step 1: Now the logic say , if a user enter a wrong command , the System must play a sound for Error and the button for " View Error"  must Animate. 

    Step 2: The Rule goes on and say if the User has not click the " View Error"  within 5 seconds , Stop the Animation on the " View Error"

    Step 3:  and Animate the "System Reboot"  and play the Sound for "System Reboot" 

    Now on a normal button click with a Mouse , this would work. But now i am not clicking the Button Physically, i am using Voice Commands and i have trapped the SpeechRecognized event which is defined like this 

     private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
            {
                // Speech utterance confidence below which we treat speech as if it hadn't been heard
                const double ConfidenceThreshold = 0.3;
    
                // Number of degrees in a right angle.
                const int DegreesInRightAngle = 90;
    
                // Number of pixels turtle should move forwards or backwards each time.
                const int DisplacementAmount = 60;
    
                this.ClearRecognitionHighlights();
    
                if (e.Result.Confidence >= ConfidenceThreshold)
                {
                    switch (e.Result.Semantics.Value.ToString())
                    { 
                      
                        case "VIEWERROR":
                            Error_Escaped = true;
                            btnViewError_Click(null, null); 
                            break;
                        case "SYSTEMREBOOT":
                            btnSystemReboot_Click(null, null);
                            break;
                        case "SYSTEMSTATUS":
                            SystemStatus_Click(null, null); 
                            break; 
                    }
                }
                else
                {
                    // set the status text
                    this.Status.Content = Properties.Resources.GrammarConfidenceLow;
                    Logger.NormalLog("The Confidence is low , the Grammar is not Recognised as a Command", Generics.Generics.ActivePage) ;
                }
            }

    as you can see i am clicking the Buttons programmatically. So if i don't click the "View Error" button within 5 seconds , the System Reboot will start playing another sound.  

    That was about the Process. Now my challenge is that. After i used a wrong option according to my Process, the "View Error" button will give a sound and i will give a Voice Command to Stop the Sound , the next in the Process will still be fired. So i debugged the code and i realised that the Program , runs all the code that was running and when its done, it hit the "SpeechRecognized" event later, i want to intercept and give the Voice Command the same ability as a button click done with a mouse can do. 

    This is a function that runs , when there is an Error  

            private void ViewError()
            {
             
                Error_Escaped = false;
                ResetBlinking(this.btnViewError);
                AnimateButton(this.btnViewError);
                 Generics.Generics.WaitNSeconds(5);
                 if (Error_Escaped == false)
                 {
                     SystemReboot();
                 }
            }

    This will set the Flag for "Error_Escape  = false " Which means no one has clicked the button. and it will Animate the Button and wait for 5 second which is my custom interval calculator. Now while its waiting  i would keep saying some Voice Command to Stop it. it will still continue while i wait , it will jump to System Reboot which will have its sound. i want the 

    SpeechRecognized(object sender, SpeechRecognizedEventArgs e)

    event to fire when i need it not after the other event of buttons are fired. 

    Tanks 


    Vuyiswa Maseko


    Vuyiswa Maseko

    Wednesday, November 16, 2016 4:50 AM

All replies

  • The most important part is missing in your code snippets.

    How is Generics.Generics.WaitNSeconds method implemented

    Wednesday, November 16, 2016 2:47 PM
  • hi Jan 

    here is the definition of the WaitNSecond 

        public static  void WaitNSeconds(int segundos)
             {
                 if (segundos < 1) return;
                 DateTime _desired = DateTime.Now.AddSeconds(segundos);
                 while (DateTime.Now < _desired)
                 {
                     System.Windows.Forms.Application.DoEvents();
                 } 
             }


    Vuyiswa Maseko

    Wednesday, November 16, 2016 5:36 PM
  • reason why it does work when you interact in Windows Forms application UI but doesn't work with Speech recognition-based event is probably based on the dubious implementation of wait function. Application.DoEvents() won't process non UI-pumped events (as SpeechRecognized). If your implementation does not differ from the samples for Speech recognition (e.g. from Kinect SDK), then SpeechRecognized events are being scheduled for Main (UI) thread.

    Most trivial solution would be to implement "delayed evaluation of state" using one of the Timers available in .NET instead of your current approach. 

    Thursday, November 17, 2016 1:53 PM