Add easier re-generate TTS - thx cvrle77 :)

This commit is contained in:
Nikolaj Olsson 2024-10-23 19:04:32 +02:00
parent 95c12f5e03
commit 54fd14b43b
3 changed files with 123 additions and 30 deletions

View File

@ -29,11 +29,13 @@
private void InitializeComponent()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.TextBoxReGenerate = new Nikse.SubtitleEdit.Controls.NikseTextBox();
this.buttonReGenerate = new System.Windows.Forms.Button();
this.labelVoice = new System.Windows.Forms.Label();
this.nikseComboBoxVoice = new Nikse.SubtitleEdit.Controls.NikseComboBox();
this.labelText = new System.Windows.Forms.Label();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonPlay = new System.Windows.Forms.Button();
this.nikseComboBoxVoice = new Nikse.SubtitleEdit.Controls.NikseComboBox();
this.TextBoxReGenerate = new Nikse.SubtitleEdit.Controls.NikseTextBox();
this.SuspendLayout();
//
// buttonCancel
@ -43,30 +45,18 @@
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(730, 208);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(84, 23);
this.buttonCancel.Size = new System.Drawing.Size(84, 24);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// TextBoxReGenerate
//
this.TextBoxReGenerate.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TextBoxReGenerate.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215)))));
this.TextBoxReGenerate.Location = new System.Drawing.Point(12, 40);
this.TextBoxReGenerate.Multiline = true;
this.TextBoxReGenerate.Name = "TextBoxReGenerate";
this.TextBoxReGenerate.Size = new System.Drawing.Size(802, 162);
this.TextBoxReGenerate.TabIndex = 22;
//
// buttonReGenerate
//
this.buttonReGenerate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonReGenerate.Location = new System.Drawing.Point(550, 208);
this.buttonReGenerate.Location = new System.Drawing.Point(362, 208);
this.buttonReGenerate.Name = "buttonReGenerate";
this.buttonReGenerate.Size = new System.Drawing.Size(174, 23);
this.buttonReGenerate.Size = new System.Drawing.Size(171, 24);
this.buttonReGenerate.TabIndex = 21;
this.buttonReGenerate.Text = "Regenerate ";
this.buttonReGenerate.UseVisualStyleBackColor = true;
@ -77,12 +67,45 @@
this.labelVoice.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.labelVoice.AutoSize = true;
this.labelVoice.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.labelVoice.Location = new System.Drawing.Point(153, 213);
this.labelVoice.Location = new System.Drawing.Point(38, 213);
this.labelVoice.Name = "labelVoice";
this.labelVoice.Size = new System.Drawing.Size(34, 13);
this.labelVoice.TabIndex = 24;
this.labelVoice.Text = "Voice";
//
// labelText
//
this.labelText.AutoSize = true;
this.labelText.Location = new System.Drawing.Point(13, 21);
this.labelText.Name = "labelText";
this.labelText.Size = new System.Drawing.Size(28, 13);
this.labelText.TabIndex = 25;
this.labelText.Text = "Text";
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(640, 208);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(84, 24);
this.buttonOK.TabIndex = 26;
this.buttonOK.Text = "OK";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// buttonPlay
//
this.buttonPlay.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonPlay.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonPlay.Location = new System.Drawing.Point(539, 208);
this.buttonPlay.Name = "buttonPlay";
this.buttonPlay.Size = new System.Drawing.Size(95, 24);
this.buttonPlay.TabIndex = 27;
this.buttonPlay.Text = "Play";
this.buttonPlay.UseVisualStyleBackColor = true;
this.buttonPlay.Click += new System.EventHandler(this.buttonPlay_Click);
//
// nikseComboBoxVoice
//
this.nikseComboBoxVoice.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -97,30 +120,35 @@
this.nikseComboBoxVoice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.nikseComboBoxVoice.DropDownWidth = 0;
this.nikseComboBoxVoice.FormattingEnabled = false;
this.nikseComboBoxVoice.Location = new System.Drawing.Point(193, 208);
this.nikseComboBoxVoice.Location = new System.Drawing.Point(78, 208);
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.Size = new System.Drawing.Size(278, 23);
this.nikseComboBoxVoice.TabIndex = 23;
this.nikseComboBoxVoice.UsePopupWindow = false;
//
// labelText
// TextBoxReGenerate
//
this.labelText.AutoSize = true;
this.labelText.Location = new System.Drawing.Point(13, 21);
this.labelText.Name = "labelText";
this.labelText.Size = new System.Drawing.Size(28, 13);
this.labelText.TabIndex = 25;
this.labelText.Text = "Text";
this.TextBoxReGenerate.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TextBoxReGenerate.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215)))));
this.TextBoxReGenerate.Location = new System.Drawing.Point(12, 40);
this.TextBoxReGenerate.Multiline = true;
this.TextBoxReGenerate.Name = "TextBoxReGenerate";
this.TextBoxReGenerate.Size = new System.Drawing.Size(802, 162);
this.TextBoxReGenerate.TabIndex = 22;
//
// RegenerateAudioClip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(826, 243);
this.Controls.Add(this.buttonPlay);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.labelText);
this.Controls.Add(this.labelVoice);
this.Controls.Add(this.nikseComboBoxVoice);
@ -134,6 +162,7 @@
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Regenerate audio clip";
this.Shown += new System.EventHandler(this.RegenerateAudioClip_Shown);
this.ResumeLayout(false);
this.PerformLayout();
@ -146,5 +175,7 @@
private System.Windows.Forms.Label labelVoice;
private Controls.NikseComboBox nikseComboBoxVoice;
private System.Windows.Forms.Label labelText;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonPlay;
}
}

View File

@ -1,6 +1,8 @@
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.VideoPlayers;
using System;
using System.Threading;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms.Tts
@ -12,6 +14,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
private readonly TextToSpeech _textToSpeech;
private readonly Subtitle _subtitle;
private readonly int _index;
private LibMpvDynamic _libMpv;
public RegenerateAudioClip(TextToSpeech textToSpeech, Subtitle subtitle, int idx)
{
@ -28,10 +31,13 @@ namespace Nikse.SubtitleEdit.Forms.Tts
labelVoice.Text = LanguageSettings.Current.TextToSpeech.Voice;
buttonReGenerate.Text = LanguageSettings.Current.TextToSpeech.Regenerate;
buttonCancel.Text = LanguageSettings.Current.General.Cancel;
buttonOK.Text = LanguageSettings.Current.General.Ok;
buttonPlay.Text = LanguageSettings.Current.TextToSpeech.Play;
UiUtil.FixLargeFonts(this, buttonCancel);
TextBoxReGenerate.Text = subtitle.Paragraphs[idx].Text;
textToSpeech.SetCurrentVoices(nikseComboBoxVoice);
buttonPlay.Enabled = false;
}
private void buttonReGenerate_Click(object sender, EventArgs e)
@ -45,12 +51,13 @@ namespace Nikse.SubtitleEdit.Forms.Tts
{
Cursor = Cursors.WaitCursor;
buttonReGenerate.Enabled = false;
var fileNameAndSpeedFactor = _textToSpeech.ReGenerateAudio(paragraph, next, nikseComboBoxVoice.Text);
var fileNameAndSpeedFactor = _textToSpeech.ReGenerateAudio(paragraph, next, nikseComboBoxVoice.Text);
if (fileNameAndSpeedFactor != null)
{
FileNameAndSpeedFactor = fileNameAndSpeedFactor;
buttonPlay.Enabled = true;
Cursor = Cursors.Default;
DialogResult = DialogResult.OK;
buttonPlay_Click(null, null);
}
}
finally
@ -64,5 +71,61 @@ namespace Nikse.SubtitleEdit.Forms.Tts
{
DialogResult = DialogResult.Cancel;
}
private void buttonOK_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
}
private void buttonPlay_Click(object sender, EventArgs e)
{
if (FileNameAndSpeedFactor == null)
{
return;
}
var waveFileName = FileNameAndSpeedFactor.Filename;
if (_libMpv != null)
{
_libMpv.Initialize(
null,
waveFileName,
(sender2, args) =>
{
_libMpv.PlayRate = 1;
_libMpv.Play();
},
null);
TaskDelayHelper.RunDelayed(TimeSpan.FromMilliseconds(1000), () =>
{
var i = 0;
while (i < 100 && !_libMpv.IsPaused)
{
i++;
Thread.Sleep(100);
Application.DoEvents();
}
buttonPlay.Enabled = true;
});
}
else
{
using (var soundPlayer = new System.Media.SoundPlayer(waveFileName))
{
soundPlayer.PlaySync();
}
}
}
private void RegenerateAudioClip_Shown(object sender, EventArgs e)
{
if (LibMpvDynamic.IsInstalled)
{
_libMpv = new LibMpvDynamic();
}
}
}
}

View File

@ -273,7 +273,6 @@ namespace Nikse.SubtitleEdit.Forms.Tts
_fileNames[idx].Factor = form.FileNameAndSpeedFactor.Factor;
listViewAudioClips.Items[idx].SubItems[4].Text = $"{(form.FileNameAndSpeedFactor.Factor * 100.0m):0.#}%";
listViewAudioClips.Items[idx].SubItems[5].Text = _subtitle.Paragraphs[idx].Text;
Play(true);
}
}
}