Add whisper update check

This commit is contained in:
niksedk 2023-08-16 08:55:29 +02:00
parent 1a874cb77d
commit ec8f8584c8
4 changed files with 193 additions and 37 deletions

View File

@ -442,6 +442,8 @@ namespace Nikse.SubtitleEdit.Core.Common
public bool VoskPostProcessing { get; set; }
public string VoskModel { get; set; }
public string WhisperChoice { get; set; }
public bool WhisperIgnoreVersion { get; set; }
public bool WhisperDeleteTempFiles { get; set; }
public string WhisperModel { get; set; }
public string WhisperLanguageCode { get; set; }
@ -6782,6 +6784,12 @@ $HorzAlign = Center
settings.Tools.WhisperChoice = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperIgnoreVersion");
if (subNode != null)
{
settings.Tools.WhisperIgnoreVersion = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("WhisperDeleteTempFiles");
if (subNode != null)
{
@ -11507,6 +11515,7 @@ $HorzAlign = Center
textWriter.WriteElementString("VoskPostProcessing", settings.Tools.VoskPostProcessing.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("VoskModel", settings.Tools.VoskModel);
textWriter.WriteElementString("WhisperChoice", settings.Tools.WhisperChoice);
textWriter.WriteElementString("WhisperIgnoreVersion", settings.Tools.WhisperIgnoreVersion.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WhisperDeleteTempFiles", settings.Tools.WhisperDeleteTempFiles.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WhisperModel", settings.Tools.WhisperModel);
textWriter.WriteElementString("WhisperLocation", settings.Tools.WhisperLocation);

View File

@ -61,12 +61,13 @@
this.toolStripSeparatorRunOnlyPostprocessing = new System.Windows.Forms.ToolStripSeparator();
this.setCPPConstmeModelsFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.removeTemporaryFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.checkBoxAutoAdjustTimings = new System.Windows.Forms.CheckBox();
this.comboBoxWhisperEngine = new Nikse.SubtitleEdit.Controls.NikseComboBox();
this.labelEngine = new System.Windows.Forms.Label();
this.buttonAdvanced = new System.Windows.Forms.Button();
this.labelAdvanced = new System.Windows.Forms.Label();
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showWhisperlogtxtToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxModels.SuspendLayout();
this.groupBoxInputFiles.SuspendLayout();
this.contextMenuStripWhisperAdvanced.SuspendLayout();
@ -400,9 +401,10 @@
this.toolStripSeparatorRunOnlyPostprocessing,
this.setCPPConstmeModelsFolderToolStripMenuItem,
this.removeTemporaryFilesToolStripMenuItem,
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem});
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem,
this.showWhisperlogtxtToolStripMenuItem});
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(320, 120);
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(320, 142);
this.contextMenuStripWhisperAdvanced.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStripWhisperAdvanced_Opening);
//
// runOnlyPostProcessingToolStripMenuItem
@ -431,6 +433,13 @@
this.removeTemporaryFilesToolStripMenuItem.Text = "Remove temporary files";
this.removeTemporaryFilesToolStripMenuItem.Click += new System.EventHandler(this.removeTemporaryFilesToolStripMenuItem_Click);
//
// downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem
//
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Name = "downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem";
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Size = new System.Drawing.Size(319, 22);
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Text = "Download CUDA for Perfview\'s Whisper-Faster";
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Click += new System.EventHandler(this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem_Click);
//
// checkBoxAutoAdjustTimings
//
this.checkBoxAutoAdjustTimings.AutoSize = true;
@ -496,12 +505,12 @@
this.labelAdvanced.TabIndex = 29;
this.labelAdvanced.Text = "Advanced...";
//
// downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem
// showWhisperlogtxtToolStripMenuItem
//
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Name = "downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem";
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Size = new System.Drawing.Size(319, 22);
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Text = "Download CUDA for Perfview\'s Whisper-Faster";
this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Click += new System.EventHandler(this.downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem_Click);
this.showWhisperlogtxtToolStripMenuItem.Name = "showWhisperlogtxtToolStripMenuItem";
this.showWhisperlogtxtToolStripMenuItem.Size = new System.Drawing.Size(319, 22);
this.showWhisperlogtxtToolStripMenuItem.Text = "Show whisper_log.txt";
this.showWhisperlogtxtToolStripMenuItem.Click += new System.EventHandler(this.ShowWhisperLogFileToolStripMenuItem_Click);
//
// WhisperAudioToText
//
@ -589,5 +598,6 @@
private System.Windows.Forms.Button buttonAdvanced;
private System.Windows.Forms.Label labelAdvanced;
private System.Windows.Forms.ToolStripMenuItem downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem showWhisperlogtxtToolStripMenuItem;
}
}

View File

@ -48,7 +48,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
public bool IncompleteModel { get; set; }
public string IncompleteModelName { get; set; }
private static bool? _cudaSomeDevice { get; set; }
private static bool? CudaSomeDevice { get; set; }
public Subtitle TranscribedSubtitle { get; private set; }
@ -132,9 +132,11 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
public static void InitializeWhisperEngines(NikseComboBox cb)
{
cb.Items.Clear();
var engines = new List<string>();
engines.Add(WhisperChoice.OpenAi);
engines.Add(WhisperChoice.Cpp);
var engines = new List<string>
{
WhisperChoice.OpenAi,
WhisperChoice.Cpp
};
if (Configuration.IsRunningOnWindows)
{
engines.Add(WhisperChoice.ConstMe);
@ -257,6 +259,19 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
return;
}
try
{
var f = SeLogger.GetWhisperLogFilePath();
if (File.Exists(f) && new FileInfo(f).Length > 100_000)
{
File.Delete(f);
}
}
catch
{
// ignore
}
_useCenterChannelOnly = Configuration.Settings.General.FFmpegUseCenterChannelOnly &&
FfmpegMediaInfo.Parse(_videoFileName).HasFrontCenterAudio(_audioTrackNumber);
@ -285,6 +300,11 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
comboBoxLanguages.Enabled = false;
comboBoxModels.Enabled = false;
var waveFileName = GenerateWavFile(_videoFileName, _audioTrackNumber);
if (_cancel)
{
return;
}
progressBar1.Style = ProgressBarStyle.Blocks;
timer1.Start();
var transcript = TranscribeViaWhisper(waveFileName);
@ -603,6 +623,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
System.Threading.Thread.Sleep(50);
}
process.Dispose();
if (GetResultFromSrt(waveFileName, out var resultTexts, _outputText, _filesToDelete))
{
var subtitle = new Subtitle();
@ -1253,27 +1275,115 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
buttonGenerate.Focus();
_initialWidth = Width;
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe)
{
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.Cpp;
whisperConstMeToolStripMenuItem_Click(null, null);
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp)
{
Init();
}
}
CheckIfInstalledAndVersion(Configuration.Settings.Tools.WhisperChoice);
}
try
private void CheckIfInstalledAndVersion(string whisperChoice)
{
if (whisperChoice == WhisperChoice.Cpp)
{
var f = SeLogger.GetWhisperLogFilePath();
if (File.Exists(f) && new FileInfo(f).Length > 50_000)
var targetFile = WhisperHelper.GetWhisperPathAndFileName(whisperChoice);
if (File.Exists(targetFile))
{
File.Delete(f);
if (!Configuration.Settings.Tools.WhisperIgnoreVersion &&
!WhisperDownload.IsLatestVersion(targetFile, whisperChoice))
{
if (MessageBox.Show(string.Format(LanguageSettings.Current.Settings.DownloadX, "Whisper CPP (Update)"), "Subtitle Edit", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
using (var downloadForm = new WhisperDownload(whisperChoice))
{
if (downloadForm.ShowDialog(this) != DialogResult.OK)
{
Configuration.Settings.Tools.WhisperIgnoreVersion = true;
return;
}
}
}
}
}
else
{
if (MessageBox.Show(string.Format(LanguageSettings.Current.Settings.DownloadX, "Whisper CPP"), "Subtitle Edit", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
using (var downloadForm = new WhisperDownload(whisperChoice))
{
if (downloadForm.ShowDialog(this) != DialogResult.OK)
{
return;
}
}
}
}
}
catch
else if (whisperChoice == WhisperChoice.PurfviewFasterWhisper)
{
// ignore
var targetFile = WhisperHelper.GetWhisperPathAndFileName(whisperChoice);
if (File.Exists(targetFile))
{
if (!Configuration.Settings.Tools.WhisperIgnoreVersion &&
!WhisperDownload.IsLatestVersion(targetFile, whisperChoice))
{
if (MessageBox.Show(string.Format(LanguageSettings.Current.Settings.DownloadX, "Whisper CPP (Update)"), "Subtitle Edit", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
using (var downloadForm = new WhisperDownload(whisperChoice))
{
if (downloadForm.ShowDialog(this) != DialogResult.OK)
{
Configuration.Settings.Tools.WhisperIgnoreVersion = true;
return;
}
}
}
}
}
else
{
if (MessageBox.Show(string.Format(LanguageSettings.Current.Settings.DownloadX, "Whisper CPP"), "Subtitle Edit", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
using (var downloadForm = new WhisperDownload(whisperChoice))
{
if (downloadForm.ShowDialog(this) != DialogResult.OK)
{
return;
}
}
}
}
}
else if (whisperChoice == WhisperChoice.ConstMe)
{
var targetFile = WhisperHelper.GetWhisperPathAndFileName(whisperChoice);
if (File.Exists(targetFile))
{
if (!Configuration.Settings.Tools.WhisperIgnoreVersion &&
!WhisperDownload.IsLatestVersion(targetFile, whisperChoice))
{
if (MessageBox.Show(string.Format(LanguageSettings.Current.Settings.DownloadX, "Whisper Const-me (Update)"), "Subtitle Edit", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
using (var downloadForm = new WhisperDownload(whisperChoice))
{
if (downloadForm.ShowDialog(this) != DialogResult.OK)
{
Configuration.Settings.Tools.WhisperIgnoreVersion = true;
return;
}
}
}
}
}
else
{
if (MessageBox.Show(string.Format(LanguageSettings.Current.Settings.DownloadX, "Whisper Const-me"), "Subtitle Edit", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
using (var downloadForm = new WhisperDownload(whisperChoice))
{
if (downloadForm.ShowDialog(this) != DialogResult.OK)
{
return;
}
}
}
}
}
}
@ -1633,6 +1743,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
}
downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Visible = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.PurfviewFasterWhisper;
showWhisperlogtxtToolStripMenuItem.Visible = File.Exists(SeLogger.GetWhisperLogFilePath());
}
private void runOnlyPostProcessingToolStripMenuItem_Click(object sender, EventArgs e)
@ -1746,7 +1858,9 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
System.Threading.Thread.Sleep(2);
}
return _cudaSomeDevice == true;
process.Dispose();
return CudaSomeDevice == true;
}
private static void OutputHandlerCheckCuda(object sendingProcess, DataReceivedEventArgs outLine)
@ -1758,10 +1872,10 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
if (!outLine.Data.Contains("CUDA device: 0") && outLine.Data.Contains("CUDA device:"))
{
_cudaSomeDevice = true;
CudaSomeDevice = true;
}
}
public static bool IsFasterWhisperCudaInstalled()
{
var folder = Path.Combine(Configuration.DataDirectory, "Whisper", "Purfview-Whisper-Faster");
@ -1774,5 +1888,10 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
var alreadyInstalled = cudaFiles.Length > 2;
return alreadyInstalled;
}
private void ShowWhisperLogFileToolStripMenuItem_Click(object sender, EventArgs e)
{
UiUtil.OpenFile(SeLogger.GetWhisperLogFilePath());
}
}
}

View File

@ -18,13 +18,13 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private readonly CancellationTokenSource _cancellationTokenSource;
private readonly string _whisperChoice;
private static readonly string[] Sha512Hashes =
private static readonly string[] Sha512HashesCpp =
{
"fc1878c3b7200d0531c376bbe52319a55575e3ceeeacecbee54a366116c30eb1aa3d0a34c742f9fd5a47ffb9f24cba75653d1498e95e4f6f86c00f6d5e593d2a", // 64-bit OpenBLAS
"44cb0f326ece26c1b41bd0b20663bc946990a7c3b56150966eebefb783496089289b6002ce93d08f1862bf6600e9912ac62057c268698672397192c55eeb30a2", // 32-bit OpenBLAS
"fc1878c3b7200d0531c376bbe52319a55575e3ceeeacecbee54a366116c30eb1aa3d0a34c742f9fd5a47ffb9f24cba75653d1498e95e4f6f86c00f6d5e593d2a", // v1.4.0/whisper-blas-bin-x64.zip
"44cb0f326ece26c1b41bd0b20663bc946990a7c3b56150966eebefb783496089289b6002ce93d08f1862bf6600e9912ac62057c268698672397192c55eeb30a2", // v1.4.0/whisper-blas-bin-Win32.zip
};
private static readonly string[] OldSha512Hashes =
private static readonly string[] OldSha512HashesCpp =
{
"e193e845380676b59deade82d3f1de70ac54da3b5ffa70b4eabb3a2a96ad312d8f197403604805cef182c85c3a3370dd74a2b0b7bccf2d95b1022c10ce8c7b79", // 64-bit OpenBLAS
"4218423f79d856096cdc8d88aad2e361740940e706e0b1d07dc3455571022419ad14cfef717f63e8fc61a7a1ef67b6722cec8b3c4c25ad7f087a23b1b89c5d91", // 32-bit OpenBLAS
@ -175,7 +175,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
}
else
{
hashes = Sha512Hashes;
hashes = Sha512HashesCpp;
}
if (!hashes.Contains(hash))
@ -292,12 +292,30 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
{
return OldSha512HashesConstMe.Contains(hash);
}
else if (whisperChoice == WhisperChoice.PurfviewFasterWhisper)
if (whisperChoice == WhisperChoice.PurfviewFasterWhisper)
{
return OldSha512HashesPurfviewFasterWhisper.Contains(hash);
}
return OldSha512Hashes.Contains(hash);
return OldSha512HashesCpp.Contains(hash);
}
public static bool IsLatestVersion(string fullPath, string whisperChoice)
{
var hash = Utilities.GetSha512Hash(FileUtil.ReadAllBytesShared(fullPath));
if (whisperChoice == WhisperChoice.ConstMe)
{
return hash == "8c354fcc12daee1d1aa755487aa8c53aea521a922f8ec2637c694b06d068ac60637f67bc74c8bc71a8ffee8db7988398de498d752ae4501b786a7ad9f6cd629f";
}
if (whisperChoice == WhisperChoice.PurfviewFasterWhisper)
{
return hash == "ab34a7cb4ce36a0634756da9a2592d81281404c3408ca223dcd9f2bdbc131e81b8a45158d9df295b42fc2bce5485ae1542c00a76efe33775ef811fbef42e86e3";
}
return hash == "c43fed38d1ae99e6fbbd8c842c2d550b4949081c0c7fba72cd2e2e8435ff05eac4f64e659efb09d597c3c062edf1e5026acc375d2a07290fa3c0fca9ac3bd7a2";
}
}
}