public SpeechToTextExplorer() { this.InitializeComponent(); this.DataContext = this; TranslationLanguagesCollection.AddRange(supportedLanguages.Where(x => x.Code != CurrentInputLanguage?.Code)); AudioSampleCollection.AddRange(audioSamples.Where(x => x.LanguageCode == CurrentInputLanguage?.Code)); }
private void CurrentInputLanguageChanged() { // update the text boxes RecognitionData inputData; switch (SpeechExplorerState) { case SpeechExplorerState.Initial: case SpeechExplorerState.SpeechToText: inputData = this.speechToTextView.GetRecognizedData(); if (!string.IsNullOrEmpty(inputData?.Text) && !Regex.IsMatch(inputData.Text, @"[()]")) { inputData.Text = inputData.Language != null ? $"({inputData.Language.Name}) {inputData.Text}" : inputData.Text; inputData.HighlightStyle = true; this.speechToTextView.SetRecognitionData(inputData); } break; case SpeechExplorerState.SpeechToTextWithTranslation: inputData = this.speechToTextWithTranslation.GetRecognizedData(); if (!string.IsNullOrEmpty(inputData?.Text) && !Regex.IsMatch(inputData.Text, @"[()]")) { inputData.Text = inputData.Language != null ? $"({inputData.Language.Name}) {inputData.Text}" : inputData.Text; inputData.HighlightStyle = true; this.speechToTextWithTranslation.SetRecognitionData(inputData, null); } break; } // update audio samples AudioSampleCollection.Clear(); AudioSampleCollection.AddRange(audioSamples.Where(x => x.LanguageCode == CurrentInputLanguage?.Code)); // update translation languages string firstLangCode = FirstTranslationLanguage?.Code; string secondLangCode = SecondTranslationLanguage?.Code; TranslationLanguagesCollection.Clear(); TranslationLanguagesCollection.AddRange(supportedLanguages.Where(x => x.Code != CurrentInputLanguage?.Code)); FirstTranslationLanguage = CurrentInputLanguage?.Code == firstLangCode ? TranslationLanguagesCollection.FirstOrDefault() : TranslationLanguagesCollection.FirstOrDefault(x => x.Code == firstLangCode); SecondTranslationLanguage = CurrentInputLanguage?.Code == secondLangCode ? TranslationLanguagesCollection.LastOrDefault() : TranslationLanguagesCollection.FirstOrDefault(x => x.Code == secondLangCode); }