From 0b90c931a62fd504874a26fefd6e79e6eb940525 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Wed, 11 Sep 2024 07:13:14 +0200 Subject: [PATCH] Try to add support for Eleven labs "eleven_turbo_v2_5" - thx laszlolaszlo :) Related to https://github.com/SubtitleEdit/subtitleedit/discussions/8810 --- src/libse/Settings/Settings.cs | 14 ++ src/libse/Settings/ToolsSettings.cs | 2 + src/ui/Forms/Tts/TextToSpeech.Designer.cs | 256 +++++++++++++--------- src/ui/Forms/Tts/TextToSpeech.cs | 109 ++++++++- 4 files changed, 273 insertions(+), 108 deletions(-) diff --git a/src/libse/Settings/Settings.cs b/src/libse/Settings/Settings.cs index 483f8b5ef..7dce936f9 100644 --- a/src/libse/Settings/Settings.cs +++ b/src/libse/Settings/Settings.cs @@ -2347,6 +2347,18 @@ namespace Nikse.SubtitleEdit.Core.Settings settings.Tools.TextToSpeechElevenLabsApiKey = subNode.InnerText; } + subNode = node.SelectSingleNode("TextToSpeechElevenLabsModel"); + if (subNode != null) + { + settings.Tools.TextToSpeechElevenLabsModel = subNode.InnerText; + } + + subNode = node.SelectSingleNode("TextToSpeechElevenLabsLanguage"); + if (subNode != null) + { + settings.Tools.TextToSpeechElevenLabsLanguage = subNode.InnerText; + } + subNode = node.SelectSingleNode("TextToSpeechAzureApiKey"); if (subNode != null) { @@ -9020,6 +9032,8 @@ namespace Nikse.SubtitleEdit.Core.Settings textWriter.WriteElementString("TextToSpeechEngine", settings.Tools.TextToSpeechEngine); textWriter.WriteElementString("TextToSpeechLastVoice", settings.Tools.TextToSpeechLastVoice); textWriter.WriteElementString("TextToSpeechElevenLabsApiKey", settings.Tools.TextToSpeechElevenLabsApiKey); + textWriter.WriteElementString("TextToSpeechElevenLabsModel", settings.Tools.TextToSpeechElevenLabsModel); + textWriter.WriteElementString("TextToSpeechElevenLabsLanguage", settings.Tools.TextToSpeechElevenLabsLanguage); textWriter.WriteElementString("TextToSpeechAzureApiKey", settings.Tools.TextToSpeechAzureApiKey); textWriter.WriteElementString("TextToSpeechAzureRegion", settings.Tools.TextToSpeechAzureRegion); textWriter.WriteElementString("TextToSpeechPreview", settings.Tools.TextToSpeechPreview.ToString(CultureInfo.InvariantCulture)); diff --git a/src/libse/Settings/ToolsSettings.cs b/src/libse/Settings/ToolsSettings.cs index 05c1cffbd..bcb7acfab 100644 --- a/src/libse/Settings/ToolsSettings.cs +++ b/src/libse/Settings/ToolsSettings.cs @@ -100,6 +100,8 @@ namespace Nikse.SubtitleEdit.Core.Settings public string TextToSpeechElevenLabsApiKey { get; set; } public string TextToSpeechAzureApiKey { get; set; } public string TextToSpeechAzureRegion { get; set; } + public string TextToSpeechElevenLabsModel { get; set; } + public string TextToSpeechElevenLabsLanguage { get; set; } public bool TextToSpeechPreview { get; set; } public bool TextToSpeechCustomAudio { get; set; } public bool TextToSpeechCustomAudioStereo { get; set; } diff --git a/src/ui/Forms/Tts/TextToSpeech.Designer.cs b/src/ui/Forms/Tts/TextToSpeech.Designer.cs index aef54b24c..279769640 100644 --- a/src/ui/Forms/Tts/TextToSpeech.Designer.cs +++ b/src/ui/Forms/Tts/TextToSpeech.Designer.cs @@ -35,28 +35,30 @@ this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.labelEngine = new System.Windows.Forms.Label(); this.groupBoxSettings = new System.Windows.Forms.GroupBox(); + this.labelLanguage = new System.Windows.Forms.Label(); + this.nikseComboBoxLanguage = new Nikse.SubtitleEdit.Controls.NikseComboBox(); this.linkLabelCustomAudio = new System.Windows.Forms.LinkLabel(); this.checkBoxAudioEncoding = new System.Windows.Forms.CheckBox(); this.labelRegion = new System.Windows.Forms.Label(); + this.nikseComboBoxRegion = new Nikse.SubtitleEdit.Controls.NikseComboBox(); this.labelVoiceCount = new System.Windows.Forms.Label(); this.checkBoxShowPreview = new System.Windows.Forms.CheckBox(); this.labelApiKey = new System.Windows.Forms.Label(); + this.nikseTextBoxApiKey = new Nikse.SubtitleEdit.Controls.NikseTextBox(); + this.TextBoxTest = new Nikse.SubtitleEdit.Controls.NikseTextBox(); this.buttonTestVoice = new System.Windows.Forms.Button(); this.checkBoxAddToVideoFile = new System.Windows.Forms.CheckBox(); this.labelVoice = new System.Windows.Forms.Label(); + this.nikseComboBoxVoice = new Nikse.SubtitleEdit.Controls.NikseComboBox(); this.contextMenuStripVoices = new System.Windows.Forms.ContextMenuStrip(this.components); this.refreshVoicesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.nikseComboBoxEngine = new Nikse.SubtitleEdit.Controls.NikseComboBox(); this.listViewActors = new System.Windows.Forms.ListView(); this.columnHeaderActor = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeaderVoice = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.contextMenuStripActors = new System.Windows.Forms.ContextMenuStrip(this.components); this.labelActors = new System.Windows.Forms.Label(); this.buttonCancel = new System.Windows.Forms.Button(); - this.nikseComboBoxRegion = new Nikse.SubtitleEdit.Controls.NikseComboBox(); - this.nikseTextBoxApiKey = new Nikse.SubtitleEdit.Controls.NikseTextBox(); - this.TextBoxTest = new Nikse.SubtitleEdit.Controls.NikseTextBox(); - this.nikseComboBoxVoice = new Nikse.SubtitleEdit.Controls.NikseComboBox(); - this.nikseComboBoxEngine = new Nikse.SubtitleEdit.Controls.NikseComboBox(); this.groupBoxSettings.SuspendLayout(); this.contextMenuStripVoices.SuspendLayout(); this.SuspendLayout(); @@ -119,6 +121,8 @@ // this.groupBoxSettings.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); + this.groupBoxSettings.Controls.Add(this.labelLanguage); + this.groupBoxSettings.Controls.Add(this.nikseComboBoxLanguage); this.groupBoxSettings.Controls.Add(this.linkLabelCustomAudio); this.groupBoxSettings.Controls.Add(this.checkBoxAudioEncoding); this.groupBoxSettings.Controls.Add(this.labelRegion); @@ -141,6 +145,41 @@ this.groupBoxSettings.TabStop = false; this.groupBoxSettings.Text = "Settings"; // + // labelLanguage + // + this.labelLanguage.AutoSize = true; + this.labelLanguage.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.labelLanguage.Location = new System.Drawing.Point(14, 274); + this.labelLanguage.Name = "labelLanguage"; + this.labelLanguage.Size = new System.Drawing.Size(55, 13); + this.labelLanguage.TabIndex = 36; + this.labelLanguage.Text = "Language"; + // + // nikseComboBoxLanguage + // + this.nikseComboBoxLanguage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.nikseComboBoxLanguage.BackColor = System.Drawing.SystemColors.Window; + this.nikseComboBoxLanguage.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); + this.nikseComboBoxLanguage.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); + this.nikseComboBoxLanguage.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); + this.nikseComboBoxLanguage.ButtonForeColor = System.Drawing.SystemColors.ControlText; + this.nikseComboBoxLanguage.ButtonForeColorDown = System.Drawing.Color.Orange; + this.nikseComboBoxLanguage.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.nikseComboBoxLanguage.DropDownHeight = 400; + this.nikseComboBoxLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.nikseComboBoxLanguage.DropDownWidth = 0; + this.nikseComboBoxLanguage.FormattingEnabled = false; + this.nikseComboBoxLanguage.Location = new System.Drawing.Point(102, 269); + this.nikseComboBoxLanguage.MaxLength = 32767; + this.nikseComboBoxLanguage.Name = "nikseComboBoxLanguage"; + this.nikseComboBoxLanguage.SelectedIndex = -1; + this.nikseComboBoxLanguage.SelectedItem = null; + this.nikseComboBoxLanguage.SelectedText = ""; + this.nikseComboBoxLanguage.Size = new System.Drawing.Size(266, 23); + this.nikseComboBoxLanguage.TabIndex = 35; + this.nikseComboBoxLanguage.UsePopupWindow = false; + // // linkLabelCustomAudio // this.linkLabelCustomAudio.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -168,12 +207,38 @@ // this.labelRegion.AutoSize = true; this.labelRegion.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.labelRegion.Location = new System.Drawing.Point(14, 268); + this.labelRegion.Location = new System.Drawing.Point(14, 245); this.labelRegion.Name = "labelRegion"; this.labelRegion.Size = new System.Drawing.Size(41, 13); this.labelRegion.TabIndex = 32; this.labelRegion.Text = "Region"; // + // nikseComboBoxRegion + // + this.nikseComboBoxRegion.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.nikseComboBoxRegion.BackColor = System.Drawing.SystemColors.Window; + this.nikseComboBoxRegion.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); + this.nikseComboBoxRegion.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); + this.nikseComboBoxRegion.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); + this.nikseComboBoxRegion.ButtonForeColor = System.Drawing.SystemColors.ControlText; + this.nikseComboBoxRegion.ButtonForeColorDown = System.Drawing.Color.Orange; + this.nikseComboBoxRegion.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.nikseComboBoxRegion.DropDownHeight = 400; + this.nikseComboBoxRegion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.nikseComboBoxRegion.DropDownWidth = 0; + this.nikseComboBoxRegion.FormattingEnabled = false; + this.nikseComboBoxRegion.Location = new System.Drawing.Point(102, 240); + this.nikseComboBoxRegion.MaxLength = 32767; + this.nikseComboBoxRegion.Name = "nikseComboBoxRegion"; + this.nikseComboBoxRegion.SelectedIndex = -1; + this.nikseComboBoxRegion.SelectedItem = null; + this.nikseComboBoxRegion.SelectedText = ""; + this.nikseComboBoxRegion.Size = new System.Drawing.Size(266, 23); + this.nikseComboBoxRegion.TabIndex = 31; + this.nikseComboBoxRegion.UsePopupWindow = false; + this.nikseComboBoxRegion.SelectedIndexChanged += new System.EventHandler(this.nikseComboBoxRegion_SelectedIndexChanged); + // // labelVoiceCount // this.labelVoiceCount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); @@ -201,12 +266,34 @@ // this.labelApiKey.AutoSize = true; this.labelApiKey.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.labelApiKey.Location = new System.Drawing.Point(20, 219); + this.labelApiKey.Location = new System.Drawing.Point(14, 217); this.labelApiKey.Name = "labelApiKey"; this.labelApiKey.Size = new System.Drawing.Size(44, 13); this.labelApiKey.TabIndex = 28; this.labelApiKey.Text = "API key"; // + // nikseTextBoxApiKey + // + this.nikseTextBoxApiKey.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.nikseTextBoxApiKey.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.nikseTextBoxApiKey.Location = new System.Drawing.Point(102, 214); + this.nikseTextBoxApiKey.Name = "nikseTextBoxApiKey"; + this.nikseTextBoxApiKey.Size = new System.Drawing.Size(266, 20); + this.nikseTextBoxApiKey.TabIndex = 27; + // + // TextBoxTest + // + this.TextBoxTest.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.TextBoxTest.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.TextBoxTest.Location = new System.Drawing.Point(17, 172); + this.TextBoxTest.Name = "TextBoxTest"; + this.TextBoxTest.Size = new System.Drawing.Size(351, 20); + this.TextBoxTest.TabIndex = 20; + this.TextBoxTest.Text = "Hello, how are you?"; + this.TextBoxTest.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TextBoxTest_KeyDown); + // // buttonTestVoice // this.buttonTestVoice.Location = new System.Drawing.Point(17, 141); @@ -240,6 +327,32 @@ this.labelVoice.TabIndex = 16; this.labelVoice.Text = "Voice"; // + // nikseComboBoxVoice + // + this.nikseComboBoxVoice.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.nikseComboBoxVoice.BackColor = System.Drawing.SystemColors.Window; + this.nikseComboBoxVoice.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); + this.nikseComboBoxVoice.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); + this.nikseComboBoxVoice.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); + this.nikseComboBoxVoice.ButtonForeColor = System.Drawing.SystemColors.ControlText; + this.nikseComboBoxVoice.ButtonForeColorDown = System.Drawing.Color.Orange; + this.nikseComboBoxVoice.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.nikseComboBoxVoice.ContextMenuStrip = this.contextMenuStripVoices; + this.nikseComboBoxVoice.DropDownHeight = 400; + this.nikseComboBoxVoice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.nikseComboBoxVoice.DropDownWidth = 0; + this.nikseComboBoxVoice.FormattingEnabled = false; + this.nikseComboBoxVoice.Location = new System.Drawing.Point(17, 110); + this.nikseComboBoxVoice.MaxLength = 32767; + this.nikseComboBoxVoice.Name = "nikseComboBoxVoice"; + this.nikseComboBoxVoice.SelectedIndex = -1; + this.nikseComboBoxVoice.SelectedItem = null; + this.nikseComboBoxVoice.SelectedText = ""; + this.nikseComboBoxVoice.Size = new System.Drawing.Size(351, 23); + this.nikseComboBoxVoice.TabIndex = 10; + this.nikseComboBoxVoice.UsePopupWindow = false; + // // contextMenuStripVoices // this.contextMenuStripVoices.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -255,6 +368,33 @@ this.refreshVoicesToolStripMenuItem.Text = "Refresh voices"; this.refreshVoicesToolStripMenuItem.Click += new System.EventHandler(this.refreshVoicesToolStripMenuItem_Click); // + // nikseComboBoxEngine + // + this.nikseComboBoxEngine.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.nikseComboBoxEngine.BackColor = System.Drawing.SystemColors.Window; + this.nikseComboBoxEngine.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); + this.nikseComboBoxEngine.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); + this.nikseComboBoxEngine.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); + this.nikseComboBoxEngine.ButtonForeColor = System.Drawing.SystemColors.ControlText; + this.nikseComboBoxEngine.ButtonForeColorDown = System.Drawing.Color.Orange; + this.nikseComboBoxEngine.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); + this.nikseComboBoxEngine.DropDownHeight = 400; + this.nikseComboBoxEngine.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown; + this.nikseComboBoxEngine.DropDownWidth = 391; + this.nikseComboBoxEngine.FormattingEnabled = false; + this.nikseComboBoxEngine.Location = new System.Drawing.Point(17, 40); + this.nikseComboBoxEngine.MaxLength = 32767; + this.nikseComboBoxEngine.Name = "nikseComboBoxEngine"; + this.nikseComboBoxEngine.SelectedIndex = -1; + this.nikseComboBoxEngine.SelectedItem = null; + this.nikseComboBoxEngine.SelectedText = ""; + this.nikseComboBoxEngine.Size = new System.Drawing.Size(351, 23); + this.nikseComboBoxEngine.TabIndex = 5; + this.nikseComboBoxEngine.TabStop = false; + this.nikseComboBoxEngine.Text = "nikseComboBox1"; + this.nikseComboBoxEngine.UsePopupWindow = false; + // // listViewActors // this.listViewActors.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -312,106 +452,6 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // - // nikseComboBoxRegion - // - this.nikseComboBoxRegion.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.nikseComboBoxRegion.BackColor = System.Drawing.SystemColors.Window; - this.nikseComboBoxRegion.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); - this.nikseComboBoxRegion.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); - this.nikseComboBoxRegion.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); - this.nikseComboBoxRegion.ButtonForeColor = System.Drawing.SystemColors.ControlText; - this.nikseComboBoxRegion.ButtonForeColorDown = System.Drawing.Color.Orange; - this.nikseComboBoxRegion.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); - this.nikseComboBoxRegion.DropDownHeight = 400; - this.nikseComboBoxRegion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.nikseComboBoxRegion.DropDownWidth = 0; - this.nikseComboBoxRegion.FormattingEnabled = false; - this.nikseComboBoxRegion.Location = new System.Drawing.Point(17, 286); - this.nikseComboBoxRegion.MaxLength = 32767; - this.nikseComboBoxRegion.Name = "nikseComboBoxRegion"; - this.nikseComboBoxRegion.SelectedIndex = -1; - this.nikseComboBoxRegion.SelectedItem = null; - this.nikseComboBoxRegion.SelectedText = ""; - this.nikseComboBoxRegion.Size = new System.Drawing.Size(351, 23); - this.nikseComboBoxRegion.TabIndex = 31; - this.nikseComboBoxRegion.UsePopupWindow = false; - // - // nikseTextBoxApiKey - // - this.nikseTextBoxApiKey.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.nikseTextBoxApiKey.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); - this.nikseTextBoxApiKey.Location = new System.Drawing.Point(17, 237); - this.nikseTextBoxApiKey.Name = "nikseTextBoxApiKey"; - this.nikseTextBoxApiKey.Size = new System.Drawing.Size(351, 20); - this.nikseTextBoxApiKey.TabIndex = 27; - // - // TextBoxTest - // - this.TextBoxTest.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.TextBoxTest.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); - this.TextBoxTest.Location = new System.Drawing.Point(17, 172); - this.TextBoxTest.Name = "TextBoxTest"; - this.TextBoxTest.Size = new System.Drawing.Size(351, 20); - this.TextBoxTest.TabIndex = 20; - this.TextBoxTest.Text = "Hello, how are you?"; - this.TextBoxTest.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TextBoxTest_KeyDown); - // - // nikseComboBoxVoice - // - this.nikseComboBoxVoice.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.nikseComboBoxVoice.BackColor = System.Drawing.SystemColors.Window; - this.nikseComboBoxVoice.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); - this.nikseComboBoxVoice.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); - this.nikseComboBoxVoice.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); - this.nikseComboBoxVoice.ButtonForeColor = System.Drawing.SystemColors.ControlText; - this.nikseComboBoxVoice.ButtonForeColorDown = System.Drawing.Color.Orange; - this.nikseComboBoxVoice.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); - this.nikseComboBoxVoice.ContextMenuStrip = this.contextMenuStripVoices; - this.nikseComboBoxVoice.DropDownHeight = 400; - this.nikseComboBoxVoice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.nikseComboBoxVoice.DropDownWidth = 0; - this.nikseComboBoxVoice.FormattingEnabled = false; - this.nikseComboBoxVoice.Location = new System.Drawing.Point(17, 110); - this.nikseComboBoxVoice.MaxLength = 32767; - this.nikseComboBoxVoice.Name = "nikseComboBoxVoice"; - this.nikseComboBoxVoice.SelectedIndex = -1; - this.nikseComboBoxVoice.SelectedItem = null; - this.nikseComboBoxVoice.SelectedText = ""; - this.nikseComboBoxVoice.Size = new System.Drawing.Size(351, 23); - this.nikseComboBoxVoice.TabIndex = 10; - this.nikseComboBoxVoice.UsePopupWindow = false; - // - // nikseComboBoxEngine - // - this.nikseComboBoxEngine.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.nikseComboBoxEngine.BackColor = System.Drawing.SystemColors.Window; - this.nikseComboBoxEngine.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); - this.nikseComboBoxEngine.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179))))); - this.nikseComboBoxEngine.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120))))); - this.nikseComboBoxEngine.ButtonForeColor = System.Drawing.SystemColors.ControlText; - this.nikseComboBoxEngine.ButtonForeColorDown = System.Drawing.Color.Orange; - this.nikseComboBoxEngine.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215))))); - this.nikseComboBoxEngine.DropDownHeight = 400; - this.nikseComboBoxEngine.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown; - this.nikseComboBoxEngine.DropDownWidth = 391; - this.nikseComboBoxEngine.FormattingEnabled = false; - this.nikseComboBoxEngine.Location = new System.Drawing.Point(17, 40); - this.nikseComboBoxEngine.MaxLength = 32767; - this.nikseComboBoxEngine.Name = "nikseComboBoxEngine"; - this.nikseComboBoxEngine.SelectedIndex = -1; - this.nikseComboBoxEngine.SelectedItem = null; - this.nikseComboBoxEngine.SelectedText = ""; - this.nikseComboBoxEngine.Size = new System.Drawing.Size(351, 23); - this.nikseComboBoxEngine.TabIndex = 5; - this.nikseComboBoxEngine.TabStop = false; - this.nikseComboBoxEngine.Text = "nikseComboBox1"; - this.nikseComboBoxEngine.UsePopupWindow = false; - // // TextToSpeech // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -475,5 +515,7 @@ private System.Windows.Forms.ToolStripMenuItem refreshVoicesToolStripMenuItem; private System.Windows.Forms.CheckBox checkBoxAudioEncoding; private System.Windows.Forms.LinkLabel linkLabelCustomAudio; + private System.Windows.Forms.Label labelLanguage; + private Controls.NikseComboBox nikseComboBoxLanguage; } } \ No newline at end of file diff --git a/src/ui/Forms/Tts/TextToSpeech.cs b/src/ui/Forms/Tts/TextToSpeech.cs index ba6806232..41db3de4d 100644 --- a/src/ui/Forms/Tts/TextToSpeech.cs +++ b/src/ui/Forms/Tts/TextToSpeech.cs @@ -15,6 +15,7 @@ using System.Net.Http.Headers; using System.Text; using System.Threading; using System.Windows.Forms; +using Nikse.SubtitleEdit.Core.Translate; using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox; namespace Nikse.SubtitleEdit.Forms.Tts @@ -120,6 +121,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts checkBoxAddToVideoFile.Text = LanguageSettings.Current.TextToSpeech.AddAudioToVideo; buttonGenerateTTS.Text = LanguageSettings.Current.TextToSpeech.GenerateSpeech; labelRegion.Text = LanguageSettings.Current.General.Region; + labelLanguage.Text = LanguageSettings.Current.ChooseLanguage.Language; checkBoxShowPreview.Text = LanguageSettings.Current.TextToSpeech.ReviewAudioClips; checkBoxAudioEncoding.Text = LanguageSettings.Current.TextToSpeech.CustomAudioEncoding; linkLabelCustomAudio.Text = LanguageSettings.Current.Settings.Title; @@ -1110,7 +1112,18 @@ namespace Nikse.SubtitleEdit.Forms.Tts var url = "https://api.elevenlabs.io/v1/text-to-speech/" + voice.Model; var text = Utilities.UnbreakLine(p.Text); - var data = "{ \"text\": \"" + Json.EncodeJsonText(text) + "\", \"model_id\": \"eleven_multilingual_v2\", \"voice_settings\": { \"stability\": 0.8, \"similarity_boost\": 1.0 } }"; + var model = nikseComboBoxRegion.Text; + + var language = string.Empty; + if (model == "eleven_turbo_v2_5") + { + if (nikseComboBoxLanguage.SelectedItem is TranslationPair tp) + { + language = $", \"language_code\": \"{tp.Code}\""; + } + } + + var data = "{ \"text\": \"" + Json.EncodeJsonText(text) + $"\", \"model_id\": \"{model}\"{language}, \"voice_settings\": {{ \"stability\": 0.8, \"similarity_boost\": 1.0 }} }}"; var content = new StringContent(data, Encoding.UTF8); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); var result = httpClient.PostAsync(url, content, CancellationToken.None).Result; @@ -1335,6 +1348,9 @@ namespace Nikse.SubtitleEdit.Forms.Tts nikseTextBoxApiKey.Visible = false; labelRegion.Visible = false; nikseComboBoxRegion.Visible = false; + labelRegion.Text = LanguageSettings.Current.General.Region; + labelLanguage.Visible = false; + nikseComboBoxLanguage.Visible = false; labelRegion.Text = LanguageSettings.Current.General.Region; labelVoice.Text = LanguageSettings.Current.TextToSpeech.Voice; @@ -1447,6 +1463,20 @@ namespace Nikse.SubtitleEdit.Forms.Tts { nikseComboBoxVoice.Items.Add(voice.ToString()); } + + labelRegion.Text = LanguageSettings.Current.AudioToText.Model; + labelRegion.Visible = true; + nikseComboBoxRegion.Items.Clear(); + nikseComboBoxRegion.Items.Add("eleven_turbo_v2_5"); + nikseComboBoxRegion.Items.Add("eleven_multilingual_v2"); + + nikseComboBoxRegion.Text = Configuration.Settings.Tools.TextToSpeechElevenLabsModel; + if (nikseComboBoxRegion.SelectedIndex < 0) + { + nikseComboBoxRegion.SelectedIndex = 1; + } + + nikseComboBoxRegion.Visible = true; } if (engine.Id == TextToSpeechEngineId.AzureTextToSpeech) @@ -1758,6 +1788,69 @@ namespace Nikse.SubtitleEdit.Forms.Tts } } + private void FillElevenLabsLanguages(string model) + { + // see https://help.elevenlabs.io/hc/en-us/articles/17883183930129-What-models-do-you-offer-and-what-is-the-difference-between-them + + if (model != "eleven_turbo_v2_5") + { + nikseComboBoxLanguage.Visible = false; + labelLanguage.Visible = false; + return; + } + + nikseComboBoxLanguage.Items.Clear(); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Arabic", "ar")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Bulgarian", "bg")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Chinese", "zh")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Croatian", "hr")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Czech", "cz")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Danish", "da")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Dutch", "nl")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("English", "en")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Filipino", "ph")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Finnish", "fi")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("French", "fr")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("German", "de")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Greek", "el")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Hindi", "hi")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Hungarian", "hu")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Indonesian", "id")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Italian", "it")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Japanese", "ja")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Korean", "kr")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Malay", "ms")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Norwegian", "no")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Polish", "pl")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Portuguese", "pt")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Romanian", "ro")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Russian", "ru")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Slovak", "sk")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Spanish", "es")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Swedish", "sv")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Tamil", "ta")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Turkish", "tr")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Ukrainian", "uk")); + nikseComboBoxLanguage.Items.Add(new TranslationPair("Vietnamese", "vi")); + + nikseComboBoxLanguage.Visible = true; + labelLanguage.Visible = true; + + nikseComboBoxLanguage.SelectedIndex = 7; // english + if (!string.IsNullOrEmpty(Configuration.Settings.Tools.TextToSpeechElevenLabsLanguage)) + { + for (var i = 0; i < nikseComboBoxLanguage.Items.Count; i++) + { + var tp = (TranslationPair)nikseComboBoxLanguage.Items[i]; + if (tp.ToString() == Configuration.Settings.Tools.TextToSpeechElevenLabsLanguage) + { + nikseComboBoxLanguage.SelectedIndex = i; + break; + } + } + } + } + private void SetFirstLanguageHitAsVoice() { nikseComboBoxVoice.Text = Configuration.Settings.Tools.TextToSpeechLastVoice; @@ -2184,6 +2277,11 @@ namespace Nikse.SubtitleEdit.Forms.Tts if (engine.Id == TextToSpeechEngineId.ElevenLabs) { Configuration.Settings.Tools.TextToSpeechElevenLabsApiKey = nikseTextBoxApiKey.Text; + Configuration.Settings.Tools.TextToSpeechElevenLabsModel = nikseComboBoxRegion.Text; + if (nikseComboBoxLanguage.Visible) + { + Configuration.Settings.Tools.TextToSpeechElevenLabsLanguage = nikseComboBoxLanguage.Text; + } } else if (engine.Id == TextToSpeechEngineId.AzureTextToSpeech) { @@ -2361,5 +2459,14 @@ namespace Nikse.SubtitleEdit.Forms.Tts form.ShowDialog(this); } } + + private void nikseComboBoxRegion_SelectedIndexChanged(object sender, EventArgs e) + { + var engine = _engines.First(p => p.Index == nikseComboBoxEngine.SelectedIndex); + if (engine.Id == TextToSpeechEngineId.ElevenLabs) + { + FillElevenLabsLanguages(nikseComboBoxRegion.Text); + } + } } } \ No newline at end of file