From 2dddf56a611ecf02d03e450c849cb69bc2643b2d Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Tue, 30 Apr 2024 20:14:59 +0200 Subject: [PATCH] Fix Azure voice refresh --- src/ui/Forms/GenerateVideoWithHardSubs.cs | 6 ++--- src/ui/Forms/Tts/TextToSpeech.cs | 30 +++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ui/Forms/GenerateVideoWithHardSubs.cs b/src/ui/Forms/GenerateVideoWithHardSubs.cs index e5b64fa2e..05469f902 100644 --- a/src/ui/Forms/GenerateVideoWithHardSubs.cs +++ b/src/ui/Forms/GenerateVideoWithHardSubs.cs @@ -2154,7 +2154,7 @@ namespace Nikse.SubtitleEdit.Forms { return; } - + var batchVideoAndSub = CreateBatchVideoAndSub(videoFileName); var listViewItem = new ListViewItem(videoFileName) { Tag = batchVideoAndSub }; listViewItem.SubItems.Add(videoDimension.ToString()); @@ -2176,7 +2176,7 @@ namespace Nikse.SubtitleEdit.Forms }; var path = Path.GetDirectoryName(videoFileName); - // try to locate subtitle file for the input vide file + // try to locate subtitle file for the input video file var subtitleFile = FileUtil.TryLocateSubtitleFile(path, videoFileName); if (File.Exists(subtitleFile)) { @@ -2187,7 +2187,7 @@ namespace Nikse.SubtitleEdit.Forms return batchVideoAndSub; } - private Dimension GetVideoDimension(string videoFileName) + private static Dimension GetVideoDimension(string videoFileName) { var mediaInfo = FfmpegMediaInfo.Parse(videoFileName); if (mediaInfo.Dimension.IsValid()) diff --git a/src/ui/Forms/Tts/TextToSpeech.cs b/src/ui/Forms/Tts/TextToSpeech.cs index 8ddebe2cd..1d186b10b 100644 --- a/src/ui/Forms/Tts/TextToSpeech.cs +++ b/src/ui/Forms/Tts/TextToSpeech.cs @@ -973,12 +973,9 @@ namespace Nikse.SubtitleEdit.Forms.Tts if (!useCache) { var httpClient = new HttpClient(); - httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); - httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json"); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Ocp-Apim-Subscription-Key", nikseTextBoxApiKey.Text.Trim()); - var url = $"https://{nikseComboBoxRegion.Text.Trim()}.tts.speech.microsoft.com/cognitiveservices/voices/list"; - var result = await httpClient.GetAsync(new Uri(url), CancellationToken.None); + var result = httpClient.GetAsync(new Uri(url)).Result; var bytes = await result.Content.ReadAsByteArrayAsync(); if (!result.IsSuccessStatusCode) @@ -1858,14 +1855,14 @@ namespace Nikse.SubtitleEdit.Forms.Tts nikseComboBoxVoice.DropDownWidth = nikseComboBoxVoice.Width; } - private void RefreshVoices() + private bool RefreshVoices() { if (nikseTextBoxApiKey.Visible && string.IsNullOrWhiteSpace(nikseTextBoxApiKey.Text)) { Cursor = Cursors.Default; MessageBox.Show("Please add API key"); nikseTextBoxApiKey.Focus(); - return; + return false; } var engine = _engines.First(p => p.Index == nikseComboBoxEngine.SelectedIndex); @@ -1876,7 +1873,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts Cursor = Cursors.Default; MessageBox.Show("Please add region"); nikseComboBoxRegion.Focus(); - return; + return false; } var _ = GetAzureVoices(false).Result; @@ -1887,16 +1884,16 @@ namespace Nikse.SubtitleEdit.Forms.Tts GetElevenLabVoices(false); nikseComboBoxEngine_SelectedIndexChanged(null, null); } + + return true; } private void contextMenuStripVoices_Opening(object sender, System.ComponentModel.CancelEventArgs e) { var engine = _engines.First(p => p.Index == nikseComboBoxEngine.SelectedIndex); - if ( - //engine.Id == TextToSpeechEngineId.AzureTextToSpeech || + if (engine.Id == TextToSpeechEngineId.AzureTextToSpeech || engine.Id == TextToSpeechEngineId.ElevenLabs || - engine.Id == TextToSpeechEngineId.Piper - ) + engine.Id == TextToSpeechEngineId.Piper) { return; } @@ -1915,15 +1912,18 @@ namespace Nikse.SubtitleEdit.Forms.Tts try { Cursor = Cursors.WaitCursor; - RefreshVoices(); + var ok = RefreshVoices(); Cursor = Cursors.Default; - MessageBox.Show(this, "Voice list downloaded"); + if (ok) + { + MessageBox.Show(this, "Voice list downloaded"); + } } catch (Exception ex) { Cursor = Cursors.Default; - MessageBox.Show(this, "Voice list download failed!" + Environment.NewLine + - Environment.NewLine + + MessageBox.Show(this, "Voice list download failed!" + Environment.NewLine + + Environment.NewLine + ex.Message); } finally