// TONE ZONE private IEnumerator Examples() { // Analyze tone if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, OnFail, _stringToTestTone1)) { Log.Debug("ExampleToneAnalyzer.Examples()", "Failed to analyze!"); } while (!_analyzeToneTested) { yield return(null); } Log.Debug("ExampleToneAnalyzer.Examples()", "Tone analyzer examples complete."); }
// For Speech Recognition -- commands to UI/Experience /// <summary> /// Invoked by Watson SpeechToText to handle response /// </summary> /// <param name="result">Result.</param> private void OnRecognize(SpeechRecognitionEvent result) { if (result != null && result.results.Length > 0) { foreach (var res in result.results) { // Commands // at present we dont recognize any Commands, so this section is commented ot // and decimated the code, so if you want it back read Ryan's Example 4 Robot // How many alt usually come back? is updating a single SO correct // or should there be a collection/queue? foreach (var alt in res.alternatives) { string text = string.Format("{0} ({1}, {2:0.00})\n", alt.transcript, res.final ? "Final" : "Interim", alt.confidence); Log.Debug("WatsonServiceConnection.OnRecognize()", text); // UPDATE THE ScriptableObject // watchers need to refresh in their Update() // or we need to implement EventVariables similar to Hipple GameEvent // VariableEvent? recognizedText.Value = text; // SEND TO TONE ANALYSIS // This might? be done as a watcher on recognizedText? string GHI = alt.transcript; if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, OnFail, GHI)) { Log.Debug("WatsonServiceConnection.Examples()", "Failed to analyze!"); } // pass to Command Parsing CommandParser(alt.transcript); } // Log Keywords - should be done as a Watcher on recognizedText if (res.keywords_result != null && res.keywords_result.keyword != null) { foreach (var keyword in res.keywords_result.keyword) { Log.Debug("WatsonServiceConnection.OnRecognize()", "keyword: {0}, confidence: {1}, start time: {2}, end time: {3}", keyword.normalized_text, keyword.confidence, keyword.start_time, keyword.end_time); //ResultsField.text = "tone analyzed! 222"; } } // Log Alternative Words if (res.word_alternatives != null) { foreach (var wordAlternative in res.word_alternatives) { Log.Debug("WatsonServiceConnection.OnRecognize()", "Word alternatives found. Start time: {0} | EndTime: {1}", wordAlternative.start_time, wordAlternative.end_time); foreach (var alternative in wordAlternative.alternatives) { Log.Debug("WatsonServiceConnection.OnRecognize()", "\t word: {0} | confidence: {1}", alternative.word, alternative.confidence); } } } } } }
public void GetTone(string question) { Log.Debug("ToneHandler.GetTone()", "{0}", question); if (!_service.GetToneAnalyze(OnGetToneAnalyze, OnFail, question)) { Log.Debug("ToneHandler.GetTone()", "Failed to analyze!"); } }
/// <summary> /// Invoked when Watched String changes and sends to Watson ToneAnalysis /// </summary> private void AnalyzeText() { Log.Debug("WatsonToneAnalysisService.AnalyzeText()", "Analyze: {0}", textToAnalyze.Value); if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, OnFail, textToAnalyze.Value)) { Log.Debug("WatsonToneAnalysisService.AnalyzeText()", "Failed to analyze!"); } }
// For Speech Recognition -- commands to UI/Experience private void OnRecognize(SpeechRecognitionEvent result) { if (result != null && result.results.Length > 0) { foreach (var res in result.results) { // Commands // at present we dont recognize any Commands, so this section is commented ot //and decimated the code, so if you want it back read Ryan's Example 4 Robot foreach (var alt in res.alternatives) { string text = string.Format("{0} ({1}, {2:0.00})\n", alt.transcript, res.final ? "Final" : "Interim", alt.confidence); Log.Debug("WatsonServiceConnection.OnRecognize()", text); ResultsField.text = text; // SEND TO TONE ANALYSIS string GHI = alt.transcript; if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, OnFail, GHI)) { Log.Debug("WatsonServiceConnection.Examples()", "Failed to analyze!"); } // ENTERING THE TONE ZONE - when the utterance contains this word if (alt.transcript.Contains("reset")) { //ResetAction(); } } // Log Keywords if (res.keywords_result != null && res.keywords_result.keyword != null) { foreach (var keyword in res.keywords_result.keyword) { Log.Debug("WatsonServiceConnection.OnRecognize()", "keyword: {0}, confidence: {1}, start time: {2}, end time: {3}", keyword.normalized_text, keyword.confidence, keyword.start_time, keyword.end_time); //ResultsField.text = "tone analyzed! 222"; } } // Log Alternative Words if (res.word_alternatives != null) { foreach (var wordAlternative in res.word_alternatives) { Log.Debug("WatsonServiceConnection.OnRecognize()", "Word alternatives found. Start time: {0} | EndTime: {1}", wordAlternative.start_time, wordAlternative.end_time); foreach (var alternative in wordAlternative.alternatives) { Log.Debug("WatsonServiceConnection.OnRecognize()", "\t word: {0} | confidence: {1}", alternative.word, alternative.confidence); } } } } } }
public override IEnumerator RunTest() { if (Utilities.Config.Instance.FindCredentials(m_ToneAnalyzer.GetServiceID()) == null) { yield break; } m_ToneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, m_StringToTestTone, "TEST"); while (!m_GetToneAnalyzerTested) { yield return(null); } yield break; }
private void OnRecognize(SpeechRecognitionEvent result) { if (result != null && result.results.Length > 0) { foreach (var res in result.results) { foreach (var alt in res.alternatives) { string text = alt.transcript; Log.Debug("Streaming", string.Format("{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence)); if (res.final) { speechText = text; NluSpeech.nluSpeech(); faceNormalizeVector = new double[24]; numInstances++; for (int i = 0; i < 24; i++) { faceNormalizeVector [i] += FacialEmotion.faceVector [i]; faceNormalizeVector [i] = faceNormalizeVector [i] / (double)numInstances; } numInstances = 0; m_ToneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, text, text); } else { numInstances++; for (int i = 0; i < 24; i++) { faceNormalizeVector [i] += FacialEmotion.faceVector [i]; } } } } } }
private void OnRecognize(SpeechRecognitionEvent result) { if (result != null && result.results.Length > 0) { foreach (var res in result.results) { foreach (var alt in res.alternatives) { string text = string.Format("{0} ({1}, {2:0.00})\n", alt.transcript, res.final ? "Final" : "Interim", alt.confidence); Log.Debug("ExampleStreaming.OnRecognize()", text); ResultsField.text = text; //// /// // ENTERING THE TONE ZONE - when the utterance contains this word //if (alt.transcript.Contains ("feel") | alt.transcript.Contains ("you") | alt.transcript.Contains ("Jimmy") | alt.transcript.Contains ("robot")) { if (true) { string GHI = alt.transcript; if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, OnFail, GHI)) { Log.Debug("ExampleToneAnalyzer.Examples()", "Failed to analyze!"); } Log.Debug("ExampleToneAnalyzer.Examples()", "NESTED TONE ZONE branch complete."); //ResultsField.text = "tone analyzed! 111"; // TEST END } ///// /// /// // ENTERING THE TONE ZONE - when the utterance contains this word if (alt.transcript.Contains("reset")) { sphere_emo_joyRenderer.transform.localScale = new Vector3(.075F, .075F, .075F); sphere_emo_angerRenderer.transform.localScale = new Vector3(.075F, .075F, .075F); sphere_emo_fearRenderer.transform.localScale = new Vector3(.075F, .075F, .075F); sphere_emo_disgustRenderer.transform.localScale = new Vector3(.075F, .075F, .075F); sphere_emo_sadnessRenderer.transform.localScale = new Vector3(.075F, .075F, .075F); MacKenzieRenderer.transform.localScale = new Vector3(5F, 5F, 5F); } if (alt.transcript.Contains("mouse") || alt.transcript.Contains("tiny")) { MacKenzieRenderer.transform.localScale = new Vector3(2F, 2F, 2F); } if (alt.transcript.Contains("elephant") || alt.transcript.Contains("giant")) { MacKenzieRenderer.transform.localScale = new Vector3(10F, 10F, 10F); } //// Text to Speak Trigger zone if (alt.transcript.Contains("blue") && ResultsField.text.Contains("Final")) // needs to be final or ECHO happens { _testString = "<speak version=\"1.0\"><express-as type=\"Uncertainty\">The color of the SKy. I am a little under the weather</express-as></speak>"; Runnable.Run(Examples()); } if (alt.transcript.Contains("yellow") && ResultsField.text.Contains("Final")) // needs to be final or ECHO happens { _testString = "<speak version=\"1.0\"><prosody pitch=\\\"250Hz\\\"><express-as type=\"GoodNews\">Oh Yes! The color of daisies! It makes me feel delighted to be alive! Good things happen with such a bright color.</express-as></prosody></speak>"; Runnable.Run(Examples()); } // Cannot ECHO the trigger condition (or be ready for loop if (alt.transcript.Contains("happy") && ResultsField.text.Contains("Final")) // needs to be final or ECHO happens { _testString = "<speak version=\"1.0\"><prosody pitch=\\\"250Hz\\\"><express-as type=\"GoodNews\">That's so nice! You bring me great joy as well!</express-as></prosody></speak>"; Runnable.Run(Examples()); } // Cannot ECHO the trigger condition (or be ready for loop if (alt.transcript.Contains("mistake") && ResultsField.text.Contains("Final")) // needs to be final or ECHO happens { _testString = "<speak version=\"1.0\"><prosody pitch=\\\"200Hz\\\"><express-as type=\"Apology\">I am so sorry. I'll try to do better next time.</express-as></prosody></speak>"; Runnable.Run(Examples()); } // Cannot ECHO the trigger condition (or be ready for loop if (alt.transcript.Contains("quantum") && ResultsField.text.Contains("Final")) // needs to be final or ECHO happens { _testString = "<speak version=\"1.0\"><prosody pitch=\\\"200Hz\\\"><express-as type=\"Uncertainty\">I dont really know how to answer that.</express-as></prosody></speak>"; Runnable.Run(Examples()); } // Cannot ECHO the trigger condition (or be ready for loop if (alt.transcript.Contains("despair") && ResultsField.text.Contains("Final")) // needs to be final or ECHO happens { _testString = "<speak version=\"1.0\"><prosody pitch=\\\"250Hz\\\"><express-as type=\"Apology\">Yes, hopeless</express-as></prosody></speak>"; Runnable.Run(Examples()); } // Cannot ECHO the trigger condition (or be ready for loop if (alt.transcript.Contains("bears") && ResultsField.text.Contains("Final")) // needs to be final or ECHO happens { _testString = "<speak version=\"1.0\"><prosody pitch=\\\"250Hz\\\"><express-as type=\"Uncertainty\">Large carnivores terrify me</express-as></prosody></speak>"; Runnable.Run(Examples()); } // Cannot ECHO the trigger condition (or be ready for loop if (alt.transcript.Contains("goodbye") && ResultsField.text.Contains("Final")) // needs to be final or ECHO happens { _testString = "<speak version=\"1.0\"><prosody pitch=\\\"200Hz\\\"><express-as type=\"GoodNews\">Bye bye! And thank you!</express-as></prosody></speak>"; Runnable.Run(Examples()); } // Cannot ECHO the trigger condition (or be ready for loop } if (res.keywords_result != null && res.keywords_result.keyword != null) { foreach (var keyword in res.keywords_result.keyword) { Log.Debug("ExampleStreaming.OnRecognize()", "keyword: {0}, confidence: {1}, start time: {2}, end time: {3}", keyword.normalized_text, keyword.confidence, keyword.start_time, keyword.end_time); } } if (res.word_alternatives != null) { foreach (var wordAlternative in res.word_alternatives) { Log.Debug("ExampleStreaming.OnRecognize()", "Word alternatives found. Start time: {0} | EndTime: {1}", wordAlternative.start_time, wordAlternative.end_time); foreach (var alternative in wordAlternative.alternatives) { Log.Debug("ExampleStreaming.OnRecognize()", "\t word: {0} | confidence: {1}", alternative.word, alternative.confidence); } } } } } }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; string credentialsFilepath = "../sdk-credentials/credentials.json"; // Load credentials file if it exists. If it doesn't exist, don't run the tests. if (File.Exists(credentialsFilepath)) { result = File.ReadAllText(credentialsFilepath); } else { yield break; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.GetCredentialByname("tone-analyzer-sdk")[0].Credentials; // Create credential and instantiate service TokenOptions tokenOptions = new TokenOptions() { IamApiKey = credential.IamApikey, }; // Create credential and instantiate service Credentials credentials = new Credentials(tokenOptions, credential.Url); // Wait for tokendata while (!credentials.HasIamTokenData()) { yield return(null); } _toneAnalyzer = new ToneAnalyzer(credentials); _toneAnalyzer.VersionDate = _toneAnalyzerVersionDate; // Analyze tone if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, OnFail, _stringToTestTone)) { Log.Debug("ExampleToneAnalyzer.GetToneAnalyze()", "Failed to analyze!"); } while (!_analyzeToneTested) { yield return(null); } Log.Debug("ExampleToneAnalyzer.RunTest()", "Tone analyzer examples complete."); yield break; }
void Start() { m_StringToTestTone = "HIS glory, by whose might all things are moved,\t\nPierces the universe, and in one part\t\nSheds more resplendence, elsewhere less. In\t\nThat largeliest of His light partakes, was I, [Heaven\t\nWitness of things, which, to relate again,\t 5\nSurpasseth power of him who comes from thence;\t\nFor that, so near approaching its desire,\t\nOut intellect is to such depth absorb’d,\t\nThat memory cannot follow. Nathless all,\t\nThat in my thoughts I of that sacred realm\t 10\nCould store, shall now be matter of my song.\t\n Benign Apollo! this last labour aid;\t\nAnd make me such a vessel of thy worth,\t\nAs thy own laurel claims, of me beloved."; m_ToneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, m_StringToTestTone); }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); try { VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; // Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format. // See https://www.ibm.com/watson/developercloud/doc/common/getting-started-variables.html. var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES"); var fileContent = File.ReadAllText(environmentalVariable); // Add in a parent object because Unity does not like to deserialize root level collection types. fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(fileContent, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["tone_analyzer"][TestCredentialIndex].Credentials; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); } catch { Log.Debug("TestToneAnalyzer", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication"); } // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); // Or authenticate using token //Credentials credentials = new Credentials(_url) //{ // AuthenticationToken = _token //}; _toneAnalyzer = new ToneAnalyzer(credentials); _toneAnalyzer.VersionDate = _toneAnalyzerVersionDate; // Analyze tone if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, _stringToTestTone)) { Log.Debug("ExampleToneAnalyzer", "Failed to analyze!"); } while (!_analyzeToneTested) { yield return(null); } Log.Debug("ExampleToneAnalyzer", "Tone analyzer examples complete."); yield break; }
void Start() { m_ToneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, m_StringToTestTone, "TEST"); }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL"); var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME"); var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD"); using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword)) { while (!simpleGet.IsComplete) { yield return(null); } result = simpleGet.Result; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["tone_analyzer"]; _username = credential.Username.ToString(); _password = credential.Password.ToString(); _url = credential.Url.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_username, _password, _url); // Or authenticate using token //Credentials credentials = new Credentials(_url) //{ // AuthenticationToken = _token //}; _toneAnalyzer = new ToneAnalyzer(credentials); _toneAnalyzer.VersionDate = _toneAnalyzerVersionDate; // Analyze tone if (!_toneAnalyzer.GetToneAnalyze(OnGetToneAnalyze, OnFail, _stringToTestTone)) { Log.Debug("ExampleToneAnalyzer.GetToneAnalyze()", "Failed to analyze!"); } while (!_analyzeToneTested) { yield return(null); } Log.Debug("ExampleToneAnalyzer.RunTest()", "Tone analyzer examples complete."); yield break; }