function handleRecognitionResult()

in archived/SpeechRecognitionAndSynthesis/js/js/scenario10_ContinuousRecognitionSRGSGrammar.js [214:303]


    function handleRecognitionResult(result) {
        /// <summary>
        /// Uses the result from the speech recognizer to change the colors of the shapes.
        /// </summary>
        /// <param name="result">The result from the recognition event.</param>

        // Check the confidence level of the recognition result.
        if (result.confidence == Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.high ||
            result.confidence == Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.medium) {

            var semanticsObj = new Object(result.semanticInterpretation);

            // Declare a string that will contain messages when the color rule matches GARBAGE.
            var garbagePrompt = "";

            // BACKGROUND: Check to see if the recognition result contains the semantic key for the background color,
            // and not a match for the GARBAGE rule, and change the color.
            if ("KEY_BACKGROUND" in semanticsObj.properties && semanticsObj.properties["KEY_BACKGROUND"].toString() != "...") {
                var newBackgroundColor = semanticsObj.properties["KEY_BACKGROUND"].toString();
                backgroundColor = getColor(newBackgroundColor);
            }

            // If "background" was matched, but the color rule matched GARBAGE, prompt the user.
            else if ("KEY_BACKGROUND" in semanticsObj.properties && semanticsObj.properties["KEY_BACKGROUND"].toString() == "...") {

                garbagePrompt += "Didn't get the background color \n\nTry saying blue background\n";
                resultTextArea.innerText = garbagePrompt;
            }

            // BORDER: Check to see if the recognition result contains the semantic key for the border color,
            // and not a match for the GARBAGE rule, and change the color.
            if ("KEY_BORDER" in semanticsObj.properties && semanticsObj.properties["KEY_BORDER"].toString() != "...") {
                var newBorderColor = semanticsObj.properties["KEY_BORDER"].toString();
                borderColor = getColor(newBorderColor);
            }

            // If "border" was matched, but the color rule matched GARBAGE, prompt the user.
            else if ("KEY_BORDER" in semanticsObj.properties && semanticsObj.properties["KEY_BORDER"].toString() == "...") {
                garbagePrompt += "Didn't get the border color\n\n Try saying red border\n";
                resultTextArea.innerText = garbagePrompt;
            }

            // CIRCLE: Check to see if the recognition result contains the semantic key for the circle color,
            // and not a match for the GARBAGE rule, and change the color.
            if ("KEY_CIRCLE" in semanticsObj.properties && semanticsObj.properties["KEY_CIRCLE"].toString() != "...") {
                var newCircleColor = semanticsObj.properties["KEY_CIRCLE"].toString();
                circleColor = getColor(newCircleColor);
            }

            // If "circle" was matched, but the color rule matched GARBAGE, prompt the user.
            else if ("KEY_CIRCLE" in semanticsObj.properties && semanticsObj.properties["KEY_CIRCLE"].toString() == "...") {
                garbagePrompt += "Didn't get the circle color\n\n Try saying green circle\n";
                resultTextArea.innerText = garbagePrompt;
            }

            // Initialize a string that will describe the user's color choices.
            var textBoxColors = "You selected (Semantic Interpretation)-> \n";

            // Write the color choices contained in the semantics of the recognition result to the text box.
            for (var key in semanticsObj.properties) {
                if (semanticsObj.properties.hasOwnProperty(key)) {
                    var value = semanticsObj.properties[key];

                    // Check to see if any of the semantic values in recognition result contains a match for the GARBAGE rule.
                    if (value != "...") {

                        // Cycle through the semantic keys and values and write them to the text box.
                        textBoxColors += value;
                        textBoxColors += " ";
                        textBoxColors += (key || "null");
                        textBoxColors += "\n";

                        resultTextArea.innerText = textBoxColors;
                    }
                    // If there was no match to the colors rule or if it matched GARBAGE, prompt the user.
                    else {
                        resultTextArea.innerText = garbagePrompt;
                    }
                }
            }

            drawCanvas();
        }

        // Prompt the user if recognition failed or recognition confidence is low.
        else if (result.confidence == Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.rejected ||
                 result.confidence == Windows.Media.SpeechRecognition.SpeechRecognitionConfidence.low) {
            resultTextArea.innerText = "Sorry, didn't get that \n\nTry saying ->\nblue background\nred border\ngreen circle";
        }
    }