Exemplo n.º 1
0
    //Method to start the recognizer.
    //Print to console the recognizer is starting, and initalise a new dictationRecognizer.
    //Lambda expressions to perform the various checks.
    public void RecognizerStart()
    {
        print("starting recognizer...");
        dialogueController.playerText.text = "starting recognizer..";

    #if UNITY_STANDALONE_WIN
        dictationRecognizer = new DictationRecognizer();

        //Display the result of the user input.
        // convert the user voice input to text and ensure it is all lower case
        //Run coRoutine to type user input to text box. Visual cue of what they said.
        //Check if the dialogue sequence is not the first sentence, if not, call the displayNextSentence() method.
        dictationRecognizer.DictationResult += (text, confidence) =>
        {
            Debug.LogFormat("Dictation result: {0}", text, confidence);
            dialogueController.txtField.text += text.ToLower();
            StopAllCoroutines();
            StartCoroutine(TypeUserInput(text));
            dialogueController.hasInputTxt = true;
            if (!dialogueController.canStart)
            {
                dialogueController.DisplayNextSentence();
            }
        };

        //Lambda expression to display what the voice recognition system thinks is being said.
        dictationRecognizer.DictationHypothesis += (text) =>
        {
            Debug.LogFormat("Dictation hypothesis: {0}", text);
        };

        //Lamda expression to display if the dictation is completed.
        dictationRecognizer.DictationComplete += (completionCause) =>
        {
            if (completionCause != DictationCompletionCause.Complete)
            {
                Debug.LogErrorFormat("Dictation completed unsuccessfully: {0}.", completionCause);
            }
        };

        //Lambda expression to display if the voice recognition system hits an error. Displays the error.
        dictationRecognizer.DictationError += (error, hresult) =>
        {
            Debug.LogErrorFormat("Dictation error: {0}; HResult = {1}.", error, hresult);
        };

        //Starts the recoginizer
        dictationRecognizer.Start();
    #endif
    }