Ejemplo n.º 1
0
        public async Task GetResponse()
        {
            try
            {
                string txt = await SpeechToText.RecordSpeechFromMicrophoneAsync();

                if (txt == "")
                {
                    return;
                }
                await AddNewMessage(MessageData.SENDER_ME, txt);

                string response = await TryGetMessageAsync(txt);

                while (response.Contains("COMMAND"))
                {
                    string[] parts = response.Split('-');

                    try
                    {
                        if (parts[1] != "")
                        {
                            await AddNewMessage(MessageData.SENDER_ASSISTANT, parts[1]);
                        }
                    }
                    catch
                    {
                        Debug.WriteLine("Only has COMMAND");
                    }

                    if (parts[0] == MSG_GETDATA)
                    {
                        //RemoteDataGetter.GetInfoFromRemoteDevice();
                        // DEMO:
                        MainPage.Current.PulseDangerZone = new SolidColorBrush(Colors.MistyRose);

                        if (MainPage.Current.PulseDangerZone != new SolidColorBrush(Colors.White))
                        {
                            parts[0] = MainPage.Current.Pulse < 1010 ? MSG_HYPERTENSION : MSG_HYPOTENSION;
                        }

                        else if (MainPage.Current.Temperature < 32 || MainPage.Current.Temperature > 40)
                        {
                            parts[0] = MainPage.Current.Temperature < 32 ? MSG_LOWTEMPERATURE : MSG_HIGHTEMPERATURE;
                        }
                    }

                    if (parts[0] == MSG_CANCELDIAL)
                    {
                        return;
                    }

                    if (parts[0] == MSG_DIALAMBULANCE)
                    {
                        try
                        {
                            await Dial.CallAsync();
                        }
                        catch
                        { }
                        return;
                    }

                    response = await TryGetMessageAsync(parts[0]);
                }

                await AddNewMessage(MessageData.SENDER_ASSISTANT, response);
            }
            catch
            {
                Debug.WriteLine("I DONT HAVE TIME FOR THIS");
            }


            /*if (!lastSent.Contains("COMMAND"))
             * {
             *  txt         = await SpeechToText.RecordSpeechFromMicrophoneAsync(); //MainPage.Current.TB_DEBUG_INPUT.Text;
             *  lastSent    = txt;
             *
             *  MessageData data = new MessageData()
             *  {
             *      Sender      = MessageData.SENDER_ME,
             *      Received    = DateTime.Now,
             *      Message     = txt
             *  };
             *
             *  MainPage.Current.AiMessages.Add(data);
             *  result = await TryGetMessageAsync(txt);
             * }
             *
             * while (true)
             * {
             *  if (result.Contains("COMMAND"))
             *  {
             *      string[] parts = result.Split('-');
             *
             *      if (parts[1] == MSG_CANCELDIAL)
             *      {
             *          /*RESET TO DEFAULT*/
            /*    return;
             * }
             *
             * if (parts[1] == MSG_DIALAMBULANCE)
             * {
             *  await Dial.CallAsync();
             *  return;
             * }
             *
             * MessageData data = new MessageData()
             * {
             *  Sender      = MessageData.SENDER_ASSISTANT,
             *  Received    = DateTime.Now,
             *  Message     = parts[2]
             * };
             *
             * MainPage.Current.AiMessages.Add(data);
             *
             * await SpeechToText.TextToSpeechAsync(MainPage.Current.element, parts[2]);
             *
             * if (parts[1] == "getData")
             * {
             *  /*TRY TO EVALUATE DATA*/

            /*    parts[1] = MSG_LOWTEMPERATURE;
             * }
             *
             * result = await TryGetMessageAsync(parts[1]);
             * }
             * else
             * {
             * MessageData data = new MessageData()
             * {
             *  Sender      = MessageData.SENDER_ASSISTANT,
             *  Received    = DateTime.Now,
             *  Message     = result
             * };
             *
             * MainPage.Current.AiMessages.Add(data);
             * await SpeechToText.TextToSpeechAsync(MainPage.Current.element, result);
             * }
             * }*/
        }