private void CancelButton_Click(object sender, RoutedEventArgs e) { if (audioListView.IsVisible) { List <IVoice> rankedAudioListCacheCopy = rankedAudioListCache.Select(x => (IVoice)x.Clone()).ToList(); AudioSettingService.preferredVoices = new ObservableCollection <IVoice>(rankedAudioListCacheCopy); } if ((AudioSettingService.selectedVoiceType == VoiceType.AzureVoice && !AzureRuntimeService.IsAzureAccountPresent()) || (AudioSettingService.selectedVoiceType == VoiceType.WatsonVoice && !WatsonRuntimeService.IsWatsonAccountPresent())) { ComputerVoice defaultVoiceSelected = computerVoiceComboBox.SelectedItem as ComputerVoice; DialogConfirmedHandler(VoiceType.ComputerVoice, defaultVoiceSelected, previewCheckbox.IsChecked.GetValueOrDefault()); } }
private void SpeakButton_Click(object sender, RoutedEventArgs e) { string textToSpeak = spokenText.Text.Trim(); if (string.IsNullOrEmpty(textToSpeak)) { return; } IVoice voice = ((Button)sender).CommandParameter as IVoice; if (voice == null) { voice = SelectedVoice; } if (voice is ComputerVoice) { ComputerVoiceRuntimeService.SpeakString(textToSpeak, voice as ComputerVoice); } else if (voice is AzureVoice && !IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName)) { AzureRuntimeService.SpeakString(textToSpeak, voice as AzureVoice); } else if (voice is AzureVoice && IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName)) { string dirPath = System.IO.Path.GetTempPath() + AudioService.TempFolderName; string filePath = dirPath + "\\" + string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName); AzureRuntimeService.PlaySavedAudioForPreview(filePath); } else if (voice is WatsonVoice && !IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName)) { WatsonRuntimeService.Speak(textToSpeak, voice as WatsonVoice); } else if (voice is WatsonVoice && IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName)) { string dirPath = System.IO.Path.GetTempPath() + AudioService.TempFolderName; string filePath = dirPath + "\\" + string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName); AzureRuntimeService.PlaySavedAudioForPreview(filePath); } }
public static void SaveStringToWaveFiles(string notesText, string folderPath, string fileNameFormat) { TaggedText taggedNotes = new TaggedText(notesText); List <string> stringsToSave = taggedNotes.SplitByClicks(); //MD5 md5 = MD5.Create(); for (int i = 0; i < stringsToSave.Count; i++) { string textToSave = stringsToSave[i]; string baseFileName = string.Format(fileNameFormat, i + 1); // The first item will autoplay; everything else is triggered by a click. string fileName = i > 0 ? baseFileName + " (OnClick)" : baseFileName; string filePath = folderPath + "\\" + fileName + ".wav"; switch (AudioSettingService.selectedVoiceType) { case VoiceType.ComputerVoice: ComputerVoiceRuntimeService.SaveStringToWaveFile(textToSave, filePath, AudioSettingService.selectedVoice as ComputerVoice); break; case VoiceType.AzureVoice: AzureRuntimeService.SaveStringToWaveFileWithAzureVoice(textToSave, filePath, AudioSettingService.selectedVoice as AzureVoice); break; case VoiceType.WatsonVoice: WatsonRuntimeService.SaveStringToWaveFile(textToSave, filePath, AudioSettingService.selectedVoice as WatsonVoice); break; default: break; } } }
private void ConfirmButton_Click(object sender, RoutedEventArgs e) { string _endpoint = ""; string _key = ""; try { _key = key.Text.Trim(); string region = ((ComboBoxItem)endpoint.SelectedItem).Content.ToString().Trim(); _endpoint = EndpointToUriConverter.watsonRegionToEndpointMapping[region]; } catch { MessageBox.Show("Key or Region cannot be empty!", "Invalid Input"); return; } bool isValidAccount = WatsonRuntimeService.IsValidUserAccount(_key, _endpoint, "Invalid Watson Account.\nIs your Watson account expired?\nAre you connected to Wifi?"); if (isValidAccount) { // Delete previous user account WatsonAccount.GetInstance().Clear(); WatsonAccountStorageService.DeleteUserAccount(); // Create and save new user account string _region = ((ComboBoxItem)endpoint.SelectedItem).Content.ToString().Trim(); WatsonAccount.GetInstance().SetUserKeyAndRegion(_key, _region); WatsonAccountStorageService.SaveUserAccount(WatsonAccount.GetInstance()); WatsonRuntimeService.IsWatsonAccountPresentAndValid = true; SwitchViewToPreviousPage(); } else { MessageBox.Show("Invalid Watson Account.\nIs your Watson account expired?\nAre you connected to Wifi?"); } }
public static void LoadUserAccount() { if (!WatsonAccount.GetInstance().IsEmpty()) { return; } Dictionary <string, string> user = new Dictionary <string, string>(); try { FileStream file = File.Open(GetAccessKeyFilePath(), FileMode.Open); XElement root = XElement.Load(file); foreach (XElement el in root.Elements()) { user.Add(el.Name.LocalName, el.Value); } string key = user.ContainsKey("key") ? user["key"] : null; string endpoint = user.ContainsKey("endpoint") ? user["endpoint"] : null; if (key != null && endpoint != null) { WatsonAccount.GetInstance().SetUserKeyAndRegion(key, endpoint); WatsonRuntimeService.IsWatsonAccountPresentAndValid = WatsonRuntimeService.IsValidUserAccount(errorMessage: "Invalid Watson Account." + "\nIs your Watson account expired?\nAre you connected to Wifi?"); } else { WatsonRuntimeService.IsWatsonAccountPresentAndValid = false; File.Delete(GetAccessKeyFilePath()); } } catch (Exception e) { WatsonRuntimeService.IsWatsonAccountPresentAndValid = false; Logger.Log(e.Message); } }