Example #1
0
    /// <summary>
    /// <c>Recieve Input</c>
    ///
    /// Descriptions: Recieves input from the SpeechToText output.
    ///
    /// preconditions: We must be on a valid node in the tree ui.
    ///
    /// postconditions: The tree ui current node will be updated.
    ///
    /// </summary>
    ///
    /// <param name="input">The input from the stt.</param>
    /// <returns> NULL </returns>
    public void RecieveInput(string input)
    {
        // log our input
        Debug.Log(string.Format("LanguageEngine::RecieveInput: input: '{0}'", input));

        // get options we have at current node.
        List <string> optionsNow = tree.GetCurrentOptions();

        if (optionsNow == null)
        {
            optionsNow = new List <string>();
        }

        // add the options as lower cased
        var options = new List <string>();

        optionsNow.ForEach((opt) =>
        {
            options.Add(opt.ToLower());
        });

        Debug.Log(string.Format("LanguageEngine::RecieveInput: options: '{0}'", string.Join(", ", optionsNow)));

        // now get the decision to make
        int decisionIndex;

        try
        {
            decisionIndex = BestDecision(input.ToLower(), options);
        }
        catch (NoBestDecision e)
        {
            Debug.Log(string.Format("LanguageEngine::RecieveInput: NoBestDecision: {0}", e));

            TTS.RunSpeech("I did not understand that, could you say it differently?");

            return;
        }
        catch (NoOptionsAvailable e)
        {
            Debug.Log(string.Format("LanguageEngine::RecieveInput: NoOptionsAvailable: {0}", e));

            // say a placeholder saying its done
            TTS.RunSpeech("We are finished, thank you.");

            // stop reading s peech
            STT.StopReadingSpeech();

            patientSystem.FinishedTree();
            return;
        }
        catch (InspectorSetupInCorrectly e)
        {
            Debug.Log(string.Format("LanguageEngine::RecieveInput: Two string algorithms choosen!: {0}", e));

            TTS.RunSpeech("I am not set up correctly!");

            return;
        }

        Debug.Assert(decisionIndex >= 0 && decisionIndex < options.Count, "decisionIndex is out of bounds of options");

        // Log our options
        Debug.Log(string.Format("LanguageEngine::RecieveInput: decision: {0}", decisionIndex));

        // With the decision, traverse the tree.
        tree.TakeOption(decisionIndex);

        // if no node then end it.
        if (tree.currentNode == null)
        {
            STT.StopReadingSpeech();

            patientSystem.FinishedTree();

            return;
        }

        // Play the animation, if one exists
        tree.RunAnim();

        // Now say the next prompt
        TTS.RunSpeech(tree.GetCurrentPrompt());

        // check if there are no options left now.
        if (tree.GetCurrentOptions().Count <= 0)
        {
            STT.StopReadingSpeech();

            patientSystem.FinishedTree();
        }
    }