Work on murf TTS

This commit is contained in:
Nikolaj Olsson 2024-11-08 08:04:30 +01:00
parent 54d09cfe28
commit 0af4540cdf
5 changed files with 116 additions and 17 deletions

View File

@ -2377,6 +2377,24 @@ namespace Nikse.SubtitleEdit.Core.Settings
settings.Tools.TextToSpeechMurfApiKey = subNode.InnerText; settings.Tools.TextToSpeechMurfApiKey = subNode.InnerText;
} }
subNode = node.SelectSingleNode("TextToSpeechMurfVoice");
if (subNode != null)
{
settings.Tools.TextToSpeechMurfVoice = subNode.InnerText;
}
subNode = node.SelectSingleNode("TextToSpeechMurfRate");
if (subNode != null)
{
settings.Tools.TextToSpeechMurfRate = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("TextToSpeechMurfPitch");
if (subNode != null)
{
settings.Tools.TextToSpeechMurfPitch = Convert.ToInt32(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("TextToSpeechAzureApiKey"); subNode = node.SelectSingleNode("TextToSpeechAzureApiKey");
if (subNode != null) if (subNode != null)
{ {
@ -9061,6 +9079,9 @@ namespace Nikse.SubtitleEdit.Core.Settings
xmlWriter.WriteElementString("TextToSpeechElevenLabsStability", settings.Tools.TextToSpeechElevenLabsStability.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteElementString("TextToSpeechElevenLabsStability", settings.Tools.TextToSpeechElevenLabsStability.ToString(CultureInfo.InvariantCulture));
xmlWriter.WriteElementString("TextToSpeechElevenLabsSimilarity", settings.Tools.TextToSpeechElevenLabsSimilarity.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteElementString("TextToSpeechElevenLabsSimilarity", settings.Tools.TextToSpeechElevenLabsSimilarity.ToString(CultureInfo.InvariantCulture));
xmlWriter.WriteElementString("TextToSpeechMurfApiKey", settings.Tools.TextToSpeechMurfApiKey); xmlWriter.WriteElementString("TextToSpeechMurfApiKey", settings.Tools.TextToSpeechMurfApiKey);
xmlWriter.WriteElementString("TextToSpeechMurfVoice", settings.Tools.TextToSpeechMurfVoice);
xmlWriter.WriteElementString("TextToSpeechMurfRate", settings.Tools.TextToSpeechMurfRate.ToString(CultureInfo.InvariantCulture));
xmlWriter.WriteElementString("TextToSpeechMurfPitch", settings.Tools.TextToSpeechMurfPitch.ToString(CultureInfo.InvariantCulture));
xmlWriter.WriteElementString("TextToSpeechAzureApiKey", settings.Tools.TextToSpeechAzureApiKey); xmlWriter.WriteElementString("TextToSpeechAzureApiKey", settings.Tools.TextToSpeechAzureApiKey);
xmlWriter.WriteElementString("TextToSpeechAzureRegion", settings.Tools.TextToSpeechAzureRegion); xmlWriter.WriteElementString("TextToSpeechAzureRegion", settings.Tools.TextToSpeechAzureRegion);
xmlWriter.WriteElementString("TextToSpeechPreview", settings.Tools.TextToSpeechPreview.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteElementString("TextToSpeechPreview", settings.Tools.TextToSpeechPreview.ToString(CultureInfo.InvariantCulture));

View File

@ -100,6 +100,9 @@ namespace Nikse.SubtitleEdit.Core.Settings
public string TextToSpeechLastVoice { get; set; } public string TextToSpeechLastVoice { get; set; }
public string TextToSpeechElevenLabsApiKey { get; set; } public string TextToSpeechElevenLabsApiKey { get; set; }
public string TextToSpeechMurfApiKey { get; set; } public string TextToSpeechMurfApiKey { get; set; }
public int TextToSpeechMurfRate { get; set; }
public int TextToSpeechMurfPitch { get; set; }
public string TextToSpeechMurfVoice { get; set; }
public string TextToSpeechAzureApiKey { get; set; } public string TextToSpeechAzureApiKey { get; set; }
public string TextToSpeechAzureRegion { get; set; } public string TextToSpeechAzureRegion { get; set; }
public string TextToSpeechElevenLabsModel { get; set; } public string TextToSpeechElevenLabsModel { get; set; }

View File

@ -142,7 +142,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
{ {
if (_whisperChoice == WhisperChoice.PurfviewFasterWhisperXXL) if (_whisperChoice == WhisperChoice.PurfviewFasterWhisperXXL)
{ {
UiUtil.OpenUrl("https://github.com/Purfview/whisper-standalone-win/releases/download/Faster-Whisper-XXL/Faster-Whisper-XXL_r192.3.4_windows.7z"); UiUtil.OpenUrl("https://github.com/Purfview/whisper-standalone-win/releases/download/Faster-Whisper-XXL/Faster-Whisper-XXL_r193.1_windows.7z");
var folder = Path.Combine(Configuration.DataDirectory, "Whisper"); var folder = Path.Combine(Configuration.DataDirectory, "Whisper");
if (!Directory.Exists(folder)) if (!Directory.Exists(folder))

View File

@ -15,6 +15,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
private readonly Subtitle _subtitle; private readonly Subtitle _subtitle;
private readonly int _index; private readonly int _index;
private LibMpvDynamic _libMpv; private LibMpvDynamic _libMpv;
private TextToSpeech.TextToSpeechEngine _engine;
public RegenerateAudioClip(TextToSpeech textToSpeech, Subtitle subtitle, int idx, TextToSpeech.TextToSpeechEngine engine) public RegenerateAudioClip(TextToSpeech textToSpeech, Subtitle subtitle, int idx, TextToSpeech.TextToSpeechEngine engine)
{ {
@ -25,6 +26,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
_subtitle = subtitle; _subtitle = subtitle;
_textToSpeech = textToSpeech; _textToSpeech = textToSpeech;
_index = idx; _index = idx;
_engine = engine;
Text = LanguageSettings.Current.ExportCustomText.Edit; Text = LanguageSettings.Current.ExportCustomText.Edit;
labelText.Text = LanguageSettings.Current.General.Text; labelText.Text = LanguageSettings.Current.General.Text;
@ -43,23 +45,47 @@ namespace Nikse.SubtitleEdit.Forms.Tts
nikseUpDownStability.Value = (int)Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsStability * 100.0); nikseUpDownStability.Value = (int)Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsStability * 100.0);
nikseUpDownSimilarity.Value = (int)Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity * 100.0); nikseUpDownSimilarity.Value = (int)Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity * 100.0);
if (engine.Id != TextToSpeech.TextToSpeechEngineId.ElevenLabs) if (engine.Id == TextToSpeech.TextToSpeechEngineId.ElevenLabs)
{ {
labelStability.Visible = false; return;
labelSimilarity.Visible = false;
nikseUpDownStability.Visible = false;
nikseUpDownSimilarity.Visible = false;
TextBoxReGenerate.Height = buttonOK.Top - TextBoxReGenerate.Top - 10;
nikseUpDownSimilarity.Left = labelSimilarity.Right + 3;
} }
if (engine.Id == TextToSpeech.TextToSpeechEngineId.Murf)
{
labelStability.Text = "Pitch";
nikseUpDownStability.Minimum = -49;
nikseUpDownStability.Maximum = 50;
nikseUpDownStability.Value = Configuration.Settings.Tools.TextToSpeechMurfPitch;
labelSimilarity.Text = "Speed";
nikseUpDownSimilarity.Minimum = -49;
nikseUpDownSimilarity.Maximum = 50;
nikseUpDownSimilarity.Value = Configuration.Settings.Tools.TextToSpeechMurfRate;
return;
}
labelStability.Visible = false;
labelSimilarity.Visible = false;
nikseUpDownStability.Visible = false;
nikseUpDownSimilarity.Visible = false;
TextBoxReGenerate.Height = buttonOK.Top - TextBoxReGenerate.Top - 10;
nikseUpDownSimilarity.Left = labelSimilarity.Right + 3;
} }
private void buttonReGenerate_Click(object sender, EventArgs e) private void buttonReGenerate_Click(object sender, EventArgs e)
{ {
_libMpv?.Stop(); _libMpv?.Stop();
Configuration.Settings.Tools.TextToSpeechElevenLabsStability = (double)nikseUpDownStability.Value / 100.0; if (_engine.Id == TextToSpeech.TextToSpeechEngineId.ElevenLabs)
Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity = (double)nikseUpDownSimilarity.Value / 100.0; {
Configuration.Settings.Tools.TextToSpeechElevenLabsStability = (double)nikseUpDownStability.Value / 100.0;
Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity = (double)nikseUpDownSimilarity.Value / 100.0;
}
else if (_engine.Id == TextToSpeech.TextToSpeechEngineId.Murf)
{
Configuration.Settings.Tools.TextToSpeechMurfPitch = (int)nikseUpDownStability.Value;
Configuration.Settings.Tools.TextToSpeechMurfRate = (int)nikseUpDownSimilarity.Value;
}
var paragraph = _subtitle.Paragraphs[_index]; var paragraph = _subtitle.Paragraphs[_index];
paragraph.Text = TextBoxReGenerate.Text.Trim(); paragraph.Text = TextBoxReGenerate.Text.Trim();

View File

@ -211,8 +211,6 @@ namespace Nikse.SubtitleEdit.Forms.Tts
checkBoxShowPreview.Checked = Configuration.Settings.Tools.TextToSpeechPreview; checkBoxShowPreview.Checked = Configuration.Settings.Tools.TextToSpeechPreview;
checkBoxAudioEncoding.Checked = Configuration.Settings.Tools.TextToSpeechCustomAudio; checkBoxAudioEncoding.Checked = Configuration.Settings.Tools.TextToSpeechCustomAudio;
checkBoxAddToVideoFile.Enabled = _videoFileName != null; checkBoxAddToVideoFile.Enabled = _videoFileName != null;
nikseUpDownStability.Value = (int)Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsStability * 100.0);
nikseUpDownSimilarity.Value = (int)Math.Round(Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity * 100.0);
} }
private void SetActor(ActorAndVoice actor) private void SetActor(ActorAndVoice actor)
@ -1434,10 +1432,12 @@ namespace Nikse.SubtitleEdit.Forms.Tts
overrideStyle = "Conversational"; overrideStyle = "Conversational";
} }
var rate = Configuration.Settings.Tools.TextToSpeechMurfRate.ToString(CultureInfo.InvariantCulture);
var pitch = Configuration.Settings.Tools.TextToSpeechMurfPitch.ToString(CultureInfo.InvariantCulture);
var body = "{ \"voiceId\": \"" + voice.VoiceId + "\", \"style\": \"" + (voice.AvailableStyles.Contains(overrideStyle) var body = "{ \"voiceId\": \"" + voice.VoiceId + "\", \"style\": \"" + (voice.AvailableStyles.Contains(overrideStyle)
? overrideStyle ? overrideStyle
: voice.AvailableStyles.FirstOrDefault()) + : voice.AvailableStyles.FirstOrDefault()) +
"\", \"text\": \"" + Json.EncodeJsonText(text) + "\", \"rate\": 0, \"pitch\": 0, \"sampleRate\": 48000, \"format\": \"MP3\", \"channelType\": \"MONO\", \"pronunciationDictionary\": { }, \"encodeAsBase64\": false, \"modelVersion\": \"GEN2\" }"; "\", \"text\": \"" + Json.EncodeJsonText(text) + "\", \"rate\": " + rate + ", \"pitch\": " + pitch + ", \"sampleRate\": 48000, \"format\": \"MP3\", \"channelType\": \"MONO\", \"pronunciationDictionary\": { }, \"encodeAsBase64\": false, \"modelVersion\": \"GEN2\" }";
var requestMessage = new HttpRequestMessage(HttpMethod.Post, url); var requestMessage = new HttpRequestMessage(HttpMethod.Post, url);
requestMessage.Content = new StringContent(body, Encoding.UTF8, "application/json"); requestMessage.Content = new StringContent(body, Encoding.UTF8, "application/json");
@ -1635,8 +1635,19 @@ namespace Nikse.SubtitleEdit.Forms.Tts
nikseComboBoxRegion.Visible = true; nikseComboBoxRegion.Visible = true;
labelStability.Text = LanguageSettings.Current.TextToSpeech.Stability;
labelSimilarity.Text = LanguageSettings.Current.TextToSpeech.Similarity;
labelStability.Visible = true; labelStability.Visible = true;
labelSimilarity.Visible = true; labelSimilarity.Visible = true;
nikseUpDownStability.Minimum = 0;
nikseUpDownStability.Maximum = 100;
nikseUpDownStability.Value = (decimal)Configuration.Settings.Tools.TextToSpeechElevenLabsStability;
nikseUpDownSimilarity.Minimum = 0;
nikseUpDownSimilarity.Maximum = 100;
nikseUpDownSimilarity.Value = (decimal)Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity;
nikseUpDownStability.Visible = true; nikseUpDownStability.Visible = true;
nikseUpDownSimilarity.Visible = true; nikseUpDownSimilarity.Visible = true;
} }
@ -1712,6 +1723,34 @@ namespace Nikse.SubtitleEdit.Forms.Tts
labelRegion.Visible = true; labelRegion.Visible = true;
nikseComboBoxRegion.Visible = true; nikseComboBoxRegion.Visible = true;
nikseComboBoxRegion.Text = "English (US and Canada)"; nikseComboBoxRegion.Text = "English (US and Canada)";
if (!string.IsNullOrEmpty(Configuration.Settings.Tools.TextToSpeechMurfVoice))
{
var voice = _murfVoices.FirstOrDefault(p => p.ToString() == Configuration.Settings.Tools.TextToSpeechMurfVoice);
if (voice != null)
{
var murfLanguage = _murfLanguages.FirstOrDefault(p => p.Code == voice.Locale);
if (murfLanguage != null)
{
nikseComboBoxRegion.Text = murfLanguage.Name;
}
nikseComboBoxVoice.Text = Configuration.Settings.Tools.TextToSpeechMurfVoice;
}
}
labelStability.Text = "Pitch";
nikseUpDownStability.Minimum = -49;
nikseUpDownStability.Maximum = 50;
nikseUpDownStability.Value = Configuration.Settings.Tools.TextToSpeechMurfPitch;
labelStability.Visible = true;
nikseUpDownStability.Visible = true;
labelSimilarity.Text = "Speed";
nikseUpDownSimilarity.Minimum = -49;
nikseUpDownSimilarity.Maximum = 50;
nikseUpDownSimilarity.Value = Configuration.Settings.Tools.TextToSpeechMurfRate;
labelSimilarity.Visible = true;
nikseUpDownSimilarity.Visible = true;
} }
if (nikseComboBoxVoice.Items.Count > 0 && nikseComboBoxVoice.SelectedIndex < 0) if (nikseComboBoxVoice.Items.Count > 0 && nikseComboBoxVoice.SelectedIndex < 0)
@ -2581,8 +2620,17 @@ namespace Nikse.SubtitleEdit.Forms.Tts
private void SaveConfiguration() private void SaveConfiguration()
{ {
Configuration.Settings.Tools.TextToSpeechElevenLabsStability = (double)nikseUpDownStability.Value / 100.0; var engine = _engines.First(p => p.Index == nikseComboBoxEngine.SelectedIndex);
Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity = (double)nikseUpDownSimilarity.Value / 100.0; if (engine.Id == TextToSpeechEngineId.ElevenLabs)
{
Configuration.Settings.Tools.TextToSpeechElevenLabsStability = (double)nikseUpDownStability.Value / 100.0;
Configuration.Settings.Tools.TextToSpeechElevenLabsSimilarity = (double)nikseUpDownSimilarity.Value / 100.0;
}
else if (engine.Id == TextToSpeechEngineId.Murf)
{
Configuration.Settings.Tools.TextToSpeechMurfPitch = (int)nikseUpDownStability.Value;
Configuration.Settings.Tools.TextToSpeechMurfRate = (int)nikseUpDownSimilarity.Value;
}
} }
private void HandleError(Exception ex) private void HandleError(Exception ex)
@ -2620,6 +2668,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
else if (engine.Id == TextToSpeechEngineId.Murf) else if (engine.Id == TextToSpeechEngineId.Murf)
{ {
Configuration.Settings.Tools.TextToSpeechMurfApiKey = nikseTextBoxApiKey.Text; Configuration.Settings.Tools.TextToSpeechMurfApiKey = nikseTextBoxApiKey.Text;
Configuration.Settings.Tools.TextToSpeechMurfVoice = nikseComboBoxVoice.Text;
} }
Configuration.Settings.Tools.TextToSpeechEngine = engine.Id.ToString(); Configuration.Settings.Tools.TextToSpeechEngine = engine.Id.ToString();