private void OnRecognize(SpeechResultList result) { // m_ResultOutput.SendData( new SpeechToTextData( result ) ); string speechToText = new SpeechToTextData(result).AllText; if (!string.IsNullOrEmpty(speechToText)) { Cloudspace.NotificationCenter.DefaultCenter().PostNotification(this, "OnTextFromSpeech", speechToText); } Log.Debug("recognise", "result: {0}", new SpeechToTextData(result).Text); if (result != null && result.Results.Length > 0) { if (m_Transcript != null) { m_Transcript.text = ""; } foreach (var res in result.Results) { foreach (var alt in res.Alternatives) { string text = alt.Transcript; if (m_Transcript != null) { m_Transcript.text += string.Format("{0} ({1}, {2:0.00})\n", text, res.Final ? "Final" : "Interim", alt.Confidence); } } } } }
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); } } } }
private void OnRecognize(SpeechResultList result) { m_ResultOutput.SendData(new SpeechToTextData(result)); if (result != null && result.Results.Length > 0) { if (m_Transcript != null) { m_Transcript.text = ""; } foreach (var res in result.Results) { foreach (var alt in res.Alternatives) { string text = alt.Transcript; if (m_Transcript != null) { m_Transcript.text += string.Format("{0} ({1}, {2:0.00})\n", text, res.Final ? "Final" : "Interim", alt.Confidence); } } } } }
private void OnRecognizeResponse(RESTConnector.Request req, RESTConnector.Response resp) { RecognizeRequest recognizeReq = req as RecognizeRequest; if (recognizeReq == null) { throw new WatsonException("Unexpected request type."); } SpeechResultList result = null; if (resp.Success) { result = ParseRecognizeResponse(resp.Data); if (result == null) { Log.Error("SpeechToText", "Failed to parse json response: {0}", resp.Data != null ? Encoding.UTF8.GetString(resp.Data) : ""); } else { Log.Status("SpeechToText", "Received Recognize Response, Elapsed Time: {0}, Results: {1}", resp.ElapsedTime, result.Results.Length); } } else { Log.Error("SpeechToText", "Recognize Error: {0}", resp.Error); } if (recognizeReq.Callback != null) { recognizeReq.Callback(result); } }
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); } }
/// <summary> /// Function that is called when the Watson API returns a result. /// </summary> /// <param name="results">List of speech-to-text results</param> protected void OnSpeechToTextResult(SpeechResultList results) { if (results.HasResult()) { SpeechResult watsonResult = results.Results[0]; var textResult = m_WatsonSpeechToTextComponent.CreateSpeechToTextResult(watsonResult); if (m_OnTextResult != null) { m_OnTextResult(textResult); } m_LastResult = textResult; } }
void HandleOnRecognize(SpeechResultList result) { if (result != null && result.Results.Length > 0) { foreach (var res in result.Results) { foreach (var alt in res.Alternatives) { string text = alt.Transcript; Debug.Log(string.Format("{0} ({1}, {2:0.00})\n", text, res.Final ? "Final" : "Interim", alt.Confidence)); } } } }
/// <summary> /// Function that is called when the Watson API returns a result. /// </summary> /// <param name="results">List of speech-to-text results</param> void OnSpeechToTextResult(SpeechResultList results) { if (results.HasResult()) { if (m_OnTextResult != null) { m_OnTextResult(m_WatsonSpeechToTextComponent.CreateSpeechToTextResult(results.Results[0])); } } else { m_OnTextResult(new SpeechToTextResult("", true)); } }
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); } } } }
/// <summary> /// Data constructor. /// </summary> /// <param name="result">The SpeechToText results.</param> public SpeechToTextData(SpeechResultList result) { Results = result; }
private void OnSpeechInput(Data data) { UnityEngine.Debug.Log("eeeee"); if (m_Output != null || m_OutputAsInputField != null) { SpeechResultList result = ((SpeechToTextData)data).Results; if (result != null && result.Results.Length > 0) { string outputTextWithStatus = ""; string outputText = ""; if (Time.time - m_TimeAtLastInterim > m_ThresholdTimeFromLastInput) { if (m_Output != null) { m_PreviousOutputTextWithStatus = m_Output.text; } if (m_OutputAsInputField != null) { m_PreviousOutputText = m_OutputAsInputField.text; } } if (m_Output != null && m_ContinuousText) { outputTextWithStatus = m_PreviousOutputTextWithStatus; } if (m_OutputAsInputField != null && m_ContinuousText) { outputText = m_PreviousOutputText; } foreach (var res in result.Results) { foreach (var alt in res.Alternatives) { string text = alt.Transcript; if (m_Output != null) { m_Output.text = string.Concat(outputTextWithStatus, string.Format("{0} ({1}, {2:0.00})\n", text, res.Final ? "Final" : "Interim", alt.Confidence)); UnityEngine.Debug.Log(m_Output.text); } if (m_OutputAsInputField != null) { if (!res.Final || alt.Confidence > m_MinConfidenceToShow) { m_OutputAsInputField.text = string.Concat(outputText, " ", text); if (m_OutputStatus != null) { m_OutputStatus.text = string.Format("{0}, {1:0.00}", res.Final ? "Final" : "Interim", alt.Confidence); } } } if (!res.Final) { m_TimeAtLastInterim = Time.time; } } } } } }
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); } } }