diff --git a/Changelog.txt b/Changelog.txt index 382742d33..dedfa36d5 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -20,6 +20,7 @@ * Add more settings for "Delete auto-backup after" - thx pahtashow * Add more options for actor in custom text export - thx Francois * Improve video auto load (allow eg. "_nl") - thx Hilde + * Improve fix italic tags - thx uckthis * FIXED: * Fix VLC video player not working * Fix for ASSA timestamps (rounding output) - thx Jerome diff --git a/build.bat b/build.bat index 3adcb3e7d..757d9624c 100644 --- a/build.bat +++ b/build.bat @@ -207,6 +207,13 @@ COPY /Y /V "Newtonsoft.Json.dll" "temp_zip\" COPY /Y /V "System.Net.Http.Primitives.dll" "temp_zip\" COPY /Y /V "NAudio.Core.dll" "temp_zip\" COPY /Y /V "NAudio.WinMM.dll" "temp_zip\" +COPY /Y /V "iTin.Core.dll" "temp_zip\" +COPY /Y /V "iTin.Core.Hardware.Common.dll" "temp_zip\" +COPY /Y /V "iTin.Core.Hardware.CrossPlatform.Cpuid.dll" "temp_zip\" +COPY /Y /V "iTin.Core.Interop.CrossPlatform.Cpuid.dll" "temp_zip\" +COPY /Y /V "iTin.Core.Interop.Shared.dll" "temp_zip\" +COPY /Y /V "iTin.Hardware.Specification.Cpuid.dll" "temp_zip\" +COPY /Y /V "iTin.Logging.dll" "temp_zip\" COPY /Y /V "Microsoft.Win32.Registry.dll" "temp_zip\" COPY /Y /V "SubtitleEdit.exe" "temp_zip\" COPY /Y /V "Languages\*.xml" "temp_zip\Languages\" diff --git a/build_beta.bat b/build_beta.bat index afe7fdd7d..9871ffc92 100644 --- a/build_beta.bat +++ b/build_beta.bat @@ -181,6 +181,13 @@ COPY /Y /V "Newtonsoft.Json.dll" "temp_zip\" COPY /Y /V "System.Net.Http.Primitives.dll" "temp_zip\" COPY /Y /V "NAudio.Core.dll" "temp_zip\" COPY /Y /V "NAudio.WinMM.dll" "temp_zip\" +COPY /Y /V "iTin.Core.dll" "temp_zip\" +COPY /Y /V "iTin.Core.Hardware.Common.dll" "temp_zip\" +COPY /Y /V "iTin.Core.Hardware.CrossPlatform.Cpuid.dll" "temp_zip\" +COPY /Y /V "iTin.Core.Interop.CrossPlatform.Cpuid.dll" "temp_zip\" +COPY /Y /V "iTin.Core.Interop.Shared.dll" "temp_zip\" +COPY /Y /V "iTin.Hardware.Specification.Cpuid.dll" "temp_zip\" +COPY /Y /V "iTin.Logging.dll" "temp_zip\" COPY /Y /V "Microsoft.Win32.Registry.dll" "temp_zip\" COPY /Y /V "SubtitleEdit.exe" "temp_zip\" COPY /Y /V "Languages\*.xml" "temp_zip\Languages\" diff --git a/installer/Subtitle_Edit_installer.iss b/installer/Subtitle_Edit_installer.iss index a6a570164..a107f30f9 100644 --- a/installer/Subtitle_Edit_installer.iss +++ b/installer/Subtitle_Edit_installer.iss @@ -314,6 +314,12 @@ Source: {#bindir}\System.Net.Http.Extensions.dll; DestDir: {app}; Source: {#bindir}\System.Net.Http.Primitives.dll; DestDir: {app}; Flags: ignoreversion; Components: main Source: {#bindir}\NAudio.Core.dll; DestDir: {app}; Flags: ignoreversion; Components: main Source: {#bindir}\NAudio.WinMM.dll; DestDir: {app}; Flags: ignoreversion; Components: main +Source: {#bindir}\iTin.Core.Hardware.Common.dll; DestDir: {app}; Flags: ignoreversion; Components: main +Source: {#bindir}\iTin.Core.Hardware.CrossPlatform.Cpuid.dll; DestDir: {app}; Flags: ignoreversion; Components: main +Source: {#bindir}\iTin.Core.Interop.CrossPlatform.Cpuid.dll; DestDir: {app}; Flags: ignoreversion; Components: main +Source: {#bindir}\iTin.Core.Interop.Shared.dll; DestDir: {app}; Flags: ignoreversion; Components: main +Source: {#bindir}\iTin.Hardware.Specification.Cpuid.dll; DestDir: {app}; Flags: ignoreversion; Components: main +Source: {#bindir}\iTin.Logging.dll; DestDir: {app}; Flags: ignoreversion; Components: main Source: {#bindir}\Microsoft.Win32.Registry.dll; DestDir: {app}; Flags: ignoreversion; Components: main Source: ..\Changelog.txt; DestDir: {app}; Flags: ignoreversion; Components: main Source: ..\LICENSE.txt; DestDir: {app}; Flags: ignoreversion; Components: main @@ -356,6 +362,13 @@ Type: files; Name: {app}\System.Net.Http.Extensions.dll; Check: IsU Type: files; Name: {app}\System.Net.Http.Primitives.dll; Check: IsUpgrade() Type: files; Name: {app}\NAudio.Core.dll; Check: IsUpgrade() Type: files; Name: {app}\NAudio.WinMM.dll; Check: IsUpgrade() +Type: files; Name: {app}\iTin.Core.dll; Check: IsUpgrade() +Type: files; Name: {app}\iTin.Core.Hardware.Common.dll; Check: IsUpgrade() +Type: files; Name: {app}\iTin.Core.Hardware.CrossPlatform.Cpuid.dll; Check: IsUpgrade() +Type: files; Name: {app}\iTin.Core.Interop.CrossPlatform.Cpuid.dll; Check: IsUpgrade() +Type: files; Name: {app}\iTin.Core.Interop.Shared.dll; Check: IsUpgrade() +Type: files; Name: {app}\iTin.Hardware.Specification.Cpuid.dll; Check: IsUpgrade() +Type: files; Name: {app}\iTin.Logging.dll; Check: IsUpgrade() Type: files; Name: {app}\Microsoft.Win32.Registry.dll; Check: IsUpgrade() diff --git a/src/ui/Forms/AudioToText/WhisperAudioToText.cs b/src/ui/Forms/AudioToText/WhisperAudioToText.cs index 4ad9eae9e..bcc41640b 100644 --- a/src/ui/Forms/AudioToText/WhisperAudioToText.cs +++ b/src/ui/Forms/AudioToText/WhisperAudioToText.cs @@ -442,6 +442,24 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText } resultTexts = results; + + try + { + if (!File.Exists(srtFileName)) + { + File.Delete(srtFileName); + } + + if (!File.Exists(vttFileName)) + { + File.Delete(vttFileName); + } + } + catch + { + // ignore + } + return true; } diff --git a/src/ui/Forms/AudioToText/WhisperDownload.Designer.cs b/src/ui/Forms/AudioToText/WhisperDownload.Designer.cs index 58b84352d..a9ef9124b 100644 --- a/src/ui/Forms/AudioToText/WhisperDownload.Designer.cs +++ b/src/ui/Forms/AudioToText/WhisperDownload.Designer.cs @@ -30,6 +30,7 @@ { this.labelDescription1 = new System.Windows.Forms.Label(); this.labelPleaseWait = new System.Windows.Forms.Label(); + this.labelAVX2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // labelDescription1 @@ -37,9 +38,9 @@ this.labelDescription1.AutoSize = true; this.labelDescription1.Location = new System.Drawing.Point(21, 27); this.labelDescription1.Name = "labelDescription1"; - this.labelDescription1.Size = new System.Drawing.Size(145, 13); + this.labelDescription1.Size = new System.Drawing.Size(132, 13); this.labelDescription1.TabIndex = 29; - this.labelDescription1.Text = "Downloading Tesseract OCR"; + this.labelDescription1.Text = "Downloading Whisper.cpp"; // // labelPleaseWait // @@ -50,17 +51,29 @@ this.labelPleaseWait.TabIndex = 28; this.labelPleaseWait.Text = "Please wait..."; // - // DownloadTesseract5 + // labelAVX2 + // + this.labelAVX2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.labelAVX2.AutoSize = true; + this.labelAVX2.ForeColor = System.Drawing.SystemColors.ControlDarkDark; + this.labelAVX2.Location = new System.Drawing.Point(274, 9); + this.labelAVX2.Name = "labelAVX2"; + this.labelAVX2.Size = new System.Drawing.Size(34, 13); + this.labelAVX2.TabIndex = 30; + this.labelAVX2.Text = "AVX2"; + // + // WhisperDownload // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(320, 93); + this.Controls.Add(this.labelAVX2); this.Controls.Add(this.labelDescription1); this.Controls.Add(this.labelPleaseWait); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; - this.Name = "DownloadTesseract5"; + this.Name = "WhisperDownload"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Download Tesseract"; @@ -74,5 +87,6 @@ private System.Windows.Forms.Label labelDescription1; private System.Windows.Forms.Label labelPleaseWait; + private System.Windows.Forms.Label labelAVX2; } } \ No newline at end of file diff --git a/src/ui/Forms/AudioToText/WhisperDownload.cs b/src/ui/Forms/AudioToText/WhisperDownload.cs index 907698b9d..f149eec1a 100644 --- a/src/ui/Forms/AudioToText/WhisperDownload.cs +++ b/src/ui/Forms/AudioToText/WhisperDownload.cs @@ -2,6 +2,7 @@ using Nikse.SubtitleEdit.Logic; using System; using System.IO; +using System.Linq; using System.Threading; using System.Windows.Forms; @@ -9,8 +10,14 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText { public sealed partial class WhisperDownload : Form { - public const string DownloadUrl = "https://github.com/SubtitleEdit/support-files/raw/master/whisper/whisper.cpp-2022-11-14.zip"; + private const string DownloadUrlAvx2 = "https://github.com/SubtitleEdit/support-files/raw/master/whisper/whisper.cpp-AVX2-2022-11-16.zip"; + private const string DownloadUrlSse2 = "https://github.com/SubtitleEdit/support-files/raw/master/whisper/whisper.cpp-SSE2-2022-11-16.zip"; private readonly CancellationTokenSource _cancellationTokenSource; + private static readonly string[] Sha512Hashes = + { + "ebbcb81782f5be763203d4e9b7a55b23d04997b0d0689c1af9638b0b5701db763569cb29d39593db84245e499876f930f64f4e758914fbfe39ad87a61cda8581", // AVX2 + "83d216fa1c1874be141c41b5bbdb61df9c447b5182787d8ae3d73c3cb6cf21743b0c7bfa6c45076938ed9629134882898623ab4932c8fde2fdee4fd5718e4bf3", // SSE2 + }; public WhisperDownload() { @@ -25,12 +32,15 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText private void WhisperDownload_Shown(object sender, EventArgs e) { + var avx2 = CpuInfo.HasAvx2(); + labelAVX2.Visible = avx2; + var downloadUrl = avx2 ? DownloadUrlAvx2 : DownloadUrlSse2; try { var httpClient = HttpClientHelper.MakeHttpClient(); using (var downloadStream = new MemoryStream()) { - var downloadTask = httpClient.DownloadAsync(DownloadUrl, downloadStream, new Progress((progress) => + var downloadTask = httpClient.DownloadAsync(downloadUrl, downloadStream, new Progress((progress) => { var pct = (int)Math.Round(progress * 100.0, MidpointRounding.AwayFromZero); labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait + " " + pct + "%"; @@ -55,19 +65,27 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText { labelPleaseWait.Text = string.Empty; Cursor = Cursors.Default; - MessageBox.Show($"Unable to download {DownloadUrl}!" + Environment.NewLine + Environment.NewLine + + MessageBox.Show($"Unable to download {downloadUrl}!" + Environment.NewLine + Environment.NewLine + exception.Message + Environment.NewLine + Environment.NewLine + exception.StackTrace); DialogResult = DialogResult.Cancel; } } - private void CompleteDownload(Stream downloadStream) + private void CompleteDownload(MemoryStream downloadStream) { if (downloadStream.Length == 0) { throw new Exception("No content downloaded - missing file or no internet connection!"); } + downloadStream.Position = 0; + var hash = Utilities.GetSha512Hash(downloadStream.ToArray()); + if (!Sha512Hashes.Contains(hash)) + { + MessageBox.Show("Whisper SHA-512 hash does not match!"); + return; + } + var folder = Path.Combine(Configuration.DataDirectory, "Whisper"); if (!Directory.Exists(folder)) { diff --git a/src/ui/Logic/CpuInfo.cs b/src/ui/Logic/CpuInfo.cs new file mode 100644 index 000000000..5bc1bd1f8 --- /dev/null +++ b/src/ui/Logic/CpuInfo.cs @@ -0,0 +1,21 @@ +using iTin.Hardware.Specification.Cpuid; +using iTin.Hardware.Specification; + +namespace Nikse.SubtitleEdit.Logic +{ + public static class CpuInfo + { + public static bool HasAvx2() + { + try + { + var avx2 = CPUID.Instance.Leafs.GetProperty(LeafProperty.ExtendedFeatures.AVX2); + return avx2.Success && (bool)avx2.Result.Value; + } + catch + { + return false; + } + } + } +} diff --git a/src/ui/SubtitleEdit.csproj b/src/ui/SubtitleEdit.csproj index b2dad31e7..baee4732b 100644 --- a/src/ui/SubtitleEdit.csproj +++ b/src/ui/SubtitleEdit.csproj @@ -61,6 +61,27 @@ DLLs\Interop.QuartzTypeLib.dll False + + ..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.dll + + + ..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.Hardware.Common.dll + + + ..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.Hardware.CrossPlatform.Cpuid.dll + + + ..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.Interop.CrossPlatform.Cpuid.dll + + + ..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.Interop.Shared.dll + + + ..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Hardware.Specification.Cpuid.dll + + + ..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Logging.dll + ..\..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll @@ -1367,6 +1388,7 @@ + @@ -2407,6 +2429,8 @@ + + \ No newline at end of file diff --git a/src/ui/packages.config b/src/ui/packages.config index 599f47181..5c7a7d9ec 100644 --- a/src/ui/packages.config +++ b/src/ui/packages.config @@ -1,5 +1,6 @@  +