From 165332eb6204c033cb6d52e41a39a284c0079c29 Mon Sep 17 00:00:00 2001 From: niksedk Date: Thu, 16 Nov 2023 13:42:56 +0100 Subject: [PATCH] Update cpp models --- src/libse/AudioToText/WhisperConstMeModel.cs | 100 +++++++++++++++++++ src/libse/AudioToText/WhisperCppModel.cs | 86 ++++++++++++++-- src/libse/AudioToText/WhisperHelper.cs | 8 +- 3 files changed, 183 insertions(+), 11 deletions(-) create mode 100644 src/libse/AudioToText/WhisperConstMeModel.cs diff --git a/src/libse/AudioToText/WhisperConstMeModel.cs b/src/libse/AudioToText/WhisperConstMeModel.cs new file mode 100644 index 000000000..b69d1d802 --- /dev/null +++ b/src/libse/AudioToText/WhisperConstMeModel.cs @@ -0,0 +1,100 @@ +using Nikse.SubtitleEdit.Core.Common; +using System.IO; + +namespace Nikse.SubtitleEdit.Core.AudioToText +{ + public class WhisperConstMeModel : IWhisperModel + { + public string ModelFolder + { + get + { + if (!string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperCppModelLocation) && + Directory.Exists(Configuration.Settings.Tools.WhisperCppModelLocation)) + { + return Configuration.Settings.Tools.WhisperCppModelLocation; + } + + return Path.Combine(Configuration.DataDirectory, "Whisper", "Const-Me", "Models"); + } + } + + public void CreateModelFolder() + { + var whisperFolder = Path.Combine(Configuration.DataDirectory, "Whisper"); + if (!Directory.Exists(whisperFolder)) + { + Directory.CreateDirectory(whisperFolder); + } + + whisperFolder = Path.Combine(whisperFolder, "Const-Me"); + if (!Directory.Exists(whisperFolder)) + { + Directory.CreateDirectory(whisperFolder); + } + + if (!Directory.Exists(ModelFolder)) + { + Directory.CreateDirectory(ModelFolder); + } + } + + public WhisperModel[] Models => new[] + { + new WhisperModel + { + Name = "tiny.en", + Size = "74 MB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.en.bin" }, + }, + new WhisperModel + { + Name = "tiny", + Size = "74 MB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.bin" }, + }, + new WhisperModel + { + Name = "base.en", + Size = "141 MB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin" }, + }, + new WhisperModel + { + Name = "base", + Size = "141 MB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.bin" }, + }, + new WhisperModel + { + Name = "small.en", + Size = "465 MB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.en.bin" }, + }, + new WhisperModel + { + Name = "small", + Size = "465 MB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin" }, + }, + new WhisperModel + { + Name = "medium.en", + Size = "1.42 GB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.en.bin" }, + }, + new WhisperModel + { + Name = "medium", + Size = "1.42 GB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.bin" }, + }, + new WhisperModel + { + Name = "large", + Size = "2.88 GB", + Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large.bin" }, + }, + }; + } +} diff --git a/src/libse/AudioToText/WhisperCppModel.cs b/src/libse/AudioToText/WhisperCppModel.cs index d2acc2308..1c70dc173 100644 --- a/src/libse/AudioToText/WhisperCppModel.cs +++ b/src/libse/AudioToText/WhisperCppModel.cs @@ -39,61 +39,129 @@ namespace Nikse.SubtitleEdit.Core.AudioToText } } + private const string DownloadUrlPrefix = "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/"; + public WhisperModel[] Models => new[] { new WhisperModel { Name = "tiny.en", Size = "74 MB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.en.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-tiny.en.bin" }, }, new WhisperModel { Name = "tiny", Size = "74 MB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-tiny.bin" }, + }, + new WhisperModel + { + Name = "tiny.en-q5_1", + Size = "32 MB", + Urls = new []{ DownloadUrlPrefix + "ggml-tiny.en-q5_1.bin" }, + }, + new WhisperModel + { + Name = "tiny-q5_1", + Size = "32 MB", + Urls = new []{ DownloadUrlPrefix + "ggml-tiny-q5_1.bin" }, }, new WhisperModel { Name = "base.en", Size = "141 MB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-base.en.bin" }, }, new WhisperModel { Name = "base", Size = "141 MB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-base.bin" }, + }, + new WhisperModel + { + Name = "base.en-q5_1", + Size = "60 MB", + Urls = new []{ DownloadUrlPrefix + "ggml-base.en-q5_1.bin" }, + }, + new WhisperModel + { + Name = "base-q5_1", + Size = "60 MB", + Urls = new []{ DownloadUrlPrefix + "ggml-base-q5_1.bin" }, }, new WhisperModel { Name = "small.en", Size = "465 MB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.en.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-small.en.bin" }, }, new WhisperModel { Name = "small", Size = "465 MB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-small.bin" }, + }, + new WhisperModel + { + Name = "small-q5_1", + Size = "190 MB", + Urls = new []{ DownloadUrlPrefix + "ggml-small-q5_1.bin" }, + }, + new WhisperModel + { + Name = "small-q5_1", + Size = "190 MB", + Urls = new []{ DownloadUrlPrefix + "ggml-small-q5_1.bin" }, }, new WhisperModel { Name = "medium.en", Size = "1.42 GB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.en.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-medium.en.bin" }, }, new WhisperModel { Name = "medium", Size = "1.42 GB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-medium.bin" }, + }, + new WhisperModel + { + Name = "medium.en-q5_0", + Size = "539 MB", + Urls = new []{ DownloadUrlPrefix + "ggml-medium.en-q5_0.bin" }, + }, + new WhisperModel + { + Name = "medium-q5_0", + Size = "539 MB", + Urls = new []{ DownloadUrlPrefix + "ggml-medium-q5_0.bin" }, + }, + new WhisperModel + { + Name = "large-v1", + Size = "2.88 GB", + Urls = new []{ DownloadUrlPrefix + "ggml-large-v1.bin" }, + }, + new WhisperModel + { + Name = "large-v2", + Size = "2.88 GB", + Urls = new []{ DownloadUrlPrefix + "ggml-large-v2.bin" }, }, new WhisperModel { Name = "large", Size = "2.88 GB", - Urls = new []{ "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large.bin" }, + Urls = new []{ DownloadUrlPrefix + "ggml-large.bin" }, + }, + new WhisperModel + { + Name = "large-q5_0", + Size = "2.88 GB", + Urls = new []{ DownloadUrlPrefix + "ggml-large-q5_0.bin" }, }, }; } diff --git a/src/libse/AudioToText/WhisperHelper.cs b/src/libse/AudioToText/WhisperHelper.cs index 95d6f0a5e..0ecb611f7 100644 --- a/src/libse/AudioToText/WhisperHelper.cs +++ b/src/libse/AudioToText/WhisperHelper.cs @@ -8,12 +8,16 @@ namespace Nikse.SubtitleEdit.Core.AudioToText { public static IWhisperModel GetWhisperModel() { - if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp || - Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe) + if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp) { return new WhisperCppModel(); } + if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe) + { + return new WhisperConstMeModel(); + } + if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.CTranslate2) { return new WhisperCTranslate2Model();