Example #1
0
        public void InterpretCommand(int StreamNumber, object StreamPosition, SpeechLib.SpeechRecognitionType RecognitionType, SpeechLib.ISpeechRecoResult Result)
        {
            //Get zone the command was heard on
            int commandZoneIdx = 0;

            for (int i = 0; i < numZones; i++)
            {
                if (recoContext[i].Equals(Result.RecoContext))
                {
                    commandZoneIdx = i;
                    break;
                }
            }

            //handle the event
            string sCommand = Result.PhraseInfo.GetText(0, -1, true);

            sCommand        = sCommand.ToLower();
            form1.statusMsg = "C2 has recognized a command";
            Console.WriteLine("Received command from " + (commandZoneIdx + 1) + ": " + sCommand);
            switch (state)
            {
            case State.IDLE:
                if (sCommand.Contains("c2") || ((sCommand.Contains("see") || sCommand.Contains('c') || sCommand.Contains("sea")) &&
                                                (sCommand.Contains("too") || sCommand.Contains("two") || sCommand.Contains("to") || sCommand.Contains("2"))))
                {
                    form1.statusMsg = "Awaiting Command:";
                    //voice[commandZoneIdx].ShortAcknowlege();
                    ResetAttentionTimer(30000);     //after 30 seconds it should stip listening

                    //state = State.LISTEN;
                    goto case State.LISTEN;
                    //C2attentionTimer.Start();
                }
                else
                {
                    missunderstandCount++;
                    form1.statusMsg = "C2 is waiting for \"C2\" command only";
                }
                break;

            case State.LISTEN:
                if (sCommand.Contains("emergency") || (sCommand.Contains("activate") && sCommand.Contains("alarm")))
                {
                    form1.statusMsg = "alarm is triggered";
                    voice[commandZoneIdx].Speak("Warning: Alarm has been triggered. Police have been notified and will arrive at the premises shortly.");
                    gpio.AppSetAlarmOn();
                }
                else if ((sCommand.Contains("emergency") || (sCommand.Contains("activate") && sCommand.Contains("alarm"))) && sCommand.Contains("off"))
                {
                    form1.statusMsg = "alarm trigger is off";
                    voice[commandZoneIdx].Speak("Alarming is off");
                    gpio.AppSetAlarmOff();
                }
                else if (sCommand.Contains("light color"))
                {
                    int r, g, b, d, bri;
                    d = 0;
                    if (sCommand.Contains("red"))
                    {
                        r = 255; g = 0; b = 0; bri = 90;
                    }
                    else if (sCommand.Contains("green"))
                    {
                        r = 0; g = 255; b = 0; bri = 90;
                    }
                    else if (sCommand.Contains("blue"))
                    {
                        r = 0; g = 0; b = 255; bri = 90;
                    }
                    else if (sCommand.Contains("purple"))
                    {
                        r = 255; g = 0; b = 255; bri = 90;
                    }
                    else if (sCommand.Contains("default"))
                    {
                        r = 0; g = 0; b = 0; bri = 100; d = 1;
                    }
                    else
                    {
                        r = 0; g = 0; b = 0; bri = 100; d = 1;
                    }
                    int[] location = GetLocation(sCommand);
                    if (location.Length < 1)
                    {
                        location = new int[1] {
                            commandZoneIdx
                        };
                    }
                    form1.statusMsg = "lights changing color in zones idx: " + location.ToString();
                    Console.Write("lights changeing color in zone indexes ");
                    for (int i = 0; i < location.Length; i++)
                    {
                        Console.Write(location[i] + " ");
                    }

                    foreach (int i in location)
                    {
                        if (d == 1)
                        {
                            gpio.AppSetLightColorDefault(i + 1);
                        }
                        else
                        {
                            gpio.AppSetLightColor(i + 1, r, g, b, bri);
                        }
                    }

                    voice[commandZoneIdx].Speak("Color set");

                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("good morning"))
                {
                    form1.statusMsg = "good morning";
                    voice[commandZoneIdx].Speak("Good Morning, how are you today?");
                    //ExecuteCommand("test.txt");
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("how are you"))
                {
                    form1.statusMsg = "I'm fine";
                    voice[commandZoneIdx].HowAreYou();
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("song"))
                {
                    form1.statusMsg = "sing";
                    voice[commandZoneIdx].Speak("Twinkle, Twinkle, little star. How I wonder what you are? Up above the world so high, like a diamond in the sky. Twinkle, Twinkle, little star. How I wonder what you are?");
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("lights") && sCommand.Contains(" on ") && (sCommand.Contains("motion") || sCommand.Contains("occupied")))
                {
                    for (int i = 0; i < numZones; i++)
                    {
                        lightsOccupied[i] = true;
                    }
                    voice[commandZoneIdx].Speak("Lights are now motion activated");
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("lights") && sCommand.Contains("off") && (sCommand.Contains("motion") || sCommand.Contains("occupied")))
                {
                    for (int i = 0; i < numZones; i++)
                    {
                        lightsOccupied[i] = false;
                    }
                    voice[commandZoneIdx].Speak("Lights are no longer motion activated");
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("lights") && sCommand.Contains("on"))
                {
                    int[] location = GetLocation(sCommand);
                    if (location.Length < 1)
                    {
                        location = new int[1] {
                            commandZoneIdx
                        };
                    }
                    form1.statusMsg = "lights going on in zone indexes " + location.ToString();
                    Console.Write("lights going on in zone indexes ");
                    for (int i = 0; i < location.Length; i++)
                    {
                        Console.Write(location[i] + " ");
                    }

                    foreach (int i in location)
                    {
                        gpio.setGpioValue(zoneAddresses[i], 25, 1);
                    }

                    voice[commandZoneIdx].Speak("Lights On");

                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("lights") && sCommand.Contains("off"))
                {
                    int[] location = GetLocation(sCommand);
                    if (location.Length < 1)
                    {
                        location = new int[1] {
                            commandZoneIdx
                        };
                    }

                    form1.statusMsg = "lights going off in zone index " + location.ToString();
                    Console.Write("lights going off in zone indexes ");
                    for (int i = 0; i < location.Length; i++)
                    {
                        Console.Write(location[i] + " ");
                    }
                    foreach (int i in location)
                    {
                        gpio.setGpioValue(zoneAddresses[i], 25, 0);
                    }

                    voice[commandZoneIdx].Speak("Lights Off");
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("security") && (sCommand.Contains("arm") || sCommand.Contains("activate")))
                {
                    voice[commandZoneIdx].Speak("Please enter code to arm security system.");
                    missunderstandCount = 0;
                    state = State.ALARM_CODE;
                    //TODO: how to enter code?
                }
                else
                {
                    if (state == State.IDLE)     //meaning that we got into here from goto from C2 recognized phrase (no other command in phrase)
                    {
                        state = State.LISTEN;
                        voice[commandZoneIdx].ShortAcknowlege();
                    }
                    else
                    {
                        missunderstandCount++;
                    }
                    form1.statusMsg = "C2 has recognized a command no comprendo";
                }
                break;

            default:
                form1.statusMsg = "C2 is in BAD STATE";
                break;
            }
        }
Example #2
0
        public void InterpretCommand(int StreamNumber, object StreamPosition, SpeechLib.SpeechRecognitionType RecognitionType, SpeechLib.ISpeechRecoResult Result)
        {
            //handle the event
            string sCommand = Result.PhraseInfo.GetText(0, -1, true);

            sCommand        = sCommand.ToLower();
            form1.statusMsg = "C2 has recognized a command";
            switch (state)
            {
            case State.IDLE:
                if (sCommand.Contains("c2") || ((sCommand.Contains("see") || sCommand.Contains('c') || sCommand.Contains("sea")) &&
                                                (sCommand.Contains("too") || sCommand.Contains("two") || sCommand.Contains("to") || sCommand.Contains("2"))))
                {
                    form1.statusMsg = "Awaiting Command:";
                    voice.ShortAcknowlege();

                    state = State.LISTEN;
                    //C2attentionTimer.Start();
                }
                else
                {
                    missunderstandCount++;
                    form1.statusMsg = "C2 is waiting for \"C2\" command only";
                }
                break;

            case State.LISTEN:
                if (sCommand.Contains("good morning"))
                {
                    form1.statusMsg = "good morning";
                    voice.Speak("Good Morning, how are you today?");
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("lights") && sCommand.Contains("on"))
                {
                    form1.statusMsg = "lights going on";
                    voice.Speak("Lights On");
                    gpio.setGpioValue("192.168.113.101", 25, 1);
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else if (sCommand.Contains("lights") && sCommand.Contains("off"))
                {
                    form1.statusMsg = "lights going off";
                    voice.Speak("Lights Off");
                    gpio.setGpioValue("192.168.113.101", 25, 0);
                    missunderstandCount = 0;
                    state = State.IDLE;
                }
                else
                {
                    missunderstandCount++;
                    form1.statusMsg = "C2 has recognized a command no comprendo";
                }
                break;

            default:
                form1.statusMsg = "C2 is in BAD STATE";
                break;
            }
        }
 private void ContexRecognition(int iIndex, object obj, SpeechLib.SpeechRecognitionType type, SpeechLib.ISpeechRecoResult result)
 {
     textBox1.Text = result.PhraseInfo.GetText(0, -1, true);
 }
Example #4
0
 private void ContexRecognition(int iIndex, object obj, SpeechLib.SpeechRecognitionType type, SpeechLib.ISpeechRecoResult result)
 {
     if (SetMessage != null)
     {
         SetMessage(result.PhraseInfo.GetText(0, -1, true));
     }
 }