예제 #1
0
    /// <summary>
    /// RecoServiceClient_OnMessageReceived event handler:
    /// This event handler gets fired every time a new message comes back via WebSocket.
    /// </summary>
    /// <param name="result"></param>
    private void RecoServiceClient_OnMessageReceived(SpeechServiceResult result)
    {
        try
        {
            if (result.Path == SpeechServiceResult.SpeechMessagePaths.SpeechHypothesis)
            {
                UpdateUICanvasLabel(result.Result.Text, FontStyle.Italic);
            }
            else if (result.Path == SpeechServiceResult.SpeechMessagePaths.SpeechPhrase)
            {
                if (isRecognizing)
                {
                    StopRecording();
                }

                UpdateUICanvasLabel(result.Result.DisplayText, FontStyle.Normal);

                // LUIS integration after speech recognition
                if (luis != null)
                {
                    luis.PredictAndHandleAsync(result.Result.DisplayText);
                }

                Debug.Log("* RECOGNITION STATUS: " + result.Result.RecognitionStatus);
                Debug.Log("* FINAL RESULT: " + result.Result.DisplayText);
            }
        }
        catch (Exception ex)
        {
            string msg = String.Format("Error: Something went wrong when posting speech recognition results. See error details below:{0}{1}{2}{3}",
                                       Environment.NewLine, ex.ToString(), Environment.NewLine, ex.Message);
            Debug.LogError(msg);
            UpdateUICanvasLabel(msg, FontStyle.Normal);
        }
    }
    /// <summary>
    /// Attempts to try a prediction of the <see cref="TestUtterance"/>.
    /// </summary>
    public async void TryPredict()
    {
        // Make sure we're enabled
        if (!enabled)
        {
            Debug.LogError($"{nameof(LuisTester)} is not enabled. Can't predict.");
            return;
        }

        // Make sure we have a Luis Manager assigned
        if (LuisManager == null)
        {
            Debug.LogError($"{nameof(LuisManager)} is not set to a valid instance.");
            return;
        }

        // If there is a scene text control and its contents aren't empty use that
        if ((SceneUtteranceInput != null) && (!string.IsNullOrEmpty(SceneUtteranceInput.text)))
        {
            TestUtterance = SceneUtteranceInput.text;
        }

        // Make sure we have something to predict
        if (string.IsNullOrEmpty(TestUtterance))
        {
            Debug.LogError($"{nameof(TestUtterance)} is empty. Nothing to predict.");
            return;
        }

        // Predict!
        await LuisManager.PredictAndHandleAsync(TestUtterance);
    }
예제 #3
0
    /// <summary>
    /// Attempts to try a prediction of the <see cref="TestUtterance"/>.
    /// </summary>
    public async void TryPredict()
    {
        if (!enabled)
        {
            Debug.LogError($"{nameof(LuisTester)} is not enabled. Can't predict.");
            return;
        }

        if (LuisManager == null)
        {
            Debug.LogError($"{nameof(LuisManager)} is not set to a valid instance.");
            return;
        }

        if (string.IsNullOrEmpty(TestUtterance))
        {
            Debug.LogError($"{nameof(TestUtterance)} is empty. Nothing to predict.");
            return;
        }

        // Predict!
        await LuisManager.PredictAndHandleAsync(TestUtterance);
    }