Add max chars to whisper cpp UI

This commit is contained in:
niksedk 2023-02-08 19:01:19 +01:00
parent 956ae0253b
commit 8871c7e9f3
7 changed files with 68 additions and 17 deletions

View File

@ -198,6 +198,7 @@ Read more info (web)?</WhisperNotFound>
<BatchMode>Batch mode</BatchMode>
<KeepPartialTranscription>Keep partial transcription</KeepPartialTranscription>
<TranslateToEnglish>Translate to English</TranslateToEnglish>
<MaxCharsPerSubtitle>Max. chars per subtitle line</MaxCharsPerSubtitle>
</AudioToText>
<AssaAttachments>
<Title>Advanced Sub Station Alpha attachments</Title>

View File

@ -64,9 +64,12 @@
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.removeTemporaryFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.checkBoxAutoAdjustTimings = new System.Windows.Forms.CheckBox();
this.numericUpDownCharsPerSub = new System.Windows.Forms.NumericUpDown();
this.labelCharsPerSub = new System.Windows.Forms.Label();
this.groupBoxModels.SuspendLayout();
this.groupBoxInputFiles.SuspendLayout();
this.contextMenuStripWhisperAdvanced.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCharsPerSub)).BeginInit();
this.SuspendLayout();
//
// buttonCancel
@ -123,7 +126,7 @@
this.textBoxLog.Multiline = true;
this.textBoxLog.Name = "textBoxLog";
this.textBoxLog.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxLog.Size = new System.Drawing.Size(168, 288);
this.textBoxLog.Size = new System.Drawing.Size(168, 65);
this.textBoxLog.TabIndex = 0;
//
// labelInfo
@ -384,7 +387,7 @@
this.toolStripSeparator1,
this.removeTemporaryFilesToolStripMenuItem});
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(210, 120);
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(210, 98);
//
// whisperPhpOriginalToolStripMenuItem
//
@ -429,11 +432,44 @@
this.checkBoxAutoAdjustTimings.Text = "Auto adjust timings";
this.checkBoxAutoAdjustTimings.UseVisualStyleBackColor = true;
//
// numericUpDownCharsPerSub
//
this.numericUpDownCharsPerSub.Location = new System.Drawing.Point(622, 148);
this.numericUpDownCharsPerSub.Maximum = new decimal(new int[] {
999,
0,
0,
0});
this.numericUpDownCharsPerSub.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDownCharsPerSub.Name = "numericUpDownCharsPerSub";
this.numericUpDownCharsPerSub.Size = new System.Drawing.Size(69, 20);
this.numericUpDownCharsPerSub.TabIndex = 23;
this.numericUpDownCharsPerSub.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// labelCharsPerSub
//
this.labelCharsPerSub.AutoSize = true;
this.labelCharsPerSub.Location = new System.Drawing.Point(522, 150);
this.labelCharsPerSub.Name = "labelCharsPerSub";
this.labelCharsPerSub.Size = new System.Drawing.Size(94, 13);
this.labelCharsPerSub.TabIndex = 24;
this.labelCharsPerSub.Text = "Max chars/subtitle";
//
// WhisperAudioToText
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(709, 494);
this.Controls.Add(this.labelCharsPerSub);
this.Controls.Add(this.numericUpDownCharsPerSub);
this.Controls.Add(this.labelElapsed);
this.Controls.Add(this.checkBoxAutoAdjustTimings);
this.Controls.Add(this.labelCpp);
@ -467,6 +503,7 @@
this.groupBoxModels.PerformLayout();
this.groupBoxInputFiles.ResumeLayout(false);
this.contextMenuStripWhisperAdvanced.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCharsPerSub)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -509,5 +546,7 @@
private System.Windows.Forms.ToolStripMenuItem removeTemporaryFilesToolStripMenuItem;
private System.Windows.Forms.CheckBox checkBoxAutoAdjustTimings;
private System.Windows.Forms.ToolStripMenuItem whisperConstMeToolStripMenuItem;
private System.Windows.Forms.NumericUpDown numericUpDownCharsPerSub;
private System.Windows.Forms.Label labelCharsPerSub;
}
}

View File

@ -101,6 +101,18 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
labelElapsed.Text = string.Empty;
Init();
var maxChars = (int)Math.Round(Configuration.Settings.General.SubtitleLineMaximumLength * 1.8, MidpointRounding.AwayFromZero);
var language = WhisperLanguage.Languages.FirstOrDefault(p => p.Code == Configuration.Settings.Tools.WhisperLanguageCode);
if (language?.Code == "jp")
{
maxChars = Configuration.Settings.Tools.AudioToTextLineMaxCharsJp;
}
else if (language?.Code == "cn")
{
maxChars = Configuration.Settings.Tools.AudioToTextLineMaxCharsCn;
}
numericUpDownCharsPerSub.Value = maxChars;
}
private void Init()
@ -122,6 +134,10 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
whisperConstMeToolStripMenuItem.Visible = Configuration.IsRunningOnWindows;
removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles;
ContextMenuStrip = contextMenuStripWhisperAdvanced;
numericUpDownCharsPerSub.Visible = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp;
labelCharsPerSub.Left = numericUpDownCharsPerSub.Left - labelCharsPerSub.Width - 9;
labelCharsPerSub.Visible = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp;
}
public static void FillModels(ComboBox comboBoxModels, string lastDownloadedModel)
@ -469,7 +485,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
labelProgress.Refresh();
Application.DoEvents();
_resultList = new List<ResultText>();
var process = GetWhisperProcess(waveFileName, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, OutputHandler);
var process = GetWhisperProcess(waveFileName, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, (int)numericUpDownCharsPerSub.Value, OutputHandler);
var sw = Stopwatch.StartNew();
_outputText.Add($"Calling whisper ({Configuration.Settings.Tools.WhisperChoice}) with : {process.StartInfo.FileName} {process.StartInfo.Arguments}{Environment.NewLine}");
_startTicks = DateTime.UtcNow.Ticks;
@ -831,7 +847,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
}
}
public static Process GetWhisperProcess(string waveFileName, string model, string language, bool translate, DataReceivedEventHandler dataReceivedHandler = null)
public static Process GetWhisperProcess(string waveFileName, string model, string language, bool translate, int maxCharsPerSub, DataReceivedEventHandler dataReceivedHandler = null)
{
// whisper --model tiny.en --language English --fp16 False a.wav
@ -849,19 +865,9 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
translateToEnglish += "--print-progress ";
}
if (!Configuration.Settings.Tools.WhisperExtraSettings.Contains("--max-len"))
if (!Configuration.Settings.Tools.WhisperExtraSettings.Contains("--max-len") && maxCharsPerSub > 0)
{
var maxChars = (int)Math.Round(Configuration.Settings.General.SubtitleLineMaximumLength * 1.8, MidpointRounding.AwayFromZero);
if (language == "jp")
{
maxChars = Configuration.Settings.Tools.AudioToTextLineMaxCharsJp;
}
if (language == "cn")
{
maxChars = Configuration.Settings.Tools.AudioToTextLineMaxCharsCn;
}
translateToEnglish += $"--max-len {maxChars} ";
translateToEnglish += $"--max-len {maxCharsPerSub} ";
}
}

View File

@ -178,7 +178,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
labelProgress.Refresh();
Application.DoEvents();
_resultList = new List<ResultText>();
var process = WhisperAudioToText.GetWhisperProcess(waveFileName, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, OutputHandler);
var process = WhisperAudioToText.GetWhisperProcess(waveFileName, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, 0, OutputHandler);
var sw = Stopwatch.StartNew();
_outputText.Add($"Calling whisper ({Configuration.Settings.Tools.WhisperChoice}) with : whisper {process.StartInfo.Arguments}{Environment.NewLine}");
buttonCancel.Visible = true;

View File

@ -344,6 +344,7 @@ namespace Nikse.SubtitleEdit.Logic
XFilesSavedToVideoSourceFolder = "{0} files saved to video source folder",
KeepPartialTranscription = "Keep partial transcription",
TranslateToEnglish = "Translate to English",
MaxCharsPerSubtitle = "Max. chars per subtitle line",
};
AssaAttachments = new LanguageStructure.AssaAttachments

View File

@ -535,6 +535,9 @@ namespace Nikse.SubtitleEdit.Logic
case "AudioToText/TranslateToEnglish":
language.AudioToText.TranslateToEnglish = reader.Value;
break;
case "AudioToText/MaxCharsPerSubtitle":
language.AudioToText.MaxCharsPerSubtitle = reader.Value;
break;
case "AssaAttachments/Title":
language.AssaAttachments.Title = reader.Value;
break;

View File

@ -202,6 +202,7 @@ namespace Nikse.SubtitleEdit.Logic
public string BatchMode { get; set; }
public string KeepPartialTranscription { get; set; }
public string TranslateToEnglish { get; set; }
public string MaxCharsPerSubtitle { get; set; }
}
public class AssaAttachments