Esempio n. 1
0
    void Start()
    {
        m_DictationRecognizer = new DictationRecognizer();

        m_DictationRecognizer.DictationResult += (text, confidence) =>
        {
            Debug.LogFormat("Dictation result: {0}", text);
            try
            {
                m_Recognitions.text += text + "\n";
            }
            catch
            {
                Debug.Log("Problems, problems, problems");
            }

            string best_match = "";
            foreach (string word in text.Split(new char[] { ' ' }))
            {
                string correctWord = word[0].ToString().ToUpper() + word.Substring(1);
                if (key_words.Contains(correctWord) && correctWord.Length > best_match.Length)
                {
                    best_match = correctWord;
                }
                else if (new string[] { "Place", "Cancel", "Rotate", "Move", "Destroy", "Email" }.Contains(correctWord))
                {
                    gameHandler.Command(correctWord);
                }
            }

            Debug.Log(best_match);
            if (best_match.Length > 0)
            {
                foreach (KeyValuePair <string, Dictionary <string, string> > entry in storageHolder.items)
                {
                    if (entry.Key.Contains(best_match))
                    {
                        gameHandler.newSelection(entry.Key);
                        break;
                    }
                }
            }
        };

        m_DictationRecognizer.DictationHypothesis += (text) =>
        {
            //Debug.LogFormat("Dictation hypothesis: {0}", text);
            try
            {
                m_Hypotheses.text += text;
            }
            catch
            {
                Debug.Log("Problems taking place");
            }
        };

        m_DictationRecognizer.DictationComplete += (completionCause) =>
        {
            // if (completionCause != DictationCompletionCause.Complete)
            //Debug.LogErrorFormat("Dictation completed unsuccessfully: {0}.", completionCause);
        };

        m_DictationRecognizer.DictationError += (error, hresult) =>
        {
            //Debug.LogErrorFormat("Dictation error: {0}; HResult = {1}.", error, hresult);
        };

        m_DictationRecognizer.Start();
    }