mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Merge pull request #8559 from ivandrofly/text-to-speech
Implement IDisposable pattern on HttpClient usage
This commit is contained in:
commit
7603bdfda9
@ -933,7 +933,8 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
private bool GenerateParagraphAudioCoqui(Subtitle subtitle, bool showProgressBar, string overrideFileName)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.BaseAddress = new Uri(nikseComboBoxVoice.Text.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? nikseComboBoxVoice.Text : "http://localhost:5002/api/tts");
|
||||
|
||||
progressBar1.Value = 0;
|
||||
@ -977,10 +978,12 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool GenerateParagraphAudioAllTalk(Subtitle subtitle, bool showProgressBar, string overrideFileName)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.BaseAddress = new Uri("http://127.0.0.1:7851");
|
||||
|
||||
progressBar1.Value = 0;
|
||||
@ -1054,6 +1057,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool GenerateParagraphAudioElevenLabs(Subtitle subtitle, bool showProgressBar, string overrideFileName)
|
||||
{
|
||||
@ -1064,7 +1068,8 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
return false;
|
||||
}
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "audio/mpeg");
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("xi-api-key", nikseTextBoxApiKey.Text.Trim());
|
||||
@ -1131,6 +1136,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private List<AzureVoiceModel> GetAzureVoices(bool useCache)
|
||||
{
|
||||
@ -1233,7 +1239,8 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
return false;
|
||||
}
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "ssml+xml");
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "audio/mpeg");
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-Microsoft-OutputFormat", "audio-16khz-32kbitrate-mono-mp3");
|
||||
@ -1301,6 +1308,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonOK_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -1806,7 +1814,8 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
if (!useCache)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
|
||||
var url = "https://huggingface.co/rhasspy/piper-voices/resolve/main/voices.json?download=true";
|
||||
@ -1823,6 +1832,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
File.WriteAllBytes(jsonFileName, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(jsonFileName))
|
||||
{
|
||||
@ -1903,7 +1913,8 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
if (!useCache)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
|
||||
|
||||
@ -1927,6 +1938,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
File.WriteAllBytes(jsonFileName, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(jsonFileName))
|
||||
{
|
||||
@ -1991,7 +2003,8 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
if (!useCache)
|
||||
{
|
||||
var httpClient = new HttpClient();
|
||||
using(var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
|
||||
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");
|
||||
|
||||
@ -2010,6 +2023,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
|
||||
File.WriteAllBytes(jsonFileName, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(jsonFileName))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user