This commit is contained in:
niksedk 2023-01-16 18:07:54 +01:00
parent 8190ce5552
commit 8ce133f357
10 changed files with 100 additions and 50 deletions

View File

@ -33,6 +33,7 @@
* Update Whisper CPP to 2023-01-08
* Rename "Fix dialogs on one line" to "Break dialogs on one line"
* Update Tesseract 5.2.0 to 5.3.0
* Improve convert of WebVTT to SubRip style handling - thx maknol
* FIXED:
* Fix italic in DCinema interop - thx Andrey
* Fix Whisper model download - thx darnn

View File

@ -0,0 +1,9 @@
namespace Nikse.SubtitleEdit.Core.AudioToText
{
public class WhisperChoice
{
public const string OpenAI = "OpenAI";
public const string Cpp = "CPP";
public const string WhisperX = "WhisperX";
}
}

View File

@ -8,17 +8,17 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
{
public static IWhisperModel GetWhisperModel()
{
return Configuration.Settings.Tools.WhisperUseCpp ? (IWhisperModel)new WhisperCppModel() : new WhisperModel();
return Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp ? (IWhisperModel)new WhisperCppModel() : new WhisperModel();
}
public static string ModelExtension()
{
return Configuration.Settings.Tools.WhisperUseCpp ? ".bin" : ".pt";
return Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp ? ".bin" : ".pt";
}
public static string GetWebSiteUrl()
{
return Configuration.Settings.Tools.WhisperUseCpp ? "https://github.com/ggerganov/whisper.cpp" : "https://github.com/openai/whisper";
return Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp ? "https://github.com/ggerganov/whisper.cpp" : "https://github.com/openai/whisper";
}
public static bool IsWhisperInstalled()
@ -33,7 +33,7 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
public static string GetWhisperFolder()
{
if (Configuration.IsRunningOnLinux && Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.IsRunningOnLinux && Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp)
{
var path = Path.Combine(Configuration.DataDirectory, "Whisper");
return Directory.Exists(path) ? path : null;
@ -60,7 +60,7 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
}
}
if (Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp)
{
var path = Path.Combine(Configuration.DataDirectory, "Whisper");
return Directory.Exists(path) ? path : null;
@ -100,7 +100,7 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
if (Configuration.IsRunningOnWindows)
{
if (Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.Settings.Tools.WhisperChoice == "CPP")
{
var f = Path.Combine(GetWhisperFolder(), "main.exe");
if (File.Exists(f))
@ -108,6 +108,14 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
return f;
}
}
else if (Configuration.Settings.Tools.WhisperChoice == "WhisperX")
{
var f = Path.Combine(GetWhisperFolder(), "whisperx.exe");
if (File.Exists(f))
{
return f;
}
}
else
{
var f = Path.Combine(GetWhisperFolder(), "whisper.exe");
@ -118,7 +126,7 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
}
}
if (Configuration.IsRunningOnLinux && Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.IsRunningOnLinux && Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp)
{
var f = Path.Combine(GetWhisperFolder(), "main");
if (File.Exists(f))
@ -126,13 +134,21 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
return f;
}
}
else if (Configuration.IsRunningOnLinux && Configuration.Settings.Tools.WhisperChoice == "WhisperX")
{
var f = Path.Combine(GetWhisperFolder(), "whisperx");
if (File.Exists(f))
{
return f;
}
}
return "whisper";
}
public static string GetWhisperModelForCmdLine(string model)
{
if (Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp)
{
return Path.Combine(GetWhisperModel().ModelFolder, model + ModelExtension());
}
@ -142,7 +158,7 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
public static string GetWhisperTranslateParameter()
{
return Configuration.Settings.Tools.WhisperUseCpp ? "--translate " : "--task translate ";
return Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp ? "--translate " : "--task translate ";
}
}
}

View File

@ -267,6 +267,20 @@ namespace Nikse.SubtitleEdit.Core.Common
// though advertised, this code page is not supported
}
}
try
{
var enc = Encoding.GetEncoding(28606);
if (!encodings.Contains(enc))
{
encodings.Add(enc);
}
}
catch
{
// ignore
}
return encodings.AsEnumerable();
}

View File

@ -416,11 +416,12 @@ namespace Nikse.SubtitleEdit.Core.Common
public bool GenVideoNonAssaFixRtlUnicode { get; set; }
public bool VoskPostProcessing { get; set; }
public string VoskModel { get; set; }
public bool WhisperUseCpp { get; set; }
public string WhisperChoice { get; set; }
public bool WhisperDeleteTempFiles { get; set; }
public string WhisperModel { get; set; }
public string WhisperLanguageCode { get; set; }
public string WhisperLocation { get; set; }
public string WhisperXLocation { get; set; }
public string WhisperExtraSettings { get; set; }
public bool WhisperAutoAdjustTimings { get; set; }
public int AudioToTextLineMaxChars { get; set; }
@ -627,7 +628,7 @@ namespace Nikse.SubtitleEdit.Core.Common
GenVideoFontSizePercentOfHeight = 0.078f;
GenVideoNonAssaBox = true;
VoskPostProcessing = true;
WhisperUseCpp = Configuration.IsRunningOnWindows;
WhisperChoice = Configuration.IsRunningOnWindows ? AudioToText.WhisperChoice.Cpp : AudioToText.WhisperChoice.OpenAI;
WhisperDeleteTempFiles = true;
WhisperExtraSettings = "";
WhisperLanguageCode = "en";
@ -6209,10 +6210,10 @@ $HorzAlign = Center
settings.Tools.VoskModel = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperUseCpp");
subNode = node.SelectSingleNode("WhisperChoice");
if (subNode != null)
{
settings.Tools.WhisperUseCpp = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
settings.Tools.WhisperChoice = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperDeleteTempFiles");
@ -6233,6 +6234,12 @@ $HorzAlign = Center
settings.Tools.WhisperLocation = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperXLocation");
if (subNode != null)
{
settings.Tools.WhisperXLocation = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperExtraSettings");
if (subNode != null)
{
@ -10540,10 +10547,11 @@ $HorzAlign = Center
textWriter.WriteElementString("GenVideoNonAssaFixRtlUnicode", settings.Tools.GenVideoNonAssaFixRtlUnicode.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("VoskPostProcessing", settings.Tools.VoskPostProcessing.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("VoskModel", settings.Tools.VoskModel);
textWriter.WriteElementString("WhisperUseCpp", settings.Tools.WhisperUseCpp.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WhisperChoice", settings.Tools.WhisperChoice);
textWriter.WriteElementString("WhisperDeleteTempFiles", settings.Tools.WhisperDeleteTempFiles.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WhisperModel", settings.Tools.WhisperModel);
textWriter.WriteElementString("WhisperLocation", settings.Tools.WhisperLocation);
textWriter.WriteElementString("WhisperXLocation", settings.Tools.WhisperXLocation);
textWriter.WriteElementString("WhisperExtraSettings", settings.Tools.WhisperExtraSettings);
textWriter.WriteElementString("WhisperLanguageCode", settings.Tools.WhisperLanguageCode);
textWriter.WriteElementString("WhisperAutoAdjustTimings", settings.Tools.WhisperAutoAdjustTimings.ToString(CultureInfo.InvariantCulture));

View File

@ -355,13 +355,13 @@
// labelCpp
//
this.labelCpp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelCpp.AutoSize = true;
this.labelCpp.ForeColor = System.Drawing.SystemColors.ControlDark;
this.labelCpp.Location = new System.Drawing.Point(669, 9);
this.labelCpp.Location = new System.Drawing.Point(580, 9);
this.labelCpp.Name = "labelCpp";
this.labelCpp.Size = new System.Drawing.Size(28, 13);
this.labelCpp.Size = new System.Drawing.Size(117, 13);
this.labelCpp.TabIndex = 21;
this.labelCpp.Text = "CPP";
this.labelCpp.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelElapsed
//

View File

@ -112,10 +112,11 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
FillModels(comboBoxModels, string.Empty);
labelFC.Text = string.Empty;
labelCpp.Visible = Configuration.Settings.Tools.WhisperUseCpp;
labelCpp.Text = Configuration.Settings.Tools.WhisperChoice;
labelCpp.Visible = true;
whisperCppCToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperUseCpp;
whisperPhpOriginalToolStripMenuItem.Checked = !Configuration.Settings.Tools.WhisperUseCpp;
whisperCppCToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp;
whisperPhpOriginalToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.OpenAI;
removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles;
ContextMenuStrip = contextMenuStripWhisperAdvanced;
}
@ -467,7 +468,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
_resultList = new List<ResultText>();
var process = GetWhisperProcess(waveFileName, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, OutputHandler);
var sw = Stopwatch.StartNew();
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.WhisperUseCpp ? "-CPP" : string.Empty)} with : {process.StartInfo.FileName} {process.StartInfo.Arguments}");
_outputText.Add($"Calling whisper ({Configuration.Settings.Tools.WhisperChoice}) with : {process.StartInfo.FileName} {process.StartInfo.Arguments}");
_startTicks = DateTime.UtcNow.Ticks;
_videoInfo = UiUtil.GetVideoInfo(waveFileName);
timer1.Start();
@ -507,7 +508,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
}
}
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.WhisperUseCpp ? "-CPP" : string.Empty)} done in {sw.Elapsed}{Environment.NewLine}");
_outputText.Add($"Calling whisper {Configuration.Settings.Tools.WhisperChoice}) done in {sw.Elapsed}{Environment.NewLine}");
for (var i = 0; i < 10; i++)
{
@ -826,7 +827,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
translateToEnglish = string.Empty;
}
if (Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp)
{
if (!Configuration.Settings.Tools.WhisperExtraSettings.Contains("--print-progress"))
{
@ -850,7 +851,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
}
var outputSrt = string.Empty;
if (Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp)
{
outputSrt = "--output-srt ";
@ -882,7 +883,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
process.StartInfo.EnvironmentVariables["Path"] = process.StartInfo.EnvironmentVariables["Path"].TrimEnd(';') + ";" + whisperFolder;
}
if (!Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.Settings.Tools.WhisperChoice != WhisperChoice.Cpp)
{
process.StartInfo.EnvironmentVariables["PYTHONIOENCODING"] = "utf-8";
process.StartInfo.EnvironmentVariables["PYTHONLEGACYWINDOWSSTDIO"] = "utf-8";
@ -1236,7 +1237,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private void whisperPhpOriginalToolStripMenuItem_Click(object sender, EventArgs e)
{
Configuration.Settings.Tools.WhisperUseCpp = false;
Configuration.Settings.Tools.WhisperChoice = "OpenAI";
if (Configuration.IsRunningOnWindows)
{
@ -1251,7 +1252,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
if (openFileDialog1.ShowDialog() != DialogResult.OK || !openFileDialog1.FileName.EndsWith("whisper.exe", StringComparison.OrdinalIgnoreCase))
{
Configuration.Settings.Tools.WhisperUseCpp = true;
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.Cpp;
}
else
{
@ -1266,7 +1267,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private void whisperCppCToolStripMenuItem_Click(object sender, EventArgs e)
{
Configuration.Settings.Tools.WhisperUseCpp = true;
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.Cpp;
Init();
}

View File

@ -287,13 +287,13 @@
// labelCpp
//
this.labelCpp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelCpp.AutoSize = true;
this.labelCpp.ForeColor = System.Drawing.SystemColors.ControlDark;
this.labelCpp.Location = new System.Drawing.Point(669, 9);
this.labelCpp.Location = new System.Drawing.Point(589, 9);
this.labelCpp.Name = "labelCpp";
this.labelCpp.Size = new System.Drawing.Size(28, 13);
this.labelCpp.Size = new System.Drawing.Size(108, 13);
this.labelCpp.TabIndex = 22;
this.labelCpp.Text = "CPP";
this.labelCpp.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// contextMenuStripWhisperAdvanced
//
@ -303,31 +303,31 @@
this.toolStripSeparator1,
this.removeTemporaryFilesToolStripMenuItem});
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(200, 98);
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(210, 76);
//
// whisperPhpOriginalToolStripMenuItem
//
this.whisperPhpOriginalToolStripMenuItem.Name = "whisperPhpOriginalToolStripMenuItem";
this.whisperPhpOriginalToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.whisperPhpOriginalToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.whisperPhpOriginalToolStripMenuItem.Text = "Whisper OpenAI (Python)";
this.whisperPhpOriginalToolStripMenuItem.Click += new System.EventHandler(this.whisperPhpOriginalToolStripMenuItem_Click);
//
// whisperCppCToolStripMenuItem
//
this.whisperCppCToolStripMenuItem.Name = "whisperCppCToolStripMenuItem";
this.whisperCppCToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.whisperCppCToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.whisperCppCToolStripMenuItem.Text = "Whisper cpp (C++)";
this.whisperCppCToolStripMenuItem.Click += new System.EventHandler(this.whisperCppCToolStripMenuItem_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(196, 6);
this.toolStripSeparator1.Size = new System.Drawing.Size(206, 6);
//
// removeTemporaryFilesToolStripMenuItem
//
this.removeTemporaryFilesToolStripMenuItem.Name = "removeTemporaryFilesToolStripMenuItem";
this.removeTemporaryFilesToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.removeTemporaryFilesToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.removeTemporaryFilesToolStripMenuItem.Text = "Remove temporary files";
this.removeTemporaryFilesToolStripMenuItem.Click += new System.EventHandler(this.removeTemporaryFilesToolStripMenuItem_Click);
//

View File

@ -62,7 +62,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
listViewInputFiles.Visible = true;
_audioClips = audioClips;
progressBar1.Maximum = 100;
labelCpp.Visible = Configuration.Settings.Tools.WhisperUseCpp;
labelCpp.Visible = true;
labelCpp.Text = Configuration.Settings.Tools.WhisperChoice;
foreach (var audioClip in audioClips)
{
listViewInputFiles.Items.Add(audioClip.AudioFileName);
@ -77,8 +78,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
comboBoxLanguages.Text = lang != null ? lang.ToString() : "English";
WhisperAudioToText.FillModels(comboBoxModels, string.Empty);
whisperCppCToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperUseCpp;
whisperPhpOriginalToolStripMenuItem.Checked = !Configuration.Settings.Tools.WhisperUseCpp;
whisperCppCToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp;
whisperPhpOriginalToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.OpenAI;
removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles;
ContextMenuStrip = contextMenuStripWhisperAdvanced;
}
@ -179,7 +180,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
_resultList = new List<ResultText>();
var process = WhisperAudioToText.GetWhisperProcess(waveFileName, model.Name, _languageCode, checkBoxTranslateToEnglish.Checked, OutputHandler);
var sw = Stopwatch.StartNew();
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.WhisperUseCpp ? "-CPP" : string.Empty)} with : whisper {process.StartInfo.Arguments}");
_outputText.Add($"Calling whisper ({Configuration.Settings.Tools.WhisperChoice}) with : whisper {process.StartInfo.Arguments}");
buttonCancel.Visible = true;
try
{
@ -215,7 +216,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
}
}
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.WhisperUseCpp ? "-CPP" : string.Empty)} done in {sw.Elapsed}{Environment.NewLine}");
_outputText.Add($"Calling whisper ({Configuration.Settings.Tools.WhisperChoice} done in {sw.Elapsed}{Environment.NewLine}");
for (var i = 0; i < 10; i++)
{
@ -430,7 +431,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private void whisperPhpOriginalToolStripMenuItem_Click(object sender, EventArgs e)
{
Configuration.Settings.Tools.WhisperUseCpp = false;
Configuration.Settings.Tools.WhisperChoice = "OpenAI";
if (Configuration.IsRunningOnWindows)
{
@ -445,7 +446,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
if (openFileDialog1.ShowDialog() != DialogResult.OK || !openFileDialog1.FileName.EndsWith("whisper.exe", StringComparison.OrdinalIgnoreCase))
{
Configuration.Settings.Tools.WhisperUseCpp = true;
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.Cpp;
}
else
{
@ -460,7 +461,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private void whisperCppCToolStripMenuItem_Click(object sender, EventArgs e)
{
Configuration.Settings.Tools.WhisperUseCpp = true;
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.Cpp;
Init();
}

View File

@ -34765,7 +34765,7 @@ namespace Nikse.SubtitleEdit.Forms
return;
}
if (Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp)
{
if (!RequireWhisperCpp())
{
@ -34831,21 +34831,21 @@ namespace Nikse.SubtitleEdit.Forms
private static void CheckWhisperCpp()
{
if (!Configuration.Settings.Tools.WhisperUseCpp)
if (Configuration.Settings.Tools.WhisperChoice != WhisperChoice.Cpp)
{
return;
}
if (Configuration.IsRunningOnLinux && WhisperHelper.GetWhisperPathAndFileName() == "whisper")
{
SeLogger.Error("UseWhisperCpp changed to 'False' as 'Whisper/whisper' or '/Whisper/main' was not found!");
Configuration.Settings.Tools.WhisperUseCpp = false;
SeLogger.Error("UseWhisperChoice changed to 'OpenAI' as 'Whisper/whisper' or '/Whisper/main' was not found!");
Configuration.Settings.Tools.WhisperChoice = "OpenAI";
}
if (Configuration.IsRunningOnWindows && WhisperHelper.GetWhisperPathAndFileName() == "whisper")
{
SeLogger.Error("UseWhisperCpp changed to 'False' as 'Whisper/whisper.exe' or '/Whisper/main.exe' was not found!");
Configuration.Settings.Tools.WhisperUseCpp = false;
SeLogger.Error("UseWhisperChoice changed to 'OpenAI' as 'Whisper/whisper.exe' or '/Whisper/main.exe' was not found!");
Configuration.Settings.Tools.WhisperChoice = "OpenAI";
}
}