Work on Whisper extra cmd line parameter

This commit is contained in:
niksedk 2023-07-12 19:22:49 +02:00
parent ee6d07e14e
commit b409b65454
7 changed files with 82 additions and 23 deletions

View File

@ -3222,4 +3222,9 @@ Keep changes?</KeepChangesMessage>
<WebVttStyleManager>
<Title>WebVTT styles</Title>
</WebVttStyleManager>
<WhisperAdvanced>
<Title>Whisper Advanced - extra command line arguments</Title>
<CommandLineArguments>Extra pameters for whisper command line:</CommandLineArguments>
<Info>Note: Different Whisper implementations have different command line parameters!</Info>
</WhisperAdvanced>
</Language>

View File

@ -438,6 +438,7 @@ namespace Nikse.SubtitleEdit.Core.Common
public string WhisperStableTsLocation { get; set; }
public string WhisperCppModelLocation { get; set; }
public string WhisperExtraSettings { get; set; }
public string WhisperExtraSettingsHistory { get; set; }
public bool WhisperAutoAdjustTimings { get; set; }
public bool WhisperUseLineMaxChars { get; set; }
public int AudioToTextLineMaxChars { get; set; }
@ -6419,6 +6420,12 @@ $HorzAlign = Center
settings.Tools.WhisperExtraSettings = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperExtraSettingsHistory");
if (subNode != null)
{
settings.Tools.WhisperExtraSettingsHistory = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperLanguageCode");
if (subNode != null)
{
@ -10819,6 +10826,7 @@ $HorzAlign = Center
textWriter.WriteElementString("WhisperStableTsLocation", settings.Tools.WhisperStableTsLocation);
textWriter.WriteElementString("WhisperCppModelLocation", settings.Tools.WhisperCppModelLocation);
textWriter.WriteElementString("WhisperExtraSettings", settings.Tools.WhisperExtraSettings);
textWriter.WriteElementString("WhisperExtraSettingsHistory", settings.Tools.WhisperExtraSettingsHistory);
textWriter.WriteElementString("WhisperLanguageCode", settings.Tools.WhisperLanguageCode);
textWriter.WriteElementString("WhisperAutoAdjustTimings", settings.Tools.WhisperAutoAdjustTimings.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WhisperUseLineMaxChars", settings.Tools.WhisperUseLineMaxChars.ToString(CultureInfo.InvariantCulture));

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Forms.AudioToText
{
partial class WhisperAdvanced
sealed partial class WhisperAdvanced
{
/// <summary>
/// Required designer variable.
@ -29,7 +29,7 @@
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WhisperAdvanced));
this.labelMeasureFont = new System.Windows.Forms.Label();
this.labelWhisperExtraCmdLine = new System.Windows.Forms.Label();
this.comboBoxWhisperExtra = new System.Windows.Forms.ComboBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOK = new System.Windows.Forms.Button();
@ -47,14 +47,14 @@
this.tabPageOpenAI.SuspendLayout();
this.SuspendLayout();
//
// labelMeasureFont
// labelWhisperExtraCmdLine
//
this.labelMeasureFont.AutoSize = true;
this.labelMeasureFont.Location = new System.Drawing.Point(12, 22);
this.labelMeasureFont.Name = "labelMeasureFont";
this.labelMeasureFont.Size = new System.Drawing.Size(202, 13);
this.labelMeasureFont.TabIndex = 217;
this.labelMeasureFont.Text = "Extra pameters for whisper command line:";
this.labelWhisperExtraCmdLine.AutoSize = true;
this.labelWhisperExtraCmdLine.Location = new System.Drawing.Point(12, 22);
this.labelWhisperExtraCmdLine.Name = "labelWhisperExtraCmdLine";
this.labelWhisperExtraCmdLine.Size = new System.Drawing.Size(202, 13);
this.labelWhisperExtraCmdLine.TabIndex = 217;
this.labelWhisperExtraCmdLine.Text = "Extra pameters for whisper command line:";
//
// comboBoxWhisperExtra
//
@ -66,6 +66,7 @@
this.comboBoxWhisperExtra.Name = "comboBoxWhisperExtra";
this.comboBoxWhisperExtra.Size = new System.Drawing.Size(680, 21);
this.comboBoxWhisperExtra.TabIndex = 214;
this.comboBoxWhisperExtra.KeyDown += new System.Windows.Forms.KeyEventHandler(this.comboBoxWhisperExtra_KeyDown);
//
// buttonCancel
//
@ -147,7 +148,7 @@
this.tabPageConstMe.Location = new System.Drawing.Point(4, 22);
this.tabPageConstMe.Name = "tabPageConstMe";
this.tabPageConstMe.Padding = new System.Windows.Forms.Padding(3);
this.tabPageConstMe.Size = new System.Drawing.Size(636, 290);
this.tabPageConstMe.Size = new System.Drawing.Size(672, 332);
this.tabPageConstMe.TabIndex = 1;
this.tabPageConstMe.Text = "Const-me";
this.tabPageConstMe.UseVisualStyleBackColor = true;
@ -161,7 +162,7 @@
this.textBoxConstMe.Name = "textBoxConstMe";
this.textBoxConstMe.ReadOnly = true;
this.textBoxConstMe.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBoxConstMe.Size = new System.Drawing.Size(630, 284);
this.textBoxConstMe.Size = new System.Drawing.Size(666, 326);
this.textBoxConstMe.TabIndex = 1;
this.textBoxConstMe.Text = resources.GetString("textBoxConstMe.Text");
this.textBoxConstMe.WordWrap = false;
@ -172,7 +173,7 @@
this.tabPageOpenAI.Location = new System.Drawing.Point(4, 22);
this.tabPageOpenAI.Name = "tabPageOpenAI";
this.tabPageOpenAI.Padding = new System.Windows.Forms.Padding(3);
this.tabPageOpenAI.Size = new System.Drawing.Size(636, 290);
this.tabPageOpenAI.Size = new System.Drawing.Size(672, 332);
this.tabPageOpenAI.TabIndex = 2;
this.tabPageOpenAI.Text = "OpenAI";
this.tabPageOpenAI.UseVisualStyleBackColor = true;
@ -186,7 +187,7 @@
this.textBoxOpenAI.Name = "textBoxOpenAI";
this.textBoxOpenAI.ReadOnly = true;
this.textBoxOpenAI.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBoxOpenAI.Size = new System.Drawing.Size(630, 284);
this.textBoxOpenAI.Size = new System.Drawing.Size(666, 326);
this.textBoxOpenAI.TabIndex = 2;
this.textBoxOpenAI.Text = resources.GetString("textBoxOpenAI.Text");
this.textBoxOpenAI.WordWrap = false;
@ -198,7 +199,7 @@
this.ClientSize = new System.Drawing.Size(707, 507);
this.Controls.Add(this.tabControlCommandLineHelp);
this.Controls.Add(this.labelNote);
this.Controls.Add(this.labelMeasureFont);
this.Controls.Add(this.labelWhisperExtraCmdLine);
this.Controls.Add(this.comboBoxWhisperExtra);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
@ -225,7 +226,7 @@
#endregion
private System.Windows.Forms.Label labelMeasureFont;
private System.Windows.Forms.Label labelWhisperExtraCmdLine;
private System.Windows.Forms.ComboBox comboBoxWhisperExtra;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Button buttonOK;

View File

@ -7,7 +7,7 @@ using Nikse.SubtitleEdit.Core.AudioToText;
namespace Nikse.SubtitleEdit.Forms.AudioToText
{
public partial class WhisperAdvanced : Form
public sealed partial class WhisperAdvanced : Form
{
public WhisperAdvanced(string whisperEngine)
{
@ -16,14 +16,20 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
UiUtil.FixFonts(this);
comboBoxWhisperExtra.Items.Clear();
comboBoxWhisperExtra.Items.Add("--temperature <TEMPERATURE>");
comboBoxWhisperExtra.Items.Add("--best_of <BEST_OF>");
comboBoxWhisperExtra.Items.Add("--beam_size <BEAM_SIZE>");
comboBoxWhisperExtra.Items.Add("--patience <PATIENCE>");
comboBoxWhisperExtra.Items.Add("--condition_on_previous_text False");
comboBoxWhisperExtra.Items.Add("--fp16 False");
comboBoxWhisperExtra.Items.Add("--temperature_increment_on_fallback <TEMPERATURE_INCREMENT_ON_FALLBACK>");
if (!string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperExtraSettingsHistory))
{
foreach (var line in Configuration.Settings.Tools.WhisperExtraSettingsHistory.SplitToLines())
{
if (!string.IsNullOrEmpty(line))
{
comboBoxWhisperExtra.Items.Add(line);
}
}
}
Text = LanguageSettings.Current.WhisperAdvanced.Title;
labelWhisperExtraCmdLine.Text = LanguageSettings.Current.WhisperAdvanced.CommandLineArguments;
labelNote.Text = LanguageSettings.Current.WhisperAdvanced.Info;
buttonOK.Text = LanguageSettings.Current.General.Ok;
buttonCancel.Text = LanguageSettings.Current.General.Cancel;
comboBoxWhisperExtra.Text = Configuration.Settings.Tools.WhisperExtraSettings;
@ -56,6 +62,13 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private void buttonOK_Click(object sender, EventArgs e)
{
var param = comboBoxWhisperExtra.Text.Trim();
if (!string.IsNullOrWhiteSpace(param) && !Configuration.Settings.Tools.WhisperExtraSettings.Contains(param))
{
Configuration.Settings.Tools.WhisperExtraSettingsHistory = param + Environment.NewLine +
Configuration.Settings.Tools.WhisperExtraSettingsHistory;
}
Configuration.Settings.Tools.WhisperExtraSettings = comboBoxWhisperExtra.Text;
DialogResult = DialogResult.OK;
}
@ -64,5 +77,13 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
{
DialogResult = DialogResult.Cancel;
}
private void comboBoxWhisperExtra_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
buttonOK_Click(null, null);
}
}
}
}

View File

@ -126,6 +126,7 @@ namespace Nikse.SubtitleEdit.Logic
public LanguageStructure.WaveformGenerateTimeCodes WaveformGenerateTimeCodes;
public LanguageStructure.WebVttNewVoice WebVttNewVoice;
public LanguageStructure.WebVttStyleManager WebVttStyleManager;
public LanguageStructure.WhisperAdvanced WhisperAdvanced;
public Language()
{
@ -3623,6 +3624,13 @@ Keep changes?",
{
Title = "WebVTT styles",
};
WhisperAdvanced = new LanguageStructure.WhisperAdvanced
{
Title = "Whisper Advanced - extra command line arguments",
CommandLineArguments = "Extra pameters for whisper command line:",
Info = "Note: Different Whisper implementations have different command line parameters!",
};
}
//public static Language Load(StreamReader sr) // normal but slow .net way

View File

@ -8794,6 +8794,15 @@ namespace Nikse.SubtitleEdit.Logic
case "WebVttStyleManager/Title":
language.WebVttStyleManager.Title = reader.Value;
break;
case "WhisperAdvanced/Title":
language.WhisperAdvanced.Title = reader.Value;
break;
case "WhisperAdvanced/CommandLineArguments":
language.WhisperAdvanced.CommandLineArguments = reader.Value;
break;
case "WhisperAdvanced/Info":
language.WhisperAdvanced.Info = reader.Value;
break;
}
}

View File

@ -3468,5 +3468,12 @@ namespace Nikse.SubtitleEdit.Logic
{
public string Title { get; set; }
}
public class WhisperAdvanced
{
public string Title { get; set; }
public string CommandLineArguments { get; set; }
public string Info { get; set; }
}
}
}