/// <summary> /// Logs the final recognition result /// </summary> private void RecognizedEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { SpeechRecognizedEventArgs eventArgs = new SpeechRecognizedEventArgs(); #if DEBUG if (rt == RecoType.Base) { eventArgs.Message = e.Result.Text; OnSpeechRecognizedEvent(eventArgs); } else { eventArgs.Message = e.Result.Text; OnSpeechRecognizedEvent(eventArgs); } eventArgs.Message = $" --- Final result received. Reason: {e.Result.Reason.ToString()}. --- "; OnSpeechRecognizedEvent(eventArgs); #endif if (!string.IsNullOrEmpty(e.Result.Text)) { //this.WriteLine(log, e.Result.Text); eventArgs.Message = e.Result.Text; OnSpeechRecognizedEvent(eventArgs); } // if access to the JSON is needed it can be obtained from Properties string json = e.Result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult); }
private async Task RecognizedEventHandlerAsync(SpeechRecognitionEventArgs e, RecoType rt) { TextBox log; if (rt == RecoType.Base) { log = this.baseModelLogText; this.SetCurrentText(this.baseModelCurrentText, e.Result.Text); if (e.Result.Text.Equals("What's the weather like?")) { var config = SpeechConfig.FromSubscription(this.SubscriptionKey, this.Region); config.SpeechRecognitionLanguage = this.RecognitionLanguage; SpeechSynthesizer basicRecognizer; if (this.UseMicrophone) { using (basicRecognizer = new SpeechSynthesizer(config)) { await basicRecognizer.SpeakTextAsync("cuacanya panas banget boo!"); } } } } else { log = this.customModelLogText; this.SetCurrentText(this.customModelCurrentText, e.Result.Text); } }
private void SpeechDetectedEventHandler(RecognitionEventArgs e, RecoType rt, string eventType) { var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; this.WriteLine(log, String.Format(CultureInfo.InvariantCulture, "Speech recognition: Speech {0} detected event: {1}.", eventType, e.ToString())); }
/// <summary> /// Session started event handler. /// </summary> private void SessionStartedEventHandler(SessionEventArgs e, RecoType rt) { //var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; var log = this.baseModelLogText; //this line added this.WriteLine(log, String.Format(CultureInfo.InvariantCulture, "Speech recognition: Session started event: {0}.", e.ToString())); }
/// <summary> /// Logs the final recognition result /// </summary> private void RecognizedEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { TextBox log; if (rt == RecoType.Base) { log = this.baseModelLogText; this.SetCurrentText(this.baseModelCurrentText, e.Result.Text); } else { log = this.customModelLogText; this.SetCurrentText(this.customModelCurrentText, e.Result.Text); } this.WriteLine(log); this.WriteLine(log, $" --- Final result received. Reason: {e.Result.Reason.ToString()}. --- "); if (!string.IsNullOrEmpty(e.Result.Text)) { //write log this.WriteLine(log, e.Result.Text); //write result this.WriteLine(this.recognizedText, $"[{DateTime.Now.ToString("HH:mm:ss")}] Me: {e.Result.Text}"); SendMessageToBot(e.Result.Text); } }
/// <summary> /// Logs the final recognition result /// </summary> private void RecognizedEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { TextBox log; if (rt == RecoType.Base) { log = this.baseModelLogText; this.SetCurrentText(this.baseModelCurrentText, e.Result.Text); } else { log = this.customModelLogText; this.SetCurrentText(this.customModelCurrentText, e.Result.Text); } this.WriteLine(log); this.WriteLine(log, $" --- Final result received. Reason: {e.Result.Reason.ToString()}. --- "); if (!string.IsNullOrEmpty(e.Result.Text)) { this.WriteLine(log, e.Result.Text); } // if access to the JSON is needed it can be obtained from Properties string json = e.Result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult); }
/// <summary> /// Session stopped event handler. Set the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void SessionStoppedEventHandler(SessionEventArgs e, RecoType rt, TaskCompletionSource <int> source) { var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; this.WriteLine(log, String.Format(CultureInfo.InvariantCulture, "Speech recognition: Session stopped event: {0}.", e.ToString())); source.TrySetResult(0); }
/// <summary> /// Session stopped event handler. Set the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void SessionStoppedEventHandler(SessionEventArgs e, RecoType rt, TaskCompletionSource <int> source) { source.TrySetResult(0); //SpeechSessionStopedEventArgs eventArgs = new SpeechSessionStopedEventArgs(); Console.WriteLine("Speech recognition: Session stopped event: " + e.ToString() + "."); //OnSpeechSessionStopedEvent(eventArgs); }
private void DetectedEventHandler(RecognitionEventArgs e, RecoType rt, string eventType) { SpeechDetectedEvendEventArgs eventArgs = new SpeechDetectedEvendEventArgs(); eventArgs.Message = "Speech recognition: Speech " + eventType + "detected event: " + e.ToString() + "."; OnSpeechDetectedEvent(eventArgs); }
/// <summary> /// Session started event handler. /// </summary> private void SessionStartedEventHandler(SessionEventArgs e, RecoType rt) { SpeechSessionStartedEventArgs eventArgs = new SpeechSessionStartedEventArgs(); eventArgs.Message = "Speech recognition: Session started event: " + e.ToString() + "."; OnSpeechSessionStartedEvent(eventArgs); }
/// <summary> /// Logs the final recognition result /// </summary> private void RecognizedEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { var config = SpeechConfig.FromSubscription(this.SubscriptionKey, this.Region); var synthesizer = new SpeechSynthesizer(config); TextBox log; if (rt == RecoType.Base) { log = this.baseModelLogText; this.SetCurrentText(this.baseModelCurrentText, e.Result.Text); if (e.Result.Text == "What's up?") { synthesizer.SpeakTextAsync("nnnnnnnnnnnnnn nnnnnnnnnnnnnnn nnnnnnnnnnnnnnnnnnnn ;;;;;;;;;;;;; My motorcycle is broken."); } } else { log = this.customModelLogText; this.SetCurrentText(this.customModelCurrentText, e.Result.Text); } this.WriteLine(log); this.WriteLine(log, $" --- Final result received. Reason: {e.Result.Reason.ToString()}. --- "); if (!string.IsNullOrEmpty(e.Result.Text)) { this.WriteLine(log, e.Result.Text); } // if access to the JSON is needed it can be obtained from Properties string json = e.Result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult); }
/// <summary> /// Logs intermediate recognition results /// </summary> private void RecognizingEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { //SpeechRecognizingEventArgs eventArgs = new SpeechRecognizingEventArgs(); Console.WriteLine("Intermediate result: " + e.Result.Text); //eventArgs.Offset = e.Offset; //eventArgs.SessionId = e.SessionId; //OnSpeechRecognizingEvent(eventArgs); }
/// <summary> /// Session stopped event handler. Set the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void SessionStoppedEventHandler(SessionEventArgs e, RecoType rt, TaskCompletionSource <int> source) { source.TrySetResult(0); SpeechSessionStopedEventArgs eventArgs = new SpeechSessionStopedEventArgs(); eventArgs.Message = "Speech recognition: Session stopped event: " + e.ToString() + "."; OnSpeechSessionStopedEvent(eventArgs); }
/// <summary> /// Logs Canceled events /// And sets the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void CanceledEventHandler(SpeechRecognitionCanceledEventArgs e, RecoType rt, TaskCompletionSource <int> source) { SpeechCanceledEventArgs eventArgs = new SpeechCanceledEventArgs(); eventArgs.Message = "--- recognition canceled ---"; OnSpeechCanceledEvent(eventArgs); eventArgs.Message = $"CancellationReason: {e.Reason.ToString()}. ErrorDetails: {e.ErrorDetails}."; OnSpeechCanceledEvent(eventArgs); }
/// <summary> /// Logs Canceled events /// And sets the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void CanceledEventHandler(SpeechRecognitionCanceledEventArgs e, RecoType rt, TaskCompletionSource <int> source) { var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; source.TrySetResult(0); this.WriteLine(log, "--- recognition canceled ---"); this.WriteLine(log, $"CancellationReason: {e.Reason.ToString()}. ErrorDetails: {e.ErrorDetails}."); this.WriteLine(log); }
/// <summary> /// Logs Error events /// And sets the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void ErrorEventHandler(RecognitionErrorEventArgs e, RecoType rt, TaskCompletionSource <int> source) { var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; source.TrySetResult(0); this.WriteLine(log, "--- Error received ---"); this.WriteLine(log, $"Status: {e.Status.ToString()}. Reason: {e.FailureReason}."); this.WriteLine(log); }
/// <summary> /// Logs Error events /// And sets the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void ErrorEventHandler(RecognitionErrorEventArgs e, RecoType rt, TaskCompletionSource <int> source) { var log = (rt == RecoType.Basic) ? this.bingLogText : this.crisLogText; source.TrySetResult(0); this.WriteLine(log, "--- Error received ---"); this.WriteLine(log, "Reason {0}", e.Status); this.WriteLine(log); }
/// <summary> /// Logs intermediate recognition results /// </summary> private void RecognizingEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { SpeechRecognizingEventArgs eventArgs = new SpeechRecognizingEventArgs(); eventArgs.Message = "Intermediate result: " + e.Result.Text; eventArgs.Offset = e.Offset; eventArgs.SessionId = e.SessionId; OnSpeechRecognizingEvent(eventArgs); }
/// <summary> /// If SessionStoppedEvent is received, sets the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void SessionEventHandler(SessionEventArgs e, RecoType rt, TaskCompletionSource <int> source) { var log = (rt == RecoType.Basic) ? this.bingLogText : this.crisLogText; this.WriteLine(log, String.Format("Speech recognition: Session event: {0}.", e.ToString())); if (e.EventType == SessionEventType.SessionStoppedEvent) { source.TrySetResult(0); } }
/// <summary> /// Subscribes to Recognition Events /// Starts the Recognition and waits until final result is received, then Stops recognition /// </summary> /// <param name="recognizer">Recognizer object</param> /// <param name="recoType">Type of Recognizer</param> /// <value> /// <c>Base</c> if Baseline model; otherwise, <c>Custom</c>. /// </value> private async Task RunRecognizer(SpeechRecognizer recognizer, RecoType recoType, TaskCompletionSource <int> source) { Console.WriteLine("LOLO RunRecognizer()"); //subscribe to events bool isChecked = false; this.Dispatcher.Invoke(() => { isChecked = this.immediateResultsCheckBox.IsChecked == true; }); Console.WriteLine("LOLO RunRecognizer() sender"); EventHandler <SpeechRecognitionEventArgs> recognizingHandler = (sender, e) => RecognizedEventHandler(e, recoType); if (isChecked) { recognizer.Recognizing += recognizingHandler; } EventHandler <SpeechRecognitionEventArgs> recognizedHandler = (sender, e) => RecognizedEventHandler(e, recoType); EventHandler <SpeechRecognitionCanceledEventArgs> canceledHandler = (sender, e) => CanceledEventHandler(e, recoType, source); EventHandler <SessionEventArgs> sessionStartedHandler = (sender, e) => SessionStartedEventHandler(e, recoType); EventHandler <SessionEventArgs> sessionStoppedHandler = (sender, e) => SessionStoppedEventHandler(e, recoType, source); EventHandler <RecognitionEventArgs> speechStartDetectedHandler = (sender, e) => SpeechDetectedEventHandler(e, recoType, "start"); EventHandler <RecognitionEventArgs> speechEndDetectedHandler = (sender, e) => SpeechDetectedEventHandler(e, recoType, "end"); recognizer.Recognized += recognizedHandler; recognizer.Canceled += canceledHandler; recognizer.SessionStarted += sessionStartedHandler; recognizer.SessionStopped += sessionStoppedHandler; recognizer.SpeechStartDetected -= speechStartDetectedHandler; recognizer.SpeechEndDetected -= speechEndDetectedHandler; //start,wait,stop recognition await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false); await source.Task.ConfigureAwait(false); await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false); this.EnableButtons(); // unsubscribe from events if (isChecked) { recognizer.Recognizing -= recognizingHandler; } recognizer.Recognized -= recognizedHandler; recognizer.Canceled -= canceledHandler; recognizer.SessionStarted -= sessionStartedHandler; recognizer.SessionStopped -= sessionStoppedHandler; recognizer.SpeechStartDetected -= speechStartDetectedHandler; recognizer.SpeechEndDetected -= speechEndDetectedHandler; }
/// <summary> /// Logs intermediate recognition results /// </summary> private void RecognizingEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { //var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; var log = this.baseModelLogText; this.WriteLine(log, "Intermediate result: {0} ", e.Result.Text); //this.GetCurrentText(e.Result.Text); this.SetRecognizingText(this.baseModelCurrentText, e.Result.Text); //this.SetCurrentText(this.baseModelCurrentText, e.Result.Text); }
/// <summary> /// Logs Canceled events /// And sets the TaskCompletionSource to 0, in order to trigger Recognition Stop /// </summary> private void CanceledEventHandler(SpeechRecognitionCanceledEventArgs e, RecoType rt, TaskCompletionSource <int> source) { var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; source.TrySetResult(0); this.WriteLine(log, "--- recognition canceled ---"); this.WriteLine(log, $"CancellationReason: {e.Reason.ToString()}. ErrorDetails: {e.ErrorDetails}."); this.WriteLine(log); Console.WriteLine("End of text ..."); this.WriteLine(log, String.Format(CultureInfo.InvariantCulture, "{0}", sbText.ToString())); Console.Write(sbText.ToString()); }
private async Task RunRecognizer(SpeechRecognizer recognizer, RecoType recoType, TaskCompletionSource <int> source) { //subscribe to events bool isChecked = false; EventHandler <SpeechRecognitionEventArgs> recognizingHandler = (sender, e) => RecognizedEventHandler(e, recoType); if (isChecked) { recognizer.Recognizing += recognizingHandler; } EventHandler <SpeechRecognitionEventArgs> recognizedHandler = (sender, e) => RecognizedEventHandler(e, recoType); EventHandler <SpeechRecognitionCanceledEventArgs> canceledHandler = (sender, e) => CanceledEventHandler(e, recoType, source); EventHandler <SessionEventArgs> sessionStartedHandler = (sender, e) => SessionStartedEventHandler(e, recoType); EventHandler <SessionEventArgs> sessionStoppedHandler = (sender, e) => SessionStoppedEventHandler(e, recoType, source); EventHandler <RecognitionEventArgs> speechStartDetectedHandler = (sender, e) => SpeechDetectedEventHandler(e, recoType, "start"); EventHandler <RecognitionEventArgs> speechEndDetectedHandler = (sender, e) => SpeechDetectedEventHandler(e, recoType, "end"); recognizer.Recognized += recognizedHandler; recognizer.Canceled += canceledHandler; recognizer.SessionStarted += sessionStartedHandler; recognizer.SessionStopped += sessionStoppedHandler; recognizer.SpeechStartDetected -= speechStartDetectedHandler; recognizer.SpeechEndDetected -= speechEndDetectedHandler; //start,wait,stop recognition await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false); await source.Task.ConfigureAwait(false); await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false); // unsubscribe from events if (isChecked) { recognizer.Recognizing -= recognizingHandler; } recognizer.Recognized -= recognizedHandler; recognizer.Canceled -= canceledHandler; recognizer.SessionStarted -= sessionStartedHandler; recognizer.SessionStopped -= sessionStoppedHandler; recognizer.SpeechStartDetected -= speechStartDetectedHandler; recognizer.SpeechEndDetected -= speechEndDetectedHandler; }
/// <summary> /// Logs the Final result /// </summary> private void FinalResultEventHandler(SpeechRecognitionResultEventArgs e, RecoType rt) { TextBox log; if (rt == RecoType.Basic) { log = this.bingLogText; this.SetCurrentText(this.bingCurrentText, e.Result.Text); } else { log = this.crisLogText; this.SetCurrentText(this.crisCurrentText, e.Result.Text); } this.WriteLine(log); this.WriteLine(log, " --- Final result received --- "); this.WriteLine(log, e.Result.Text); }
/// <summary> /// Logs the Final result /// </summary> private void FinalResultEventHandler(SpeechRecognitionResultEventArgs e, RecoType rt) { TextBox log; if (rt == RecoType.Base) { log = this.baseModelLogText; this.SetCurrentText(this.baseModelCurrentText, e.Result.Text); } else { log = this.customModelLogText; this.SetCurrentText(this.customModelCurrentText, e.Result.Text); } this.WriteLine(log); this.WriteLine(log, $" --- Final result received. Status: {e.Result.RecognitionStatus.ToString()}. --- "); if (!string.IsNullOrEmpty(e.Result.Text)) { this.WriteLine(log, e.Result.Text); } }
/// <summary> /// Subscribes to Recognition Events /// Starts the Recognition and waits until Final Result is received, then Stops recognition /// </summary> /// <param name="recognizer">Recognizer object</param> /// <param name="recoType">Type of Recognizer</param> /// <value> /// <c>Base</c> if Baseline model; otherwise, <c>Custom</c>. /// </value> private async Task RunRecognizer(SpeechRecognizer recognizer, RecoType recoType, TaskCompletionSource <int> source) { //subscribe to events bool isChecked = false; this.Dispatcher.Invoke(() => { isChecked = this.immediateResultsCheckBox.IsChecked == true; }); if (isChecked) { recognizer.IntermediateResultReceived += (sender, e) => IntermediateResultEventHandler(e, recoType); } recognizer.FinalResultReceived += (sender, e) => FinalResultEventHandler(e, recoType); recognizer.RecognitionErrorRaised += (sender, e) => ErrorEventHandler(e, recoType, source); recognizer.OnSessionEvent += (sender, e) => SessionEventHandler(e, recoType, source); recognizer.OnSpeechDetectedEvent += (sender, e) => SpeechDetectedEventHandler(e, recoType); //start,wait,stop recognition await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false); await source.Task.ConfigureAwait(false); await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false); this.EnableButtons(); // unsubscribe from events if (isChecked) { recognizer.IntermediateResultReceived -= (sender, e) => IntermediateResultEventHandler(e, recoType); } recognizer.FinalResultReceived -= (sender, e) => FinalResultEventHandler(e, recoType); recognizer.RecognitionErrorRaised -= (sender, e) => ErrorEventHandler(e, recoType, source); recognizer.OnSessionEvent -= (sender, e) => SessionEventHandler(e, recoType, source); recognizer.OnSpeechDetectedEvent -= (sender, e) => SpeechDetectedEventHandler(e, recoType); }
/// <summary> /// Logs the final recognition result /// </summary> private void RecognizedEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { if (rt == RecoType.Base) { Console.WriteLine(e.Result.Text); } else { Console.WriteLine(e.Result.Text); } Console.WriteLine($" --- Final result received. Reason: {e.Result.Reason.ToString()}. --- "); if (!string.IsNullOrEmpty(e.Result.Text)) { //this.WriteLine(log, e.Result.Text); Console.WriteLine(e.Result.Text); } // if access to the JSON is needed it can be obtained from Properties string json = e.Result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult); }
private void RecognizedEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { if (rt == RecoType.Base) { //log = this.baseModelLogText; //this.SetCurrentText(this.baseModelCurrentText, e.Result.Text); } else { //log = this.customModelLogText; //this.SetCurrentText(this.customModelCurrentText, e.Result.Text); } //this.WriteLine(log); //this.WriteLine(log, $" --- Final result received. Reason: {e.Result.Reason.ToString()}. --- "); //if (!string.IsNullOrEmpty(e.Result.Text)) //{ // this.WriteLine(log, e.Result.Text); //} Debug.Log("RecognizedEventHandler" + e.Result.Text); resultText = e.Result.Text; }
/// <summary> /// Logs intermediate recognition results /// </summary> private void RecognizingEventHandler(SpeechRecognitionEventArgs e, RecoType rt) { var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; this.WriteLine(log, "Intermediate result: {0} ", e.Result.Text); }
private void SpeechDetectedEventHandler(RecognitionEventArgs e, RecoType rt) { var log = (rt == RecoType.Base) ? this.baseModelLogText : this.customModelLogText; this.WriteLine(log, String.Format("Speech recognition: Speech event: {0}.", e.ToString())); }