private async void OnTranslateRecognizing(object sender, TranslationRecognitionEventArgs args) { if (args.Result.Reason == ResultReason.TranslatingSpeech) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // origin if (!string.IsNullOrEmpty(args.Result.Text)) { recognitionData = new RecognitionData(dictatedTextBuilder.ToString(), null); UpdateTextBox(this.dictationTextBlock, recognitionData, args.Result.Text); } // translation var firstLanguage = this.firstTranslateLanguageCombobox.SelectedItem as SupportedLanguage; var secondLanguage = this.secondTranslateLanguageCombobox.SelectedItem as SupportedLanguage; var translations = args.Result.Translations; foreach (var translation in translations) { if (firstLanguage != null && firstLanguage.TranslationCode.Contains(translation.Key) && !string.IsNullOrEmpty(translation.Value)) { firstTranslationRecognitionData = new RecognitionData(firstTranslatedTextBuilder.ToString(), null); UpdateTextBox(this.firstTranslationTextBlock, firstTranslationRecognitionData, translation.Value); } if (secondLanguage != null && secondLanguage.TranslationCode.Contains(translation.Key) && !string.IsNullOrEmpty(translation.Value)) { secondTranslationRecognitionData = new RecognitionData(secondTranslatedTextBuilder.ToString(), null); UpdateTextBox(this.secondTranslationTextBlock, secondTranslationRecognitionData, translation.Value); } } }); } }
// "Recognized" events are fired when the utterance end was detected by the server private void RecognizedTranslationHandler(object sender, TranslationRecognitionEventArgs e) { if (e.Result.Reason == ResultReason.TranslatedSpeech) { Debug.Log($"RECOGNIZED: Text={e.Result.Text}"); lock (threadLocker) { recognizedString = $"RECOGNIZED RESULT ({fromLanguage}): {Environment.NewLine}{e.Result.Text}"; recognizedString += $"{Environment.NewLine}TRANSLATED RESULTS:"; foreach (var element in e.Result.Translations) { recognizedString += $"{Environment.NewLine}[{element.Key}]: {element.Value}"; } } } else if (e.Result.Reason == ResultReason.RecognizedSpeech) { Debug.Log($"RECOGNIZED: Text={e.Result.Text}"); lock (threadLocker) { recognizedString = $"NON-TRANSLATED RESULT: {Environment.NewLine}{e.Result.Text}"; } } else if (e.Result.Reason == ResultReason.NoMatch) { Debug.Log($"NOMATCH: Speech could not be recognized or translated."); } }
/// <summary> /// Called on final response. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="TranslationRecognitionEventArgs"/> instance containing the event data.</param> private void OnRecognizedEventHandler(object sender, TranslationRecognitionEventArgs e) { //if (e.Result.Text.Length == 0) //{ // this.WriteLine(this.crisLogText, "Reason: " + e.Result.Reason); // this.WriteLine(this.crisLogText, "No phrase response is available."); //} //else //{ // string text = e.Result.Text; // foreach (var t in e.Result.Translations) // { // text += $"\nSame in {t.Key}: {t.Value}"; // } // this.SetCurrentText(this.crisCurrentText, text); // text += "\n"; // this.WriteLine(this.crisLogText, text); //} orignalText = e.Result.Text; foreach (var t in e.Result.Translations) { resultText = t.Value; break; //text = $"\nSame in {t.Key}: {t.Value}"; } //resultText = e.Result.Translations[e.Result.Translations]; Debug.Log(e.Result.Text); }
private void RecognizedHandler(object sender, TranslationRecognitionEventArgs e) { lock (_threadLocker) { _message = $"{e.Result.Text} \n {e.Result.Translations["en"]}"; Debug.Log("RecognizedHandler: " + _message); } }
/// <summary> /// Hello. /// </summary> /// <param name="sender">sender.</param> /// <param name="e">e.</param> private void MSpeechRecognizer_Recognized(object sender, TranslationRecognitionEventArgs e) { var t = Task.Run(() => this.PersistAsync(e.Result.Text, e.Result.Translations)); t.Wait(); this.ResetCurrentTranscriptionEntity(); }
/// <summary> /// Called when a partial response is received. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="TranslationRecognitionEventArgs"/> instance containing the event data.</param> private void OnRecognizingEventHandler(object sender, TranslationRecognitionEventArgs e) { //string text = e.Result.Text; //foreach (var t in e.Result.Translations) //{ // text += $"\nSame in {t.Key}: {t.Value}"; //} //this.SetCurrentText(this.crisCurrentText, text); }
private void RecognisingTranslationHandler(object sender, TranslationRecognitionEventArgs e) { if (e.Result.Text != null) { this.RecognisedSpeech?.Invoke(e.Result.Text); } if (e.Result.Translations[toLanguage] != null) { this.RecognisedTranslation?.Invoke(e.Result.Translations[toLanguage]); } }
private void HandleTranslatorRecognized(object s, TranslationRecognitionEventArgs e) { if (e.Result.Reason == ResultReason.TranslatedSpeech) { recognizedString = e.Result.Text; foreach (var element in e.Result.Translations) { translatedString = element.Value; } } }
private void RecognizedHandler(object sender, TranslationRecognitionEventArgs e) { Debug.Log("recognized : " + e.Result.Text); if (e.Result.Reason == ResultReason.TranslatedSpeech) { translatedMessage = ""; foreach (var element in e.Result.Translations) { Debug.Log(" translations : " + element.Key + " -> " + element.Value); translatedMessage += element.Value; } } }
// "Recognizing" events are fired every time we receive interim results during recognition (i.e. hypotheses) private void RecognizingTranslationHandler(object sender, TranslationRecognitionEventArgs e) { if (e.Result.Reason == ResultReason.TranslatingSpeech) { Debug.Log($"RECOGNIZED HYPOTHESIS: Text={e.Result.Text}"); lock (threadLocker) { recognizedString = $"RECOGNIZED HYPOTHESIS ({fromLanguage}): {Environment.NewLine}{e.Result.Text}"; recognizedString += $"{Environment.NewLine}TRANSLATED HYPOTHESESE:"; foreach (var element in e.Result.Translations) { recognizedString += $"{Environment.NewLine}[{element.Key}]: {element.Value}"; } } } }
private void RecognizingHandler(object sender, TranslationRecognitionEventArgs e) { Debug.Log("recognizing : reason = " + e.Result.Reason + ", text = " + e.Result.Text); lock (threadLocker) { if (e.Result.Reason == ResultReason.TranslatingSpeech) { translatedMessage = ""; translatingMessage = ""; foreach (var element in e.Result.Translations) { Debug.Log(" translations : " + element.Key + " -> " + element.Value); translatingMessage += element.Value; } } } }
private void RecognizerRecognized(object sender, TranslationRecognitionEventArgs e) { var translationLanguage = _languageTranslated.Split("-")[0]; var translation = e.Result.Translations[translationLanguage].ToString(); Trace.WriteLine("Recognized: " + translation); var ttsAudio = _synthesizer.SpeakTextAsync(translation).Result.AudioData; var translationResult = new Translation { LanguageSpoken = _languageSpoken, LanguageTranslated = _languageTranslated, Text = translation, UUID = _uuid }; _hub.Clients.All.SendAsync("receiveTranslation", translationResult); _audioToWrite.Enqueue(ttsAudio); }
/// <summary> /// Called on final response. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="TranslationRecognitionEventArgs"/> instance containing the event data.</param> private void OnRecognizedEventHandler(object sender, TranslationRecognitionEventArgs e) { if (e.Result.Text.Length == 0) { this.WriteLine(this.crisLogText, "Reason: " + e.Result.Reason); this.WriteLine(this.crisLogText, "No phrase response is available."); } else { string text = e.Result.Text; foreach (var t in e.Result.Translations) { text += $"\nSame in {t.Key}: {t.Value}"; } this.SetCurrentText(this.crisCurrentText, text); text += "\n"; this.WriteLine(this.crisLogText, text); } }
private void OnSpeechRecognizing(object sender, TranslationRecognitionEventArgs e) { Recognizing?.Invoke(sender, e); }
private void OnRecognized(object sender, TranslationRecognitionEventArgs e) { SendMessage(e.ToString()); }
private void CanceledHandler(object sender, TranslationRecognitionEventArgs e) { Debug.Log("recognizer canceled"); }
private void HandleTranslatorCanceled(object s, TranslationRecognitionEventArgs e) { UnityEngine.Debug.Log("HandleTranslatorCanceled called"); }