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.azureRegionToEndpointMapping[region]; } catch { MessageBox.Show("Key or Region cannot be empty!", "Invalid Input"); return; } if (AzureRuntimeService.IsValidUserAccount(_key, _endpoint)) { // Delete previous user account AzureAccount.GetInstance().Clear(); AzureAccountStorageService.DeleteUserAccount(); // Create and save new user account string _region = ((ComboBoxItem)endpoint.SelectedItem).Content.ToString().Trim(); AzureAccount.GetInstance().SetUserKeyAndRegion(_key, _region); AzureAccountStorageService.SaveUserAccount(AzureAccount.GetInstance()); AzureRuntimeService.IsAzureAccountPresentAndValid = true; SwitchViewToPreviousPage(); } else { MessageBox.Show("Invalid Azure Account.\nIs your account expired?\nAre you connected to WiFi?"); } }
private void LogOutAzureAccountButton_Click(object sender, RoutedEventArgs e) { AzureAccount.GetInstance().Clear(); AzureAccountStorageService.DeleteUserAccount(); azureVoiceComboBox.Visibility = Visibility.Collapsed; azureVoiceBtn.Visibility = Visibility.Visible; changeAcctBtn.Visibility = Visibility.Hidden; logoutBtn.Visibility = Visibility.Hidden; RadioAzureVoice.IsEnabled = false; RadioDefaultVoice.IsChecked = true; AzureRuntimeService.IsAzureAccountPresentAndValid = false; }
public static void SpeakStringAsync(string textToSpeak, AzureVoice voice) { RenewCancellationToken(); string accessToken; string dirPath = Path.GetTempPath() + AudioService.TempFolderName; string filePath = dirPath + "\\" + string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName); try { AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance(); accessToken = auth.GetAccessToken(); Logger.Log("Token: " + accessToken); } catch { Logger.Log("Failed authentication."); return; } if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string requestUri = AzureAccount.GetInstance().GetUri(); if (requestUri == null) { return; } var azureVoiceSynthesizer = new SynthesizeAzureVoice(); azureVoiceSynthesizer.OnAudioAvailable += PlayAudio; azureVoiceSynthesizer.OnError += OnAzureVoiceErrorHandler; // Reuse Synthesize object to minimize latency azureVoiceSynthesizer.Speak(token, new InputOptions() { RequestUri = new Uri(requestUri), Text = textToSpeak, VoiceType = voice.voiceType, Locale = voice.Locale, VoiceName = voice.voiceName, // Service can return audio in different output format. OutputFormat = AudioOutputFormat.Riff24Khz16BitMonoPcm, AuthorizationToken = "Bearer " + accessToken, }, filePath).Wait(); }
public static void EmbedSelectedSlideNotes() { List <PowerPointSlide> slides = PowerPointCurrentPresentationInfo.SelectedSlides.ToList(); if (AudioSettingService.selectedVoiceType == AudioGenerator.VoiceType.AzureVoice && AzureAccount.GetInstance().IsEmpty()) { MessageBox.Show("Invalid user account. Please log in again."); throw new Exception("Invalid user account."); } int numberOfSlides = slides.Count; ProcessingStatusForm progressBarForm = new ProcessingStatusForm(numberOfSlides, BackgroundWorkerType.AudioGenerationService); progressBarForm.ShowThematicDialog(false); }
public static bool SaveStringToWaveFileWithAzureVoice(string textToSave, string filePath, AzureVoice voice) { RenewCancellationToken(); string accessToken; string textToSpeak = GetHumanSpeakNotesForText(textToSave); try { AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance(); accessToken = auth.GetAccessToken(); Logger.Log("Token: " + accessToken); } catch { Logger.Log("Failed authentication."); return(false); } string requestUri = AzureAccount.GetInstance().GetUri(); if (requestUri == null) { return(false); } var azureVoiceSynthesizer = new SynthesizeAzureVoice(); azureVoiceSynthesizer.OnAudioAvailable += SaveAudioToWaveFile; azureVoiceSynthesizer.OnError += OnAzureVoiceErrorHandler; // Reuse Synthesize object to minimize latency azureVoiceSynthesizer.Speak(token, new InputOptions() { RequestUri = new Uri(requestUri), Text = textToSpeak, VoiceType = voice.voiceType, Locale = voice.Locale, VoiceName = voice.voiceName, // Service can return audio in different output format. OutputFormat = AudioOutputFormat.Riff24Khz16BitMonoPcm, AuthorizationToken = "Bearer " + accessToken, }, filePath).Wait(); return(true); }
public static bool IsValidUserAccount(bool showErrorMessage = true, string errorMessage = "Failed Azure authentication.") { try { string _key = AzureAccount.GetInstance().GetKey(); string _endpoint = EndpointToUriConverter.azureRegionToEndpointMapping[AzureAccount.GetInstance().GetRegion()]; AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance(_endpoint, _key); string accessToken = auth.GetAccessToken(); Console.WriteLine("Token: {0}\n", accessToken); } catch { Console.WriteLine(errorMessage); if (showErrorMessage) { MessageBox.Show(errorMessage); } return(false); } return(true); }
public static void LoadUserAccount() { if (!AzureAccount.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"].Trim() : null; if (key != null && endpoint != null) { AzureAccount.GetInstance().SetUserKeyAndRegion(key, endpoint); AzureRuntimeService.IsAzureAccountPresentAndValid = AzureRuntimeService.IsValidUserAccount(errorMessage: "Invalid Azure Account." + "\nIs your Azure account expired?\nAre you connected to Wifi?"); } else { AzureRuntimeService.IsAzureAccountPresentAndValid = false; File.Delete(GetAccessKeyFilePath()); } } catch (Exception e) { AzureRuntimeService.IsAzureAccountPresentAndValid = false; Logger.Log(e.Message); } }
protected override void ExecuteAction(string ribbonId) { if (AudioSettingService.selectedVoiceType == VoiceType.AzureVoice && AzureAccount.GetInstance().IsEmpty()) { MessageBox.Show("Invalid user account. Please log in again."); return; } //TODO: This needs to improved to stop using global variables this.StartNewUndoEntry(); PowerPointSlide currentSlide = this.GetCurrentSlide(); // If there are text in notes page for any of the selected slides if (this.GetCurrentPresentation().SelectedSlides.Any(slide => slide.NotesPageText.Trim() != "")) { ComputerVoiceRuntimeService.IsRemoveAudioEnabled = true; this.GetRibbonUi().RefreshRibbonControl("RemoveNarrationsButton"); } try { ComputerVoiceRuntimeService.EmbedSelectedSlideNotes(); } catch { MessageBox.Show("Failed to generate audio files."); return; } CustomTaskPane recorderPane = this.GetAddIn().GetActivePane(typeof(RecorderTaskPane)); if (recorderPane == null) { return; } RecorderTaskPane recorder = recorderPane.Control as RecorderTaskPane; if (recorder == null) { return; } // initialize selected slides' audio List <string[]> allAudioFiles = ComputerVoiceRuntimeService.ExtractSlideNotes(); recorder.InitializeAudioAndScript(this.GetCurrentPresentation().SelectedSlides.ToList(), allAudioFiles, true); // if current list is visible, update the pane immediately if (recorderPane.Visible) { recorder.UpdateLists(currentSlide.ID); } if (AudioSettingService.IsPreviewEnabled) { ComputerVoiceRuntimeService.PreviewAnimations(); } }
public static bool IsAzureAccountPresent() { return(!AzureAccount.GetInstance().IsEmpty()); }