More work on whisper/Const-me

This commit is contained in:
niksedk 2023-02-08 20:14:21 +01:00
parent 8871c7e9f3
commit befb5f03ad
13 changed files with 70 additions and 106 deletions

View File

@ -207,14 +207,6 @@ 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 "cpuid.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\"

View File

@ -181,14 +181,6 @@ 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 "cpuid.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\"

View File

@ -326,14 +326,6 @@ 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}\cpuid.dll; DestDir: {app}; Flags: ignoreversion; Components: main
Source: {#bindir}\iTin.Core.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
@ -376,14 +368,6 @@ 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}\cpuid.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()

View File

@ -108,7 +108,7 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe)
{
var path = Path.Combine(Configuration.DataDirectory, "Whisper", "ConstMe");
var path = Path.Combine(Configuration.DataDirectory, "Whisper", "Const-me");
return Directory.Exists(path) ? path : null;
}

View File

@ -387,7 +387,7 @@
this.toolStripSeparator1,
this.removeTemporaryFilesToolStripMenuItem});
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(210, 98);
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(210, 120);
//
// whisperPhpOriginalToolStripMenuItem
//
@ -407,7 +407,7 @@
//
this.whisperConstMeToolStripMenuItem.Name = "whisperConstMeToolStripMenuItem";
this.whisperConstMeToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.whisperConstMeToolStripMenuItem.Text = "Whisper ConstMe (GPU)";
this.whisperConstMeToolStripMenuItem.Text = "Whisper Const-me (GPU)";
this.whisperConstMeToolStripMenuItem.Click += new System.EventHandler(this.whisperConstMeToolStripMenuItem_Click);
//
// toolStripSeparator1

View File

@ -559,6 +559,10 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
public static bool GetResultFromSrt(string waveFileName, out List<ResultText> resultTexts, ConcurrentBag<string> outputText, List<string> filesToDelete)
{
var srtFileName = waveFileName + ".srt";
if (!File.Exists(srtFileName) && waveFileName.EndsWith(".wav"))
{
srtFileName = waveFileName.Remove(waveFileName.Length - 4) + ".srt";
}
var whisperFolder = WhisperHelper.GetWhisperFolder() ?? string.Empty;
var vttFileName = Path.Combine(whisperFolder, Path.GetFileName(waveFileName) + ".vtt");

View File

@ -54,6 +54,7 @@
this.contextMenuStripWhisperAdvanced = new System.Windows.Forms.ContextMenuStrip(this.components);
this.whisperPhpOriginalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.whisperCppCToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.whisperConstMeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.removeTemporaryFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxModels.SuspendLayout();
@ -301,10 +302,11 @@
this.contextMenuStripWhisperAdvanced.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.whisperPhpOriginalToolStripMenuItem,
this.whisperCppCToolStripMenuItem,
this.whisperConstMeToolStripMenuItem,
this.toolStripSeparator1,
this.removeTemporaryFilesToolStripMenuItem});
this.contextMenuStripWhisperAdvanced.Name = "contextMenuStripWhisperAdvanced";
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(210, 76);
this.contextMenuStripWhisperAdvanced.Size = new System.Drawing.Size(210, 120);
//
// whisperPhpOriginalToolStripMenuItem
//
@ -320,6 +322,13 @@
this.whisperCppCToolStripMenuItem.Text = "Whisper cpp (C++)";
this.whisperCppCToolStripMenuItem.Click += new System.EventHandler(this.whisperCppCToolStripMenuItem_Click);
//
// whisperConstMeToolStripMenuItem
//
this.whisperConstMeToolStripMenuItem.Name = "whisperConstMeToolStripMenuItem";
this.whisperConstMeToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.whisperConstMeToolStripMenuItem.Text = "Whisper Const-me (GPU)";
this.whisperConstMeToolStripMenuItem.Click += new System.EventHandler(this.whisperConstMeGPUToolStripMenuItem_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
@ -400,5 +409,6 @@
private System.Windows.Forms.ToolStripMenuItem whisperCppCToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem removeTemporaryFilesToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem whisperConstMeToolStripMenuItem;
}
}

View File

@ -81,6 +81,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
whisperCppCToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp;
whisperPhpOriginalToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.OpenAI;
removeTemporaryFilesToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperDeleteTempFiles;
whisperConstMeToolStripMenuItem.Checked = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe;
whisperConstMeToolStripMenuItem.Visible = Configuration.IsRunningOnWindows;
ContextMenuStrip = contextMenuStripWhisperAdvanced;
}
@ -474,5 +476,37 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
{
contextMenuStripWhisperAdvanced.Show(MousePosition);
}
private void whisperConstMeGPUToolStripMenuItem_Click(object sender, EventArgs e)
{
var oldChoice = Configuration.Settings.Tools.WhisperChoice;
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.ConstMe;
var fileName = WhisperHelper.GetWhisperPathAndFileName();
if (!File.Exists(fileName) ||
WhisperDownload.IsOld(fileName, WhisperChoice.ConstMe))
{
Configuration.Settings.Tools.WhisperChoice = oldChoice;
if (MessageBox.Show(string.Format(LanguageSettings.Current.Settings.DownloadX, "whisper ConstMe (GPU)"), "Subtitle Edit", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
using (var downloadForm = new WhisperDownload(WhisperChoice.ConstMe))
{
if (downloadForm.ShowDialog(this) == DialogResult.OK)
{
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.ConstMe;
}
else
{
return;
}
}
}
else
{
return;
}
}
Init();
}
}
}

View File

@ -30,7 +30,7 @@
{
this.labelDescription1 = new System.Windows.Forms.Label();
this.labelPleaseWait = new System.Windows.Forms.Label();
this.labelAVX2 = new System.Windows.Forms.Label();
this.labelWhisperChoice = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// labelDescription1
@ -53,21 +53,21 @@
//
// 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";
this.labelWhisperChoice.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelWhisperChoice.AutoSize = true;
this.labelWhisperChoice.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
this.labelWhisperChoice.Location = new System.Drawing.Point(274, 9);
this.labelWhisperChoice.Name = "labelWhisperChoice";
this.labelWhisperChoice.Size = new System.Drawing.Size(34, 13);
this.labelWhisperChoice.TabIndex = 30;
this.labelWhisperChoice.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.labelWhisperChoice);
this.Controls.Add(this.labelDescription1);
this.Controls.Add(this.labelPleaseWait);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
@ -87,6 +87,6 @@
private System.Windows.Forms.Label labelDescription1;
private System.Windows.Forms.Label labelPleaseWait;
private System.Windows.Forms.Label labelAVX2;
private System.Windows.Forms.Label labelWhisperChoice;
}
}

View File

@ -11,10 +11,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
{
public sealed partial class WhisperDownload : Form
{
private const string DownloadUrlAvx2 = "https://github.com/ggerganov/whisper.cpp/releases/download/v1.2.0/whisper-blas-bin-x64.zip";
private const string DownloadUrlSse2 = "https://github.com/ggerganov/whisper.cpp/releases/download/v1.2.0/whisper-blas-bin-x64.zip";
private const string DownloadUrl32BitAvx2 = "https://github.com/ggerganov/whisper.cpp/releases/download/v1.2.0/whisper-blas-bin-Win32.zip";
private const string DownloadUrl32BitSse2 = "https://github.com/ggerganov/whisper.cpp/releases/download/v1.2.0/whisper-blas-bin-Win32.zip";
private const string DownloadUrl64Cpp = "https://github.com/ggerganov/whisper.cpp/releases/download/v1.2.0/whisper-blas-bin-x64.zip";
private const string DownloadUrl32Cpp = "https://github.com/ggerganov/whisper.cpp/releases/download/v1.2.0/whisper-blas-bin-Win32.zip";
private readonly CancellationTokenSource _cancellationTokenSource;
private readonly string _whisperChoice;
@ -66,15 +64,11 @@ 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;
if (IntPtr.Size * 8 == 32)
{
downloadUrl = avx2 ? DownloadUrl32BitAvx2 : DownloadUrl32BitSse2;
}
labelWhisperChoice.Visible = true;
labelWhisperChoice.Text = _whisperChoice;
labelWhisperChoice.Left = Width - labelWhisperChoice.Width - 20;
var downloadUrl = IntPtr.Size * 8 == 32 ? DownloadUrl32Cpp : DownloadUrl64Cpp;
if (_whisperChoice == WhisperChoice.ConstMe)
{
downloadUrl = DownloadUrlConstMe;
@ -141,7 +135,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
if (_whisperChoice == WhisperChoice.ConstMe)
{
folder = Path.Combine(folder, "ConstMe");
folder = Path.Combine(folder, "Const-me");
if (!Directory.Exists(folder))
{

View File

@ -1,21 +0,0 @@
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;
}
}
}
}

View File

@ -61,27 +61,6 @@
<HintPath>DLLs\Interop.QuartzTypeLib.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="iTin.Core, Version=2.0.0.4, Culture=neutral, PublicKeyToken=91c459d24f0559c7, processorArchitecture=MSIL">
<HintPath>..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.dll</HintPath>
</Reference>
<Reference Include="iTin.Core.Hardware.Common, Version=1.0.0.4, Culture=neutral, PublicKeyToken=55a914aaf3e07893, processorArchitecture=MSIL">
<HintPath>..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.Hardware.Common.dll</HintPath>
</Reference>
<Reference Include="iTin.Core.Hardware.CrossPlatform.Cpuid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=55a914aaf3e07893, processorArchitecture=MSIL">
<HintPath>..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.Hardware.CrossPlatform.Cpuid.dll</HintPath>
</Reference>
<Reference Include="iTin.Core.Interop.CrossPlatform.Cpuid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1863a70dcfb63184, processorArchitecture=MSIL">
<HintPath>..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.Interop.CrossPlatform.Cpuid.dll</HintPath>
</Reference>
<Reference Include="iTin.Core.Interop.Shared, Version=1.0.0.3, Culture=neutral, PublicKeyToken=1863a70dcfb63184, processorArchitecture=MSIL">
<HintPath>..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Core.Interop.Shared.dll</HintPath>
</Reference>
<Reference Include="iTin.Hardware.Specification.Cpuid, Version=1.0.0.2, Culture=neutral, PublicKeyToken=4854c22d6845e07c, processorArchitecture=MSIL">
<HintPath>..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Hardware.Specification.Cpuid.dll</HintPath>
</Reference>
<Reference Include="iTin.Logging, Version=1.0.0.1, Culture=neutral, PublicKeyToken=1f353418c19ff38d, processorArchitecture=MSIL">
<HintPath>..\..\packages\iCPUID.1.0.5\lib\net461\iTin.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
</Reference>
@ -1401,7 +1380,6 @@
<Compile Include="Logic\CommandLineConvert\TsConvert.cs" />
<Compile Include="Logic\CommandLineConvert\TsToBluRaySup.cs" />
<Compile Include="Logic\CpsLineLength.cs" />
<Compile Include="Logic\CpuInfo.cs" />
<Compile Include="Logic\CurrentLanguage.cs" />
<Compile Include="Logic\DarkTheme.cs" />
<Compile Include="Logic\FileTypeAssociations.cs" />
@ -2452,8 +2430,6 @@
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
<Error Condition="!Exists('..\..\packages\Vosk.0.3.38\build\Vosk.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Vosk.0.3.38\build\Vosk.targets'))" />
<Error Condition="!Exists('..\..\packages\iCPUID.1.0.5\build\net461\iCPUID.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\iCPUID.1.0.5\build\net461\iCPUID.targets'))" />
</Target>
<Import Project="..\..\packages\Vosk.0.3.38\build\Vosk.targets" Condition="Exists('..\..\packages\Vosk.0.3.38\build\Vosk.targets')" />
<Import Project="..\..\packages\iCPUID.1.0.5\build\net461\iCPUID.targets" Condition="Exists('..\..\packages\iCPUID.1.0.5\build\net461\iCPUID.targets')" />
</Project>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="iCPUID" version="1.0.5" targetFramework="net48" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net462" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net462" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net462" />