mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 20:52:44 +01:00
Minor fix for whisper UI
This commit is contained in:
parent
828cd46efb
commit
7695391c47
@ -15,6 +15,7 @@
|
||||
* Update Bulgarian translation - thx Калин
|
||||
* Update Korean translation - thx domddol
|
||||
* Update Polish translation - thx admas
|
||||
* Update Greek translation - thx PMitsakis
|
||||
* Optimize bd sup saving in batch/cmd-line convert
|
||||
* Add a few English words/names to dictionaries
|
||||
* Add more settings for "Delete auto-backup after" - thx pahtashow
|
||||
|
@ -8,17 +8,17 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
|
||||
{
|
||||
public static IWhisperModel GetWhisperModel()
|
||||
{
|
||||
return Configuration.Settings.Tools.UseWhisperCpp ? (IWhisperModel)new WhisperCppModel() : new WhisperModel();
|
||||
return Configuration.Settings.Tools.WhisperUseCpp ? (IWhisperModel)new WhisperCppModel() : new WhisperModel();
|
||||
}
|
||||
|
||||
public static string ModelExtension()
|
||||
{
|
||||
return Configuration.Settings.Tools.UseWhisperCpp ? ".bin" : ".pt";
|
||||
return Configuration.Settings.Tools.WhisperUseCpp ? ".bin" : ".pt";
|
||||
}
|
||||
|
||||
public static string GetWebSiteUrl()
|
||||
{
|
||||
return Configuration.Settings.Tools.UseWhisperCpp ? "https://github.com/ggerganov/whisper.cpp" : "https://github.com/openai/whisper";
|
||||
return Configuration.Settings.Tools.WhisperUseCpp ? "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.UseWhisperCpp)
|
||||
if (Configuration.IsRunningOnLinux && Configuration.Settings.Tools.WhisperUseCpp)
|
||||
{
|
||||
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.UseWhisperCpp)
|
||||
if (Configuration.Settings.Tools.WhisperUseCpp)
|
||||
{
|
||||
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.UseWhisperCpp)
|
||||
if (Configuration.Settings.Tools.WhisperUseCpp)
|
||||
{
|
||||
var f = Path.Combine(GetWhisperFolder(), "main.exe");
|
||||
if (File.Exists(f))
|
||||
@ -118,7 +118,7 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
|
||||
}
|
||||
}
|
||||
|
||||
if (Configuration.IsRunningOnLinux && Configuration.Settings.Tools.UseWhisperCpp)
|
||||
if (Configuration.IsRunningOnLinux && Configuration.Settings.Tools.WhisperUseCpp)
|
||||
{
|
||||
var f = Path.Combine(GetWhisperFolder(), "main");
|
||||
if (File.Exists(f))
|
||||
@ -132,7 +132,7 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
|
||||
|
||||
public static string GetWhisperModelForCmdLine(string model)
|
||||
{
|
||||
if (Configuration.Settings.Tools.UseWhisperCpp)
|
||||
if (Configuration.Settings.Tools.WhisperUseCpp)
|
||||
{
|
||||
return Path.Combine(GetWhisperModel().ModelFolder, model + ModelExtension());
|
||||
}
|
||||
|
@ -410,7 +410,8 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
public bool GenVideoNonAssaFixRtlUnicode { get; set; }
|
||||
public bool VoskPostProcessing { get; set; }
|
||||
public string VoskModel { get; set; }
|
||||
public bool UseWhisperCpp { get; set; }
|
||||
public bool WhisperUseCpp { get; set; }
|
||||
public bool WhisperDeleteTempFiles { get; set; }
|
||||
public string WhisperModel { get; set; }
|
||||
public string WhisperLanguageCode { get; set; }
|
||||
public string WhisperLocation { get; set; }
|
||||
@ -614,7 +615,8 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
GenVideoFontSizePercentOfHeight = 0.078f;
|
||||
GenVideoNonAssaBox = true;
|
||||
VoskPostProcessing = true;
|
||||
UseWhisperCpp = Configuration.IsRunningOnWindows;
|
||||
WhisperUseCpp = Configuration.IsRunningOnWindows;
|
||||
WhisperDeleteTempFiles = true;
|
||||
WhisperExtraSettings = "";
|
||||
WhisperLanguageCode = "en";
|
||||
AudioToTextLineMaxChars = 86;
|
||||
@ -6131,10 +6133,16 @@ $HorzAlign = Center
|
||||
settings.Tools.VoskModel = subNode.InnerText;
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("UseWhisperCpp");
|
||||
subNode = node.SelectSingleNode("WhisperUseCpp");
|
||||
if (subNode != null)
|
||||
{
|
||||
settings.Tools.UseWhisperCpp = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
|
||||
settings.Tools.WhisperUseCpp = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("WhisperDeleteTempFiles");
|
||||
if (subNode != null)
|
||||
{
|
||||
settings.Tools.WhisperDeleteTempFiles = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("WhisperModel");
|
||||
@ -10406,7 +10414,8 @@ $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("UseWhisperCpp", settings.Tools.UseWhisperCpp.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("WhisperUseCpp", settings.Tools.WhisperUseCpp.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("WhisperDeleteTempFiles", settings.Tools.WhisperDeleteTempFiles.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("WhisperModel", settings.Tools.WhisperModel);
|
||||
textWriter.WriteElementString("WhisperLocation", settings.Tools.WhisperLocation);
|
||||
textWriter.WriteElementString("WhisperExtraSettings", settings.Tools.WhisperExtraSettings);
|
||||
|
@ -143,7 +143,6 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
buttonBatchMode.Enabled = false;
|
||||
comboBoxModels.Enabled = false;
|
||||
var waveFileName = GenerateWavFile(_videoFileName, _audioTrackNumber);
|
||||
textBoxLog.AppendText("Wav file name: " + waveFileName);
|
||||
textBoxLog.AppendText(Environment.NewLine);
|
||||
progressBar1.Style = ProgressBarStyle.Blocks;
|
||||
var transcript = TranscribeViaVosk(waveFileName, modelFileName);
|
||||
@ -201,7 +200,6 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
continue;
|
||||
}
|
||||
|
||||
textBoxLog.AppendText("Wav file name: " + waveFileName + Environment.NewLine);
|
||||
progressBar1.Style = ProgressBarStyle.Blocks;
|
||||
var transcript = TranscribeViaVosk(waveFileName, modelFileName);
|
||||
if (_cancel)
|
||||
|
@ -114,7 +114,6 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
buttonDownload.Enabled = false;
|
||||
comboBoxModels.Enabled = false;
|
||||
var waveFileName = videoFileName;
|
||||
textBoxLog.AppendText("Wav file name: " + waveFileName + Environment.NewLine);
|
||||
var transcript = TranscribeViaVosk(waveFileName, modelFileName);
|
||||
if (_cancel)
|
||||
{
|
||||
|
@ -58,8 +58,10 @@
|
||||
this.labelCpp = new System.Windows.Forms.Label();
|
||||
this.labelElapsed = new System.Windows.Forms.Label();
|
||||
this.contextMenuStripWhisperAdvanced = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.speedupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.noneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.whisperPhpOriginalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.whisperCppCToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.removeTemporaryFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.groupBoxModels.SuspendLayout();
|
||||
this.groupBoxInputFiles.SuspendLayout();
|
||||
this.contextMenuStripWhisperAdvanced.SuspendLayout();
|
||||
@ -373,24 +375,38 @@
|
||||
// contextMenuStripWhisperAdvanced
|
||||
//
|
||||
this.contextMenuStripWhisperAdvanced.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.noneToolStripMenuItem,
|
||||
this.speedupToolStripMenuItem});
|
||||
this.whisperPhpOriginalToolStripMenuItem,
|
||||
this.whisperCppCToolStripMenuItem,
|
||||
this.toolStripSeparator1,
|
||||
this.removeTemporaryFilesToolStripMenuItem});
|
||||
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
|
||||
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(181, 70);
|
||||
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(200, 98);
|
||||
//
|
||||
// speedupToolStripMenuItem
|
||||
// whisperPhpOriginalToolStripMenuItem
|
||||
//
|
||||
this.speedupToolStripMenuItem.Name = "speedupToolStripMenuItem";
|
||||
this.speedupToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.speedupToolStripMenuItem.Text = "--speed-up";
|
||||
this.speedupToolStripMenuItem.Click += new System.EventHandler(this.speedupToolStripMenuItem_Click);
|
||||
this.whisperPhpOriginalToolStripMenuItem.Name = "whisperPhpOriginalToolStripMenuItem";
|
||||
this.whisperPhpOriginalToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
|
||||
this.whisperPhpOriginalToolStripMenuItem.Text = "Whisper php (original)";
|
||||
this.whisperPhpOriginalToolStripMenuItem.Click += new System.EventHandler(this.whisperPhpOriginalToolStripMenuItem_Click);
|
||||
//
|
||||
// noneToolStripMenuItem
|
||||
// whisperCppCToolStripMenuItem
|
||||
//
|
||||
this.noneToolStripMenuItem.Name = "noneToolStripMenuItem";
|
||||
this.noneToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.noneToolStripMenuItem.Text = "(none)";
|
||||
this.noneToolStripMenuItem.Click += new System.EventHandler(this.noneToolStripMenuItem_Click);
|
||||
this.whisperCppCToolStripMenuItem.Name = "whisperCppCToolStripMenuItem";
|
||||
this.whisperCppCToolStripMenuItem.Size = new System.Drawing.Size(199, 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);
|
||||
//
|
||||
// removeTemporaryFilesToolStripMenuItem
|
||||
//
|
||||
this.removeTemporaryFilesToolStripMenuItem.Name = "removeTemporaryFilesToolStripMenuItem";
|
||||
this.removeTemporaryFilesToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
|
||||
this.removeTemporaryFilesToolStripMenuItem.Text = "Remove temporary files";
|
||||
this.removeTemporaryFilesToolStripMenuItem.Click += new System.EventHandler(this.removeTemporaryFilesToolStripMenuItem_Click);
|
||||
//
|
||||
// WhisperAudioToText
|
||||
//
|
||||
@ -465,7 +481,9 @@
|
||||
private System.Windows.Forms.Label labelCpp;
|
||||
private System.Windows.Forms.Label labelElapsed;
|
||||
private System.Windows.Forms.ContextMenuStrip contextMenuStripWhisperAdvanced;
|
||||
private System.Windows.Forms.ToolStripMenuItem speedupToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem noneToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem whisperPhpOriginalToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem whisperCppCToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
private System.Windows.Forms.ToolStripMenuItem removeTemporaryFilesToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
private bool _cancel;
|
||||
private bool _batchMode;
|
||||
private int _batchFileNumber;
|
||||
private readonly List<string> _filesToDelete;
|
||||
private List<string> _filesToDelete;
|
||||
private readonly Form _parentForm;
|
||||
private bool _useCenterChannelOnly;
|
||||
private int _initialWidth = 725;
|
||||
@ -70,17 +70,6 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
|
||||
checkBoxUsePostProcessing.Checked = Configuration.Settings.Tools.VoskPostProcessing;
|
||||
|
||||
comboBoxLanguages.Items.Clear();
|
||||
comboBoxLanguages.Items.AddRange(WhisperLanguage.Languages.OrderBy(p => p.Name).ToArray<object>());
|
||||
var lang = WhisperLanguage.Languages.FirstOrDefault(p => p.Code == Configuration.Settings.Tools.WhisperLanguageCode);
|
||||
comboBoxLanguages.Text = lang != null ? lang.ToString() : "English";
|
||||
|
||||
FillModels(comboBoxModels, string.Empty);
|
||||
|
||||
textBoxLog.Visible = false;
|
||||
textBoxLog.Dock = DockStyle.Fill;
|
||||
labelProgress.Text = string.Empty;
|
||||
labelTime.Text = string.Empty;
|
||||
_filesToDelete = new List<string>();
|
||||
|
||||
if (string.IsNullOrEmpty(videoFileName))
|
||||
@ -93,21 +82,32 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
listViewInputFiles.Items.Add(videoFileName);
|
||||
}
|
||||
|
||||
textBoxLog.Visible = false;
|
||||
textBoxLog.Dock = DockStyle.Fill;
|
||||
labelProgress.Text = string.Empty;
|
||||
labelTime.Text = string.Empty;
|
||||
listViewInputFiles.Visible = false;
|
||||
labelFC.Text = string.Empty;
|
||||
labelCpp.Visible = Configuration.Settings.Tools.UseWhisperCpp;
|
||||
labelElapsed.Text = string.Empty;
|
||||
|
||||
//if (Configuration.Settings.Tools.UseWhisperCpp)
|
||||
//{
|
||||
// speedupToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperExtraSettings == speedupToolStripMenuItem.Text;
|
||||
// ContextMenuStrip = contextMenuStripWhisperAdvanced;{}
|
||||
Init();
|
||||
}
|
||||
|
||||
// if (string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperExtraSettings))
|
||||
// {
|
||||
// noneToolStripMenuItem_Click(null, null);
|
||||
// }
|
||||
//}
|
||||
private void Init()
|
||||
{
|
||||
comboBoxLanguages.Items.Clear();
|
||||
comboBoxLanguages.Items.AddRange(WhisperLanguage.Languages.OrderBy(p => p.Name).ToArray<object>());
|
||||
var lang = WhisperLanguage.Languages.FirstOrDefault(p => p.Code == Configuration.Settings.Tools.WhisperLanguageCode);
|
||||
comboBoxLanguages.Text = lang != null ? lang.ToString() : "English";
|
||||
|
||||
FillModels(comboBoxModels, string.Empty);
|
||||
|
||||
labelFC.Text = string.Empty;
|
||||
labelCpp.Visible = Configuration.Settings.Tools.WhisperUseCpp;
|
||||
|
||||
whisperCppCToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperUseCpp;
|
||||
whisperPhpOriginalToolStripMenuItem.Checked = !Configuration.Settings.Tools.WhisperUseCpp;
|
||||
removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles;
|
||||
ContextMenuStrip = contextMenuStripWhisperAdvanced;
|
||||
}
|
||||
|
||||
public static void FillModels(ComboBox comboBoxModels, string lastDownloadedModel)
|
||||
@ -179,7 +179,6 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
comboBoxLanguages.Enabled = false;
|
||||
comboBoxModels.Enabled = false;
|
||||
var waveFileName = GenerateWavFile(_videoFileName, _audioTrackNumber);
|
||||
_outputText.Add("Wav file name: " + waveFileName);
|
||||
progressBar1.Style = ProgressBarStyle.Blocks;
|
||||
timer1.Start();
|
||||
var transcript = TranscribeViaWhisper(waveFileName);
|
||||
@ -251,7 +250,6 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
}
|
||||
|
||||
_outputText.Add(string.Empty);
|
||||
_outputText.Add("Wav file name: " + waveFileName);
|
||||
progressBar1.Style = ProgressBarStyle.Blocks;
|
||||
var transcript = TranscribeViaWhisper(waveFileName);
|
||||
if (_cancel)
|
||||
@ -339,7 +337,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.UseWhisperCpp ? "-CPP" : string.Empty)} with : {process.StartInfo.FileName} {process.StartInfo.Arguments}");
|
||||
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.WhisperUseCpp ? "-CPP" : string.Empty)} with : {process.StartInfo.FileName} {process.StartInfo.Arguments}");
|
||||
_startTicks = DateTime.UtcNow.Ticks;
|
||||
_videoInfo = UiUtil.GetVideoInfo(waveFileName);
|
||||
timer1.Start();
|
||||
@ -378,7 +376,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
}
|
||||
}
|
||||
|
||||
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.UseWhisperCpp ? "-CPP" : string.Empty)} done in {sw.Elapsed}{Environment.NewLine}");
|
||||
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.WhisperUseCpp ? "-CPP" : string.Empty)} done in {sw.Elapsed}{Environment.NewLine}");
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
@ -386,7 +384,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
System.Threading.Thread.Sleep(50);
|
||||
}
|
||||
|
||||
if (GetResultFromSrt(waveFileName, out var resultTexts, _outputText))
|
||||
if (GetResultFromSrt(waveFileName, out var resultTexts, _outputText, _filesToDelete))
|
||||
{
|
||||
return resultTexts;
|
||||
}
|
||||
@ -395,7 +393,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
return _resultList;
|
||||
}
|
||||
|
||||
public static bool GetResultFromSrt(string waveFileName, out List<ResultText> resultTexts, ConcurrentBag<string> outputText)
|
||||
public static bool GetResultFromSrt(string waveFileName, out List<ResultText> resultTexts, ConcurrentBag<string> outputText, List<string> filesToDelete)
|
||||
{
|
||||
var srtFileName = waveFileName + ".srt";
|
||||
var vttFileName = Path.Combine(WhisperHelper.GetWhisperFolder(), Path.GetFileName(waveFileName) + ".vtt");
|
||||
@ -443,21 +441,14 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
|
||||
resultTexts = results;
|
||||
|
||||
try
|
||||
if (File.Exists(srtFileName))
|
||||
{
|
||||
if (!File.Exists(srtFileName))
|
||||
{
|
||||
File.Delete(srtFileName);
|
||||
filesToDelete?.Add(srtFileName);
|
||||
}
|
||||
|
||||
if (!File.Exists(vttFileName))
|
||||
if (File.Exists(vttFileName))
|
||||
{
|
||||
File.Delete(vttFileName);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
filesToDelete?.Add(vttFileName);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -664,7 +655,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
translateToEnglish = string.Empty;
|
||||
}
|
||||
|
||||
if (Configuration.Settings.Tools.UseWhisperCpp && string.IsNullOrEmpty(translateToEnglish) && !Configuration.Settings.Tools.WhisperExtraSettings.Contains("--max-len"))
|
||||
if (Configuration.Settings.Tools.WhisperUseCpp && string.IsNullOrEmpty(translateToEnglish) && !Configuration.Settings.Tools.WhisperExtraSettings.Contains("--max-len"))
|
||||
{
|
||||
var maxChars = (int)Math.Round(Configuration.Settings.General.SubtitleLineMaximumLength * 1.8, MidpointRounding.AwayFromZero);
|
||||
if (language == "jp")
|
||||
@ -680,7 +671,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
}
|
||||
|
||||
var outputSrt = string.Empty;
|
||||
if (Configuration.Settings.Tools.UseWhisperCpp)
|
||||
if (Configuration.Settings.Tools.WhisperUseCpp)
|
||||
{
|
||||
outputSrt = "--output-srt ";
|
||||
|
||||
@ -751,7 +742,17 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
|
||||
Configuration.Settings.Tools.VoskPostProcessing = checkBoxUsePostProcessing.Checked;
|
||||
|
||||
foreach (var fileName in _filesToDelete)
|
||||
DeleteTemporaryFiles(_filesToDelete);
|
||||
}
|
||||
|
||||
public static void DeleteTemporaryFiles(List<string> filesToDelete)
|
||||
{
|
||||
if (!Configuration.Settings.Tools.WhisperDeleteTempFiles)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var fileName in filesToDelete)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -1036,18 +1037,22 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
checkBoxTranslateToEnglish.Enabled = comboBoxLanguages.Text.ToLowerInvariant() != "english";
|
||||
}
|
||||
|
||||
private void speedupToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void whisperPhpOriginalToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
noneToolStripMenuItem.Checked = false;
|
||||
speedupToolStripMenuItem.Checked = true;
|
||||
Configuration.Settings.Tools.WhisperExtraSettings = speedupToolStripMenuItem.Text;
|
||||
Configuration.Settings.Tools.WhisperUseCpp = false;
|
||||
Init();
|
||||
}
|
||||
|
||||
private void noneToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void whisperCppCToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
noneToolStripMenuItem.Checked = true;
|
||||
speedupToolStripMenuItem.Checked = false;
|
||||
Configuration.Settings.Tools.WhisperExtraSettings = string.Empty;
|
||||
Configuration.Settings.Tools.WhisperUseCpp = true;
|
||||
Init();
|
||||
}
|
||||
|
||||
private void removeTemporaryFilesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Configuration.Settings.Tools.WhisperDeleteTempFiles = !Configuration.Settings.Tools.WhisperDeleteTempFiles;
|
||||
removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,14 @@
|
||||
this.columnHeaderFileName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.checkBoxTranslateToEnglish = new System.Windows.Forms.CheckBox();
|
||||
this.labelCpp = new System.Windows.Forms.Label();
|
||||
this.contextMenuStripWhisperAdvanced = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.whisperPhpOriginalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.whisperCppCToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.removeTemporaryFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.groupBoxModels.SuspendLayout();
|
||||
this.groupBoxInputFiles.SuspendLayout();
|
||||
this.contextMenuStripWhisperAdvanced.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
@ -289,6 +295,42 @@
|
||||
this.labelCpp.TabIndex = 22;
|
||||
this.labelCpp.Text = "CPP";
|
||||
//
|
||||
// contextMenuStripWhisperAdvanced
|
||||
//
|
||||
this.contextMenuStripWhisperAdvanced.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.whisperPhpOriginalToolStripMenuItem,
|
||||
this.whisperCppCToolStripMenuItem,
|
||||
this.toolStripSeparator1,
|
||||
this.removeTemporaryFilesToolStripMenuItem});
|
||||
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
|
||||
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(200, 98);
|
||||
//
|
||||
// whisperPhpOriginalToolStripMenuItem
|
||||
//
|
||||
this.whisperPhpOriginalToolStripMenuItem.Name = "whisperPhpOriginalToolStripMenuItem";
|
||||
this.whisperPhpOriginalToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
|
||||
this.whisperPhpOriginalToolStripMenuItem.Text = "Whisper php (original)";
|
||||
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.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);
|
||||
//
|
||||
// removeTemporaryFilesToolStripMenuItem
|
||||
//
|
||||
this.removeTemporaryFilesToolStripMenuItem.Name = "removeTemporaryFilesToolStripMenuItem";
|
||||
this.removeTemporaryFilesToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
|
||||
this.removeTemporaryFilesToolStripMenuItem.Text = "Remove temporary files";
|
||||
this.removeTemporaryFilesToolStripMenuItem.Click += new System.EventHandler(this.removeTemporaryFilesToolStripMenuItem_Click);
|
||||
//
|
||||
// WhisperAudioToTextSelectedLines
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@ -322,6 +364,7 @@
|
||||
this.groupBoxModels.ResumeLayout(false);
|
||||
this.groupBoxModels.PerformLayout();
|
||||
this.groupBoxInputFiles.ResumeLayout(false);
|
||||
this.contextMenuStripWhisperAdvanced.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@ -351,5 +394,10 @@
|
||||
private System.Windows.Forms.ComboBox comboBoxLanguages;
|
||||
private System.Windows.Forms.CheckBox checkBoxTranslateToEnglish;
|
||||
private System.Windows.Forms.Label labelCpp;
|
||||
private System.Windows.Forms.ContextMenuStrip contextMenuStripWhisperAdvanced;
|
||||
private System.Windows.Forms.ToolStripMenuItem whisperPhpOriginalToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem whisperCppCToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
private System.Windows.Forms.ToolStripMenuItem removeTemporaryFilesToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
private int _batchFileNumber;
|
||||
private readonly List<AudioClipsGet.AudioClip> _audioClips;
|
||||
private readonly Form _parentForm;
|
||||
private readonly List<string> _filesToDelete;
|
||||
private readonly Regex _timeRegex = new Regex(@"^\[\d\d:\d\d[\.,]\d\d\d --> \d\d:\d\d[\.,]\d\d\d\]", RegexOptions.Compiled);
|
||||
private List<ResultText> _resultList;
|
||||
private string _languageCode;
|
||||
@ -33,6 +34,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
UiUtil.FixFonts(this);
|
||||
UiUtil.FixLargeFonts(this, buttonGenerate);
|
||||
_parentForm = parentForm;
|
||||
_filesToDelete = new List<string>();
|
||||
|
||||
Text = LanguageSettings.Current.AudioToText.Title;
|
||||
labelInfo.Text = LanguageSettings.Current.AudioToText.WhisperInfo;
|
||||
@ -51,12 +53,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
|
||||
checkBoxUsePostProcessing.Checked = Configuration.Settings.Tools.VoskPostProcessing;
|
||||
|
||||
comboBoxLanguages.Items.Clear();
|
||||
comboBoxLanguages.Items.AddRange(WhisperLanguage.Languages.OrderBy(p => p.Name).ToArray<object>());
|
||||
var lang = WhisperLanguage.Languages.FirstOrDefault(p => p.Code == Configuration.Settings.Tools.WhisperLanguageCode);
|
||||
comboBoxLanguages.Text = lang != null ? lang.ToString() : "English";
|
||||
|
||||
WhisperAudioToText.FillModels(comboBoxModels, string.Empty);
|
||||
Init();
|
||||
|
||||
textBoxLog.Visible = false;
|
||||
textBoxLog.Dock = DockStyle.Fill;
|
||||
@ -65,13 +62,27 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
listViewInputFiles.Visible = true;
|
||||
_audioClips = audioClips;
|
||||
progressBar1.Maximum = 100;
|
||||
labelCpp.Visible = Configuration.Settings.Tools.UseWhisperCpp;
|
||||
labelCpp.Visible = Configuration.Settings.Tools.WhisperUseCpp;
|
||||
foreach (var audioClip in audioClips)
|
||||
{
|
||||
listViewInputFiles.Items.Add(audioClip.AudioFileName);
|
||||
}
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
comboBoxLanguages.Items.Clear();
|
||||
comboBoxLanguages.Items.AddRange(WhisperLanguage.Languages.OrderBy(p => p.Name).ToArray<object>());
|
||||
var lang = WhisperLanguage.Languages.FirstOrDefault(p => p.Code == Configuration.Settings.Tools.WhisperLanguageCode);
|
||||
comboBoxLanguages.Text = lang != null ? lang.ToString() : "English";
|
||||
WhisperAudioToText.FillModels(comboBoxModels, string.Empty);
|
||||
|
||||
whisperCppCToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperUseCpp;
|
||||
whisperPhpOriginalToolStripMenuItem.Checked = !Configuration.Settings.Tools.WhisperUseCpp;
|
||||
removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles;
|
||||
ContextMenuStrip = contextMenuStripWhisperAdvanced;
|
||||
}
|
||||
|
||||
private void ButtonGenerate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxModels.Items.Count == 0)
|
||||
@ -104,12 +115,12 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
|
||||
private void GenerateBatch()
|
||||
{
|
||||
_languageCode = GetLanguage(comboBoxLanguages.Text);
|
||||
_languageCode = WhisperAudioToText.GetLanguage(comboBoxLanguages.Text);
|
||||
groupBoxInputFiles.Enabled = false;
|
||||
comboBoxLanguages.Enabled = false;
|
||||
comboBoxModels.Enabled = false;
|
||||
_batchFileNumber = 0;
|
||||
var postProcessor = new AudioToTextPostProcessor(GetLanguage(comboBoxModels.Text))
|
||||
var postProcessor = new AudioToTextPostProcessor(_languageCode)
|
||||
{
|
||||
ParagraphMaxChars = Configuration.Settings.General.SubtitleLineMaximumLength * 2,
|
||||
};
|
||||
@ -129,7 +140,6 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
var waveFileName = videoFileName;
|
||||
|
||||
_outputText.Add(string.Empty);
|
||||
_outputText.Add("Wav file name: " + waveFileName);
|
||||
progressBar1.Style = ProgressBarStyle.Blocks;
|
||||
var transcript = TranscribeViaWhisper(waveFileName);
|
||||
if (_cancel)
|
||||
@ -169,7 +179,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.UseWhisperCpp ? "-CPP" : string.Empty)} with : whisper {process.StartInfo.Arguments}");
|
||||
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.WhisperUseCpp ? "-CPP" : string.Empty)} with : whisper {process.StartInfo.Arguments}");
|
||||
ShowProgressBar();
|
||||
progressBar1.Style = ProgressBarStyle.Marquee;
|
||||
buttonCancel.Visible = true;
|
||||
@ -207,7 +217,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
}
|
||||
}
|
||||
|
||||
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.UseWhisperCpp ? "-CPP" : string.Empty)} done in {sw.Elapsed}{Environment.NewLine}");
|
||||
_outputText.Add($"Calling whisper{(Configuration.Settings.Tools.WhisperUseCpp ? "-CPP" : string.Empty)} done in {sw.Elapsed}{Environment.NewLine}");
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
@ -215,7 +225,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
System.Threading.Thread.Sleep(50);
|
||||
}
|
||||
|
||||
if (WhisperAudioToText.GetResultFromSrt(waveFileName, out var resultTexts, _outputText))
|
||||
if (WhisperAudioToText.GetResultFromSrt(waveFileName, out var resultTexts, _outputText, null))
|
||||
{
|
||||
return resultTexts;
|
||||
}
|
||||
@ -297,25 +307,6 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetLanguage(string text)
|
||||
{
|
||||
var languageCodeList = VoskModel.Models.Select(p => p.TwoLetterLanguageCode);
|
||||
foreach (var languageCode in languageCodeList)
|
||||
{
|
||||
if (text.Contains("model-" + languageCode) || text.Contains("model-small-" + languageCode) || text.StartsWith(languageCode, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return languageCode;
|
||||
}
|
||||
|
||||
if (languageCode == "jp" && (text.Contains("model-ja") || text.Contains("model-small-ja")))
|
||||
{
|
||||
return languageCode;
|
||||
}
|
||||
}
|
||||
|
||||
return "en";
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (buttonGenerate.Enabled)
|
||||
@ -345,7 +336,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
Configuration.Settings.Tools.WhisperLanguageCode = language.Code;
|
||||
}
|
||||
|
||||
Configuration.Settings.Tools.VoskPostProcessing = checkBoxUsePostProcessing.Checked;
|
||||
WhisperAudioToText.DeleteTemporaryFiles(_filesToDelete);
|
||||
}
|
||||
|
||||
private void AudioToText_KeyDown(object sender, KeyEventArgs e)
|
||||
@ -419,7 +410,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
using (var form = new WhisperModelDownload { AutoClose = true })
|
||||
{
|
||||
form.ShowDialog(this);
|
||||
VoskAudioToText.FillModels(comboBoxModels, form.LastDownloadedModel.Name);
|
||||
WhisperAudioToText.FillModels(comboBoxModels, form.LastDownloadedModel.Name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -449,5 +440,23 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
{
|
||||
checkBoxTranslateToEnglish.Enabled = comboBoxLanguages.Text.ToLowerInvariant() != "english";
|
||||
}
|
||||
|
||||
private void whisperPhpOriginalToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Configuration.Settings.Tools.WhisperUseCpp = false;
|
||||
Init();
|
||||
}
|
||||
|
||||
private void whisperCppCToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Configuration.Settings.Tools.WhisperUseCpp = true;
|
||||
Init();
|
||||
}
|
||||
|
||||
private void removeTemporaryFilesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Configuration.Settings.Tools.WhisperDeleteTempFiles = !Configuration.Settings.Tools.WhisperDeleteTempFiles;
|
||||
removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,4 +120,7 @@
|
||||
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="contextMenuStripWhisperAdvanced.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>99, 16</value>
|
||||
</metadata>
|
||||
</root>
|
@ -136,7 +136,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
}
|
||||
|
||||
buttonDownload.Enabled = true;
|
||||
labelPleaseWait.Text = string.Format(LanguageSettings.Current.SettingsFfmpeg.XDownloadOk, "Vosk model");
|
||||
labelPleaseWait.Text = string.Format(LanguageSettings.Current.SettingsFfmpeg.XDownloadOk, "Whisper model");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34677,7 +34677,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
if (Configuration.Settings.Tools.UseWhisperCpp)
|
||||
if (Configuration.Settings.Tools.WhisperUseCpp)
|
||||
{
|
||||
if (!RequireWhisperCpp())
|
||||
{
|
||||
@ -34735,7 +34735,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
|
||||
private static void CheckWhisperCpp()
|
||||
{
|
||||
if (!Configuration.Settings.Tools.UseWhisperCpp)
|
||||
if (!Configuration.Settings.Tools.WhisperUseCpp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -34743,13 +34743,13 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
if (Configuration.IsRunningOnLinux && WhisperHelper.GetWhisperPathAndFileName() == "whisper")
|
||||
{
|
||||
SeLogger.Error("UseWhisperCpp changed to 'False' as 'Whisper/whisper' or '/Whisper/main' was not found!");
|
||||
Configuration.Settings.Tools.UseWhisperCpp = false;
|
||||
Configuration.Settings.Tools.WhisperUseCpp = false;
|
||||
}
|
||||
|
||||
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.UseWhisperCpp = false;
|
||||
Configuration.Settings.Tools.WhisperUseCpp = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user