Ejemplo n.º 1
0
 public void StopRecording()
 {
     _speechRecognition.StopRecord();
     recordingEndedDelegate();
     Debug.Log("Recording stopped.");
 }
Ejemplo n.º 2
0
        private void InsertRecognitionResponseInfo(RecognitionResponse recognitionResponse)
        {
            if (recognitionResponse == null || recognitionResponse.results.Length == 0)
            {
                _resultText.text = "\nWords not detected. Try again";
                //	_startRecordButton.interactable = true;
                //	_startRecordButton.image.sprite = Mike_white;

                //	_speechRecognition.StopRecord();
                return;
            }

            _resultText.text = "You said: " + recognitionResponse.results[0].alternatives[0].transcript + "'";

            var words = recognitionResponse.results[0].alternatives[0].words;

            if (words != null)
            {
                string times = string.Empty;
                string phrase, today;
                actionType      = "";
                seasonParameter = "";
                weatherDate     = DateTime.Now;             // dont know how to reset this!!!



                string[] dayofWeek = { "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" };

                foreach (var item in recognitionResponse.results[0].alternatives[0].words)
                {
                    //times += "<color=green>" + item.word+ "\n";// + "</color> -  start: " + item.startTime + "; end: " + item.endTime + "\n";

                    phrase = item.word;
                    phrase = phrase.ToLower();
                    //_resultText.text += "\n" + phrase;
                    if (phrase.Contains("today") || phrase.Contains("tomorrow") || phrase.Contains("sunday") || phrase.Contains("monday") || phrase.Contains("tuesday") || phrase.Contains("wednesday") || phrase.Contains("thursday") || phrase.Contains("friday") || phrase.Contains("saturday"))
                    {
                        actionType = "weather";

                        if (phrase.Contains("today"))
                        {
                            phrase      = "today";
                            weatherDate = DateTime.Now;
                        }
                        else if (phrase.Contains("tomorrow"))
                        {
                            phrase      = "tomorrow";
                            weatherDate = DateTime.Now.AddDays(1);
                        }

                        else
                        {
                            today  = DateTime.Now.DayOfWeek.ToString();
                            today  = today.ToLower();
                            phrase = phrase.Replace("?", String.Empty).Replace("'s", String.Empty).Replace(".", String.Empty).Replace(",", String.Empty);
                            phrase = phrase.ToLower();

                            int index1     = Array.IndexOf(dayofWeek, phrase);
                            int indexToday = Array.IndexOf(dayofWeek, today);
                            //_resultText.text += "\n index 1=" + index1 + "indexToday=" + indexToday + "today is: " + today;

                            if (index1 > indexToday)
                            {
                                weatherDate = DateTime.Now.AddDays(index1 - indexToday);
                            }
                            else if (index1 < indexToday)
                            {
                                weatherDate = DateTime.Now.AddDays(index1 - indexToday + 7);
                            }                                                                                                                          // if its a earlier day than today, calculate the next week's same day
                            else
                            {
                                weatherDate = DateTime.Now;
                            }
                        }
                    }
                    else if (phrase.Contains("summer") || phrase.Contains("autumn") || phrase.Contains("spring") || phrase.Contains("sun") || phrase.Contains("sunny") || phrase.Contains("winter"))
                    {
                        phrase = phrase.Replace("?", String.Empty).Replace("'s", String.Empty).Replace(".", String.Empty).Replace(",", String.Empty);
                        phrase = phrase.ToLower();

                        actionType      = "season";
                        seasonParameter = phrase;
                    }
                }

                // step 1 - Call getWeather(DateTime wdate) APIs to get weather status (return object would have a seasons parameter)
                // step 2 - call video player to change "showWeather" showWeather(string actionType, string seasonParameter)

                /*		times += "ActionType = " + actionType + "\n"
                 + "seasonParameter = " + seasonParameter + "\n"
                 + "weatherDate = " + weatherDate + "\n";
                 +
                 +              _resultText.text += "\n" + times;
                 */
                //call this only if actionType=season, else call katerina's script
                if (actionType == "season")
                {
                    getSeason(seasonParameter);
                }
                else if (actionType == "weather")
                {
                    getWeather(weatherDate);
                }
                else
                {
                    _resultText.text += "\n Ask for e.g what's the weather tomorrow";
                }
            }

            _startRecordButton.interactable = true;
            _startRecordButton.image.sprite = Mike_white;

            _speechRecognition.StopRecord();
            actionType      = "";
            seasonParameter = "";
        }
 private void StopRecordButtonOnClickHandler()
 {
     _speechRecognitionState.color = Color.yellow;
     _speechRecognition.StopRecord();
 }