Exemplo n.º 1
0
        private void OnRecognize(Data data)
        {
            SpeechResultList result = ((SpeechToTextData)data).Results;

            if (result.HasFinalResult())
            {
                string text           = result.Results[0].Alternatives[0].Transcript;
                double textConfidence = result.Results[0].Alternatives[0].Confidence;

                Log.Debug("NlcWidget", "OnRecognize: {0} ({1:0.00})", text, textConfidence);
                EventManager.Instance.SendEvent(Constants.Event.ON_DEBUG_MESSAGE, string.Format("{0} ({1:0.00})", text, textConfidence));

                if (textConfidence > m_MinWordConfidence)
                {
                    if (!string.IsNullOrEmpty(m_ClassifierId))
                    {
                        if (!m_NLC.Classify(m_ClassifierId, text, OnClassified))
                        {
                            Log.Error("NlcWidget", "Failed to send {0} to NLC.", text);
                        }
                    }
                    else
                    {
                        Log.Equals("NlcWidget", "No valid classifier set.");
                    }
                }
                else
                {
                    if (textConfidence > m_IgnoreWordConfidence)
                    {
                        EventManager.Instance.SendEvent(Constants.Event.ON_CLASSIFY_FAILURE, result);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void OnSpeechInput(Data data)
        {
            SpeechResultList result = ((SpeechToTextData)data).Results;

            if (result != null && result.HasFinalResult())
            {
                string text = result.Results[0].Alternatives[0].Transcript;

                Converse(text);
                AddDialog(text, m_QuestionPrefab);
            }
        }
        private void OnRecognize(Data data)
        {
            SpeechResultList result = ((SpeechToTextData)data).Results;

            if (result.HasFinalResult())
            {
                string text           = result.Results[0].Alternatives[0].Transcript;
                double textConfidence = result.Results[0].Alternatives[0].Confidence;

                Log.Debug("NaturalLanguageClassifierWidget", "OnRecognize: {0} ({1:0.00})", text, textConfidence);
                EventManager.Instance.SendEvent("OnDebugMessage", string.Format("{0} ({1:0.00})", text, textConfidence));

                if (textConfidence > MinWordConfidence)
                {
                    if (!string.IsNullOrEmpty(m_ClassifierId))
                    {
                        if (!m_NaturalLanguageClassifier.Classify(m_ClassifierId, text, OnClassified))
                        {
                            Log.Error("NaturalLanguageClassifierWidget", "Failed to send {0} to Natural Language Classifier.", text);
                        }
                    }
                    else
                    {
                        Log.Equals("NaturalLanguageClassifierWidget", "No valid classifier set.");
                    }
                }
                else
                {
                    Log.Debug("NaturalLanguagClassifierWidget", "Text confidence {0} < {1} (Min word confidence)", textConfidence, MinWordConfidence);
                    if (textConfidence > IgnoreWordConfidence)
                    {
                        Log.Debug("NaturalLanguageClassifierWidget", "Text confidence {0} > {1} (Ignore word confidence)", textConfidence, IgnoreWordConfidence);
                        EventManager.Instance.SendEvent("OnClassifyFailure", result);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void OnListenMessage(WSConnector.Message msg)
        {
            if (msg is WSConnector.TextMessage)
            {
                WSConnector.TextMessage tm = (WSConnector.TextMessage)msg;

                IDictionary json = Json.Deserialize(tm.Text) as IDictionary;
                if (json != null)
                {
                    if (json.Contains("results"))
                    {
                        SpeechResultList results = ParseRecognizeResponse(json);
                        if (results != null)
                        {
                            // when we get results, start listening for the next block ..
                            // if continuous is true, then we don't need to do this..
                            if (!EnableContinousRecognition && results.HasFinalResult())
                            {
                                SendStart();
                            }

                            if (m_ListenCallback != null)
                            {
                                m_ListenCallback(results);
                            }
                            else
                            {
                                StopListening();            // automatically stop listening if our callback is destroyed.
                            }
                        }
                        else
                        {
                            Log.Error("SpeechToText", "Failed to parse results: {0}", tm.Text);
                        }
                    }
                    else if (json.Contains("state"))
                    {
                        string state = (string)json["state"];

#if ENABLE_DEBUGGING
                        Log.Debug("SpeechToText", "Server state is {0}", state);
#endif
                        if (state == "listening")
                        {
                            if (m_IsListening)
                            {
                                if (!m_ListenActive)
                                {
                                    m_ListenActive = true;

                                    // send all pending audio clips ..
                                    while (m_ListenRecordings.Count > 0)
                                    {
                                        AudioData clip = m_ListenRecordings.Dequeue();
                                        m_ListenSocket.Send(new WSConnector.BinaryMessage(AudioClipUtil.GetL16(clip.Clip)));
                                        m_AudioSent = true;
                                    }
                                }
                            }
                        }
                    }
                    else if (json.Contains("error"))
                    {
                        string error = (string)json["error"];
                        Log.Error("SpeechToText", "Error: {0}", error);

                        StopListening();
                        if (OnError != null)
                        {
                            OnError(error);
                        }
                    }
                    else
                    {
                        Log.Warning("SpeechToText", "Unknown message: {0}", tm.Text);
                    }
                }
                else
                {
                    Log.Error("SpeechToText", "Failed to parse JSON from server: {0}", tm.Text);
                }
            }
        }