Test stable-ts

This commit is contained in:
niksedk 2023-05-05 07:48:46 +02:00
parent 3e1ded5b42
commit 72464d0bbf
6 changed files with 141 additions and 4 deletions

View File

@ -1497,7 +1497,7 @@ To use an API key, go to "Options -> Settings -> Tools" to enter your Goog
<AutoContinueInOneSecond>Auto continue in one second</AutoContinueInOneSecond>
<AutoContinueInXSeconds>Auto continue in {0} seconds</AutoContinueInXSeconds>
<StillTypingAutoContinueStopped>Still typing... auto continue stopped</StillTypingAutoContinueStopped>
<InsertNewSubtitleAtVideoPosition>&amp;Insert new subtitle at video pos</InsertNewSubtitleAtVideoPosition>
<InsertNewSubtitleAtVideoPosition>Insert new subtitle at video pos</InsertNewSubtitleAtVideoPosition>
<InsertNewSubtitleAtVideoPositionNoTextBoxFocus>Insert new subtitle at video pos (no text box focus)</InsertNewSubtitleAtVideoPositionNoTextBoxFocus>
<Auto>Auto</Auto>
<PlayFromJustBeforeText>Play from just before text</PlayFromJustBeforeText>

View File

@ -7,5 +7,6 @@
public const string WhisperX = "WhisperX";
public const string ConstMe = "Const-me";
public const string CTranslate2 = "CTranslate2";
public const string StableTs = "stable-ts";
}
}

View File

@ -60,6 +60,11 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
return "https://github.com/jordimas/whisper-ctranslate2";
}
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.StableTs)
{
return "https://github.com/jianfch/stable-ts";
}
return "https://github.com/openai/whisper";
}
@ -141,6 +146,19 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
}
}
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.StableTs && !string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperStableTsLocation))
{
if (Configuration.Settings.Tools.WhisperStableTsLocation.EndsWith("stable-ts.exe", StringComparison.InvariantCultureIgnoreCase) && File.Exists(Configuration.Settings.Tools.WhisperStableTsLocation))
{
return Path.GetDirectoryName(Configuration.Settings.Tools.WhisperStableTsLocation);
}
if (Directory.Exists(Configuration.Settings.Tools.WhisperStableTsLocation) && File.Exists(Path.Combine(Configuration.Settings.Tools.WhisperStableTsLocation, "stable-ts.exe")))
{
return Configuration.Settings.Tools.WhisperStableTsLocation;
}
}
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe)
{
var path = Path.Combine(Configuration.DataDirectory, "Whisper", "Const-me");
@ -181,6 +199,17 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
return null;
}
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.StableTs)
{
var whisperCTranslate2FullPath = Path.Combine(dir, "Scripts", "stable-ts.exe");
if (File.Exists(whisperCTranslate2FullPath))
{
return Path.Combine(dir, "Scripts");
}
return null;
}
var whisperFullPath = Path.Combine(dir, "Scripts", "whisper.exe");
if (File.Exists(whisperFullPath))
{
@ -223,6 +252,11 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
return "main";
}
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.StableTs)
{
return "stable-ts";
}
return "whisper";
}
@ -252,6 +286,14 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
return f;
}
}
else if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.StableTs)
{
var f = Path.Combine(whisperFolder, "stable-ts.exe");
if (File.Exists(f))
{
return f;
}
}
else if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe)
{
var f = Path.Combine(whisperFolder, "main.exe");
@ -295,8 +337,14 @@ namespace Nikse.SubtitleEdit.Core.AudioToText
{
return f;
}
}
else if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.StableTs)
{
var f = Path.Combine(whisperFolder, "stable-ts");
if (File.Exists(f))
{
return f;
}
}
return "whisper";

View File

@ -434,6 +434,7 @@ namespace Nikse.SubtitleEdit.Core.Common
public string WhisperLocation { get; set; }
public string WhisperCtranslate2Location { get; set; }
public string WhisperXLocation { get; set; }
public string WhisperStableTsLocation { get; set; }
public string WhisperCppModelLocation { get; set; }
public string WhisperExtraSettings { get; set; }
public bool WhisperAutoAdjustTimings { get; set; }
@ -6367,6 +6368,12 @@ $HorzAlign = Center
settings.Tools.WhisperXLocation = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperStableTsLocation");
if (subNode != null)
{
settings.Tools.WhisperStableTsLocation = subNode.InnerText;
}
subNode = node.SelectSingleNode("WhisperCppModelLocation");
if (subNode != null)
{
@ -10767,6 +10774,7 @@ $HorzAlign = Center
textWriter.WriteElementString("WhisperLocation", settings.Tools.WhisperLocation);
textWriter.WriteElementString("WhisperCtranslate2Location", settings.Tools.WhisperCtranslate2Location);
textWriter.WriteElementString("WhisperXLocation", settings.Tools.WhisperXLocation);
textWriter.WriteElementString("WhisperStableTsLocation", settings.Tools.WhisperStableTsLocation);
textWriter.WriteElementString("WhisperCppModelLocation", settings.Tools.WhisperCppModelLocation);
textWriter.WriteElementString("WhisperExtraSettings", settings.Tools.WhisperExtraSettings);
textWriter.WriteElementString("WhisperLanguageCode", settings.Tools.WhisperLanguageCode);

View File

@ -162,6 +162,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
engines.Add(WhisperChoice.ConstMe);
}
engines.Add(WhisperChoice.CTranslate2);
engines.Add(WhisperChoice.StableTs);
engines.Add(WhisperChoice.WhisperX);
foreach (var engine in engines)
@ -960,6 +961,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
}
var outputSrt = string.Empty;
var postParams = string.Empty;
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp ||
Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe)
{
@ -971,10 +973,15 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
Configuration.Settings.Tools.WhisperExtraSettings = string.Empty;
}
}
else if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.StableTs)
{
var srtFileName = Path.GetFileNameWithoutExtension(waveFileName);
postParams = $" -o {srtFileName}.srt";
}
var w = WhisperHelper.GetWhisperPathAndFileName();
var m = WhisperHelper.GetWhisperModelForCmdLine(model);
var parameters = $"--language {language} --model \"{m}\" {outputSrt}{translateToEnglish}{Configuration.Settings.Tools.WhisperExtraSettings} \"{waveFileName}\"";
var parameters = $"--language {language} --model \"{m}\" {outputSrt}{translateToEnglish}{Configuration.Settings.Tools.WhisperExtraSettings} \"{waveFileName}\"{postParams}";
SeLogger.Error($"{w} {parameters}");
@ -1495,6 +1502,38 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
Init();
}
private void WhisperEngineStableTs()
{
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.StableTs;
if (Configuration.IsRunningOnWindows)
{
var path = WhisperHelper.GetWhisperFolder();
if (string.IsNullOrEmpty(path))
{
using (var openFileDialog1 = new OpenFileDialog())
{
openFileDialog1.Title = "Locate stable-ts.exe (Python version)";
openFileDialog1.FileName = string.Empty;
openFileDialog1.Filter = "stable-ts.exe|stable-ts.exe";
if (openFileDialog1.ShowDialog() != DialogResult.OK
|| !openFileDialog1.FileName.EndsWith("stable-ts.exe", StringComparison.OrdinalIgnoreCase))
{
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.Cpp;
comboBoxWhisperEngine.Text = WhisperChoice.Cpp;
}
else
{
Configuration.Settings.Tools.WhisperStableTsLocation = openFileDialog1.FileName;
}
}
}
}
Init();
}
private void comboBoxWhisperEngine_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxWhisperEngine.Text == Configuration.Settings.Tools.WhisperChoice)
@ -1523,6 +1562,10 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
{
WhisperEngineWhisperX();
}
else if (comboBoxWhisperEngine.Text == WhisperChoice.StableTs)
{
WhisperEngineStableTs();
}
}
private void setCPPConstMeModelsFolderToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -483,6 +483,39 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
Init();
}
private void WhisperEngineStableTs()
{
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.StableTs;
if (Configuration.IsRunningOnWindows)
{
var path = WhisperHelper.GetWhisperFolder();
if (string.IsNullOrEmpty(path))
{
using (var openFileDialog1 = new OpenFileDialog())
{
openFileDialog1.Title = "Locate stable-ts.exe (Python version)";
openFileDialog1.FileName = string.Empty;
openFileDialog1.Filter = "stable-ts.exe|stable-ts.exe";
if (openFileDialog1.ShowDialog() != DialogResult.OK
|| !openFileDialog1.FileName.EndsWith("stable-ts.exe", StringComparison.OrdinalIgnoreCase))
{
Configuration.Settings.Tools.WhisperChoice = WhisperChoice.Cpp;
comboBoxWhisperEngine.Text = WhisperChoice.Cpp;
}
else
{
Configuration.Settings.Tools.WhisperStableTsLocation = openFileDialog1.FileName;
}
}
}
}
Init();
}
private void removeTemporaryFilesToolStripMenuItem_Click(object sender, EventArgs e)
{
Configuration.Settings.Tools.WhisperDeleteTempFiles = !Configuration.Settings.Tools.WhisperDeleteTempFiles;
@ -580,6 +613,10 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
{
WhisperEngineWhisperX();
}
else if (comboBoxWhisperEngine.Text == WhisperChoice.StableTs)
{
WhisperEngineStableTs();
}
}
private void setCPPConstMeModelsFolderToolStripMenuItem_Click(object sender, EventArgs e)