mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 12:44:46 +01:00
More tts
This commit is contained in:
parent
502409a14e
commit
f861d00f46
@ -19028,17 +19028,22 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
else if (e.Modifiers == (Keys.Alt | Keys.Shift | Keys.Control) && e.KeyCode == Keys.T)
|
||||
{
|
||||
using (var form = new TextToSpeech(_subtitle, GetCurrentSubtitleFormat(), _videoFileName, _videoInfo))
|
||||
{
|
||||
if (form.ShowDialog(this) != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
e.SuppressKeyPress = true;
|
||||
}
|
||||
|
||||
TaskDelayHelper.RunDelayed(TimeSpan.FromMilliseconds(25), () =>
|
||||
{
|
||||
if (RequireFfmpegOk())
|
||||
{
|
||||
using (var form = new TextToSpeech(_subtitle, GetCurrentSubtitleFormat(), _videoFileName, _videoInfo))
|
||||
{
|
||||
if (form.ShowDialog(this) != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// put new entries above tabs
|
||||
|
||||
|
65
src/ui/Forms/Tts/TextToSpeech.Designer.cs
generated
65
src/ui/Forms/Tts/TextToSpeech.Designer.cs
generated
@ -36,13 +36,14 @@
|
||||
this.labelEngine = new System.Windows.Forms.Label();
|
||||
this.groupBoxMsSettings = new System.Windows.Forms.GroupBox();
|
||||
this.labelMsVoice = new System.Windows.Forms.Label();
|
||||
this.nikseComboBoxVoice = new Nikse.SubtitleEdit.Controls.NikseComboBox();
|
||||
this.checkBoxAddToVideoFile = new System.Windows.Forms.CheckBox();
|
||||
this.listView1 = new System.Windows.Forms.ListView();
|
||||
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.contextMenuStripActors = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.nikseComboBoxVoice = new Nikse.SubtitleEdit.Controls.NikseComboBox();
|
||||
this.nikseComboBoxEngine = new Nikse.SubtitleEdit.Controls.NikseComboBox();
|
||||
this.buttonTestVoice = new System.Windows.Forms.Button();
|
||||
this.groupBoxMsSettings.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -105,6 +106,7 @@
|
||||
//
|
||||
this.groupBoxMsSettings.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBoxMsSettings.Controls.Add(this.buttonTestVoice);
|
||||
this.groupBoxMsSettings.Controls.Add(this.labelMsVoice);
|
||||
this.groupBoxMsSettings.Controls.Add(this.nikseComboBoxVoice);
|
||||
this.groupBoxMsSettings.Location = new System.Drawing.Point(451, 57);
|
||||
@ -125,34 +127,12 @@
|
||||
this.labelMsVoice.TabIndex = 16;
|
||||
this.labelMsVoice.Text = "Voice";
|
||||
//
|
||||
// nikseComboBoxVoice
|
||||
//
|
||||
this.nikseComboBoxVoice.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | 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.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, 41);
|
||||
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 = 15;
|
||||
this.nikseComboBoxVoice.UsePopupWindow = false;
|
||||
//
|
||||
// checkBoxAddToVideoFile
|
||||
//
|
||||
this.checkBoxAddToVideoFile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.checkBoxAddToVideoFile.AutoSize = true;
|
||||
this.checkBoxAddToVideoFile.Checked = true;
|
||||
this.checkBoxAddToVideoFile.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.checkBoxAddToVideoFile.Location = new System.Drawing.Point(614, 397);
|
||||
this.checkBoxAddToVideoFile.Name = "checkBoxAddToVideoFile";
|
||||
this.checkBoxAddToVideoFile.Size = new System.Drawing.Size(176, 17);
|
||||
@ -194,6 +174,30 @@
|
||||
this.contextMenuStripActors.Name = "contextMenuStripActors";
|
||||
this.contextMenuStripActors.Size = new System.Drawing.Size(61, 4);
|
||||
//
|
||||
// nikseComboBoxVoice
|
||||
//
|
||||
this.nikseComboBoxVoice.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | 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.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, 41);
|
||||
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 = 15;
|
||||
this.nikseComboBoxVoice.UsePopupWindow = false;
|
||||
//
|
||||
// nikseComboBoxEngine
|
||||
//
|
||||
this.nikseComboBoxEngine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
@ -221,6 +225,16 @@
|
||||
this.nikseComboBoxEngine.UsePopupWindow = false;
|
||||
this.nikseComboBoxEngine.SelectedIndexChanged += new System.EventHandler(this.nikseComboBoxEngine_SelectedIndexChanged);
|
||||
//
|
||||
// buttonTestVoice
|
||||
//
|
||||
this.buttonTestVoice.Location = new System.Drawing.Point(17, 80);
|
||||
this.buttonTestVoice.Name = "buttonTestVoice";
|
||||
this.buttonTestVoice.Size = new System.Drawing.Size(150, 23);
|
||||
this.buttonTestVoice.TabIndex = 17;
|
||||
this.buttonTestVoice.Text = "Test voice";
|
||||
this.buttonTestVoice.UseVisualStyleBackColor = true;
|
||||
this.buttonTestVoice.Click += new System.EventHandler(this.buttonTestVoice_Click);
|
||||
//
|
||||
// TextToSpeech
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@ -267,5 +281,6 @@
|
||||
private System.Windows.Forms.ColumnHeader columnHeader1;
|
||||
private System.Windows.Forms.ColumnHeader columnHeader2;
|
||||
private System.Windows.Forms.ContextMenuStrip contextMenuStripActors;
|
||||
private System.Windows.Forms.Button buttonTestVoice;
|
||||
}
|
||||
}
|
@ -95,22 +95,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
_waveFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(_waveFolder);
|
||||
|
||||
if (nikseComboBoxEngine.SelectedIndex == 0)
|
||||
{
|
||||
GenerateParagraphAudioMs();
|
||||
}
|
||||
else if (nikseComboBoxEngine.SelectedIndex == 1)
|
||||
{
|
||||
GenerateParagraphAudioPiperTts();
|
||||
}
|
||||
else if (nikseComboBoxEngine.SelectedIndex == 2)
|
||||
{
|
||||
GenerateParagraphAudioTortoiseTts();
|
||||
}
|
||||
else if (nikseComboBoxEngine.SelectedIndex == 3)
|
||||
{
|
||||
GenerateParagraphAudioMimic3();
|
||||
}
|
||||
GenerateParagraphAudio(_subtitle);
|
||||
|
||||
var fileNames = FixParagraphAudioSpeed();
|
||||
|
||||
@ -130,6 +115,26 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
UiUtil.OpenFolder(_waveFolder);
|
||||
}
|
||||
|
||||
private void GenerateParagraphAudio(Subtitle subtitle)
|
||||
{
|
||||
if (nikseComboBoxEngine.SelectedIndex == 0)
|
||||
{
|
||||
GenerateParagraphAudioMs(subtitle, true);
|
||||
}
|
||||
else if (nikseComboBoxEngine.SelectedIndex == 1)
|
||||
{
|
||||
GenerateParagraphAudioPiperTts(subtitle, true);
|
||||
}
|
||||
else if (nikseComboBoxEngine.SelectedIndex == 2)
|
||||
{
|
||||
GenerateParagraphAudioTortoiseTts(subtitle, true);
|
||||
}
|
||||
else if (nikseComboBoxEngine.SelectedIndex == 3)
|
||||
{
|
||||
GenerateParagraphAudioMimic3(subtitle, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddAudioToVideoFile(string audioFileName)
|
||||
{
|
||||
var videoExt = ".mkv";
|
||||
@ -251,11 +256,11 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
return outputFileName;
|
||||
}
|
||||
|
||||
private void GenerateParagraphAudioMs()
|
||||
private void GenerateParagraphAudioMs(Subtitle subtitle, bool showProgressBar)
|
||||
{
|
||||
progressBar1.Value = 0;
|
||||
progressBar1.Maximum = _subtitle.Paragraphs.Count;
|
||||
progressBar1.Visible = true;
|
||||
progressBar1.Maximum = subtitle.Paragraphs.Count;
|
||||
progressBar1.Visible = showProgressBar;
|
||||
|
||||
using (var synthesizer = new SpeechSynthesizer())
|
||||
{
|
||||
@ -271,11 +276,15 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
}
|
||||
}
|
||||
|
||||
for (var index = 0; index < _subtitle.Paragraphs.Count; index++)
|
||||
for (var index = 0; index < subtitle.Paragraphs.Count; index++)
|
||||
{
|
||||
progressBar1.Value = index + 1;
|
||||
labelProgress.Text = $"Generating audio texts: {index + 1} / {_subtitle.Paragraphs.Count}...";
|
||||
var p = _subtitle.Paragraphs[index];
|
||||
if (showProgressBar)
|
||||
{
|
||||
progressBar1.Value = index + 1;
|
||||
labelProgress.Text = $"Generating audio texts: {index + 1} / {subtitle.Paragraphs.Count}...";
|
||||
}
|
||||
|
||||
var p = subtitle.Paragraphs[index];
|
||||
synthesizer.SetOutputToWaveFile(Path.Combine(_waveFolder, index + ".wav"));
|
||||
var builder = new PromptBuilder();
|
||||
if (voiceInfo != null)
|
||||
@ -312,7 +321,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
labelProgress.Text = string.Empty;
|
||||
}
|
||||
|
||||
private bool GenerateParagraphAudioPiperTts()
|
||||
private bool GenerateParagraphAudioPiperTts(Subtitle subtitle, bool showProgressBar)
|
||||
{
|
||||
var ttsPath = Path.Combine(Configuration.DataDirectory, "TextToSpeech");
|
||||
if (!Directory.Exists(ttsPath))
|
||||
@ -345,15 +354,19 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
}
|
||||
|
||||
progressBar1.Value = 0;
|
||||
progressBar1.Maximum = _subtitle.Paragraphs.Count;
|
||||
progressBar1.Visible = true;
|
||||
progressBar1.Maximum = subtitle.Paragraphs.Count;
|
||||
progressBar1.Visible = showProgressBar;
|
||||
var voices = PiperModels.GetVoices();
|
||||
|
||||
for (var index = 0; index < _subtitle.Paragraphs.Count; index++)
|
||||
for (var index = 0; index < subtitle.Paragraphs.Count; index++)
|
||||
{
|
||||
progressBar1.Value = index + 1;
|
||||
labelProgress.Text = $"Generating audio texts: {index + 1} / {_subtitle.Paragraphs.Count}...";
|
||||
var p = _subtitle.Paragraphs[index];
|
||||
if (showProgressBar)
|
||||
{
|
||||
progressBar1.Value = index + 1;
|
||||
labelProgress.Text = $"Generating audio texts: {index + 1} / {subtitle.Paragraphs.Count}...";
|
||||
}
|
||||
|
||||
var p = subtitle.Paragraphs[index];
|
||||
var outputFileName = Path.Combine(_waveFolder, index + ".wav");
|
||||
|
||||
var voice = voices.First(x => x.ToString() == nikseComboBoxVoice.Text);
|
||||
@ -424,7 +437,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool GenerateParagraphAudioTortoiseTts()
|
||||
private bool GenerateParagraphAudioTortoiseTts(Subtitle subtitle, bool showProgressBar)
|
||||
{
|
||||
var pythonFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
||||
"AppData",
|
||||
@ -449,15 +462,18 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
}
|
||||
|
||||
progressBar1.Value = 0;
|
||||
progressBar1.Maximum = _subtitle.Paragraphs.Count;
|
||||
progressBar1.Visible = true;
|
||||
progressBar1.Maximum = subtitle.Paragraphs.Count;
|
||||
progressBar1.Visible = showProgressBar;
|
||||
|
||||
|
||||
for (var index = 0; index < _subtitle.Paragraphs.Count; index++)
|
||||
for (var index = 0; index < subtitle.Paragraphs.Count; index++)
|
||||
{
|
||||
progressBar1.Value = index + 1;
|
||||
labelProgress.Text = $"Generating audio texts: {index + 1} / {_subtitle.Paragraphs.Count}...";
|
||||
var p = _subtitle.Paragraphs[index];
|
||||
if (showProgressBar)
|
||||
{
|
||||
progressBar1.Value = index + 1;
|
||||
labelProgress.Text = $"Generating audio texts: {index + 1} / {subtitle.Paragraphs.Count}...";
|
||||
}
|
||||
|
||||
var p = subtitle.Paragraphs[index];
|
||||
var outputFileName = Path.Combine(_waveFolder, index + ".wav");
|
||||
|
||||
var v = voice;
|
||||
@ -499,7 +515,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
return true;
|
||||
}
|
||||
|
||||
private void GenerateParagraphAudioMimic3()
|
||||
private void GenerateParagraphAudioMimic3(Subtitle subtitle, bool showProgressBar)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@ -624,5 +640,28 @@ namespace Nikse.SubtitleEdit.Forms.Tts
|
||||
{
|
||||
listView1.AutoSizeLastColumn();
|
||||
}
|
||||
|
||||
private void buttonTestVoice_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
_waveFolder = Path.GetTempPath();
|
||||
var text = "Hello there, how are you?";
|
||||
var sub = new Subtitle();
|
||||
sub.Paragraphs.Add(new Paragraph(text, 0, 2500));
|
||||
GenerateParagraphAudio(sub);
|
||||
var waveFileName = Path.Combine(_waveFolder, "0.wav");
|
||||
using (var soundPlayer = new System.Media.SoundPlayer(waveFileName))
|
||||
{
|
||||
soundPlayer.Play();
|
||||
}
|
||||
|
||||
File.Delete(waveFileName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user