Allow seetting CPP/ConstMe Whisper models folder - thx vivadavid :)

Fix #6807
This commit is contained in:
niksedk 2023-04-13 22:10:57 +02:00
parent 2dfb73358e
commit bde2df5ae2
6 changed files with 83 additions and 19 deletions

View File

@ -5,7 +5,19 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
{
public class WhisperCppModel : IWhisperModel
{
public string ModelFolder => Path.Combine(Configuration.DataDirectory, "Whisper", "Models");
public string ModelFolder
{
get
{
if (!string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperCppModelLocation) &&
Directory.Exists(Configuration.Settings.Tools.WhisperCppModelLocation))
{
return Configuration.Settings.Tools.WhisperCppModelLocation;
}
return Path.Combine(Configuration.DataDirectory, "Whisper", "Models");
}
}
public void CreateModelFolder()
{

View File

@ -383,7 +383,7 @@ namespace Nikse.SubtitleEdit.Core.Common
}
else
{
v = v + Environment.NewLine;
v += Environment.NewLine;
}
htmlTags[index] = v;

View File

@ -57,13 +57,13 @@
this.checkBoxTranslateToEnglish = new System.Windows.Forms.CheckBox();
this.labelElapsed = new System.Windows.Forms.Label();
this.contextMenuStripWhisperAdvanced = new System.Windows.Forms.ContextMenuStrip(this.components);
this.setCPPConstmeModelsFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.removeTemporaryFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.checkBoxAutoAdjustTimings = new System.Windows.Forms.CheckBox();
this.labelCharsPerSub = new System.Windows.Forms.Label();
this.comboBoxCharsPerSub = new System.Windows.Forms.ComboBox();
this.comboBoxWhisperEngine = new System.Windows.Forms.ComboBox();
this.labelEngine = new System.Windows.Forms.Label();
this.setCPPConstmeModelsFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxModels.SuspendLayout();
this.groupBoxInputFiles.SuspendLayout();
this.contextMenuStripWhisperAdvanced.SuspendLayout();
@ -370,12 +370,20 @@
this.setCPPConstmeModelsFolderToolStripMenuItem,
this.removeTemporaryFilesToolStripMenuItem});
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(259, 70);
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(259, 48);
this.contextMenuStripWhisperAdvanced.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStripWhisperAdvanced_Opening);
//
// setCPPConstmeModelsFolderToolStripMenuItem
//
this.setCPPConstmeModelsFolderToolStripMenuItem.Name = "setCPPConstmeModelsFolderToolStripMenuItem";
this.setCPPConstmeModelsFolderToolStripMenuItem.Size = new System.Drawing.Size(258, 22);
this.setCPPConstmeModelsFolderToolStripMenuItem.Text = "Set CPP/Const-me models folder...";
this.setCPPConstmeModelsFolderToolStripMenuItem.Click += new System.EventHandler(this.setCPPConstMeModelsFolderToolStripMenuItem_Click);
//
// removeTemporaryFilesToolStripMenuItem
//
this.removeTemporaryFilesToolStripMenuItem.Name = "removeTemporaryFilesToolStripMenuItem";
this.removeTemporaryFilesToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.removeTemporaryFilesToolStripMenuItem.Size = new System.Drawing.Size(258, 22);
this.removeTemporaryFilesToolStripMenuItem.Text = "Remove temporary files";
this.removeTemporaryFilesToolStripMenuItem.Click += new System.EventHandler(this.removeTemporaryFilesToolStripMenuItem_Click);
//
@ -428,12 +436,6 @@
this.labelEngine.TabIndex = 27;
this.labelEngine.Text = "Engine";
//
// setCPPConstmeModelsFolderToolStripMenuItem
//
this.setCPPConstmeModelsFolderToolStripMenuItem.Name = "setCPPConstmeModelsFolderToolStripMenuItem";
this.setCPPConstmeModelsFolderToolStripMenuItem.Size = new System.Drawing.Size(258, 22);
this.setCPPConstmeModelsFolderToolStripMenuItem.Text = "Set CPP/Const-me models folder...";
//
// WhisperAudioToText
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -1455,5 +1455,29 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
WhisperEngineCTranslate2();
}
}
private void setCPPConstMeModelsFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
using (var folderBrowserDialog1 = new FolderBrowserDialog())
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
Configuration.Settings.Tools.WhisperCppModelLocation = folderBrowserDialog1.SelectedPath;
}
}
}
private void contextMenuStripWhisperAdvanced_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperCppModelLocation) &&
Directory.Exists(Configuration.Settings.Tools.WhisperCppModelLocation))
{
setCPPConstmeModelsFolderToolStripMenuItem.Text = $"Set CPP/Const-me models folder... [{Configuration.Settings.Tools.WhisperCppModelLocation}]";
}
else
{
setCPPConstmeModelsFolderToolStripMenuItem.Text = "Set CPP/Const-me models folder...";
}
}
}
}

View File

@ -51,10 +51,10 @@
this.columnHeaderFileName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.checkBoxTranslateToEnglish = new System.Windows.Forms.CheckBox();
this.contextMenuStripWhisperAdvanced = new System.Windows.Forms.ContextMenuStrip(this.components);
this.setCPPConstmeModelsFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.removeTemporaryFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.labelEngine = new System.Windows.Forms.Label();
this.comboBoxWhisperEngine = new System.Windows.Forms.ComboBox();
this.setCPPConstmeModelsFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxModels.SuspendLayout();
this.groupBoxInputFiles.SuspendLayout();
this.contextMenuStripWhisperAdvanced.SuspendLayout();
@ -291,11 +291,19 @@
this.removeTemporaryFilesToolStripMenuItem});
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(259, 70);
this.contextMenuStripWhisperAdvanced.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStripWhisperAdvanced_Opening);
//
// setCPPConstmeModelsFolderToolStripMenuItem
//
this.setCPPConstmeModelsFolderToolStripMenuItem.Name = "setCPPConstmeModelsFolderToolStripMenuItem";
this.setCPPConstmeModelsFolderToolStripMenuItem.Size = new System.Drawing.Size(258, 22);
this.setCPPConstmeModelsFolderToolStripMenuItem.Text = "Set CPP/Const-me models folder...";
this.setCPPConstmeModelsFolderToolStripMenuItem.Click += new System.EventHandler(this.setCPPConstMeModelsFolderToolStripMenuItem_Click);
//
// removeTemporaryFilesToolStripMenuItem
//
this.removeTemporaryFilesToolStripMenuItem.Name = "removeTemporaryFilesToolStripMenuItem";
this.removeTemporaryFilesToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.removeTemporaryFilesToolStripMenuItem.Size = new System.Drawing.Size(258, 22);
this.removeTemporaryFilesToolStripMenuItem.Text = "Remove temporary files";
this.removeTemporaryFilesToolStripMenuItem.Click += new System.EventHandler(this.removeTemporaryFilesToolStripMenuItem_Click);
//
@ -320,12 +328,6 @@
this.comboBoxWhisperEngine.TabIndex = 28;
this.comboBoxWhisperEngine.SelectedIndexChanged += new System.EventHandler(this.comboBoxWhisperEngine_SelectedIndexChanged);
//
// setCPPConstmeModelsFolderToolStripMenuItem
//
this.setCPPConstmeModelsFolderToolStripMenuItem.Name = "setCPPConstmeModelsFolderToolStripMenuItem";
this.setCPPConstmeModelsFolderToolStripMenuItem.Size = new System.Drawing.Size(258, 22);
this.setCPPConstmeModelsFolderToolStripMenuItem.Text = "Set CPP/Const-me models folder...";
//
// WhisperAudioToTextSelectedLines
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -561,5 +561,29 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
WhisperEngineCTranslate2();
}
}
private void setCPPConstMeModelsFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
using (var folderBrowserDialog1 = new FolderBrowserDialog())
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
Configuration.Settings.Tools.WhisperCppModelLocation = folderBrowserDialog1.SelectedPath;
}
}
}
private void contextMenuStripWhisperAdvanced_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperCppModelLocation) &&
Directory.Exists(Configuration.Settings.Tools.WhisperCppModelLocation))
{
setCPPConstmeModelsFolderToolStripMenuItem.Text = $"Set CPP/Const-me models folder... [{Configuration.Settings.Tools.WhisperCppModelLocation}]";
}
else
{
setCPPConstmeModelsFolderToolStripMenuItem.Text = "Set CPP/Const-me models folder...";
}
}
}
}