Minor work on progress helper

This commit is contained in:
niksedk 2023-08-16 15:43:15 +02:00
parent 0833371735
commit 207c4a8175
8 changed files with 96 additions and 10 deletions

View File

@ -980,9 +980,11 @@ We leverage the intrinsic rhythm of the image.</CreateSimpleChainingToolTip>
<InfoAssaOn>Note: Advanced SubStation Alpha styling will be used :)</InfoAssaOn>
<XGeneratedWithBurnedInSubsInX>"{0}" generated with burned-in subtitle in {1}.</XGeneratedWithBurnedInSubsInX>
<TimeRemainingMinutes>Time remaining: {0} minutes</TimeRemainingMinutes>
<TimeRemainingOneMinute>Time remaining: One minute</TimeRemainingOneMinute>
<TimeRemainingSeconds>Time remaining: {0} seconds</TimeRemainingSeconds>
<TimeRemainingAFewSeconds>Time remaining: A few seconds</TimeRemainingAFewSeconds>
<TimeRemainingMinutesAndSeconds>Time remaining: {0} minutes and {1} seconds</TimeRemainingMinutesAndSeconds>
<TimeRemainingOneMinuteAndSeconds>Time remaining: One minute and {0} seconds</TimeRemainingOneMinuteAndSeconds>
<TargetFileName>Target file name: {0}</TargetFileName>
<TargetFileSize>Target file size (requires 2 pass encoding)</TargetFileSize>
<FileSizeMb>File size in MB</FileSizeMb>

View File

@ -0,0 +1,38 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Logic;
namespace Test.Logic
{
[TestClass]
public class ProgressHelperTest
{
[TestMethod]
public void TestOneMinute()
{
var result = ProgressHelper.ToProgressTime(new TimeCode(0, 1, 0, 0).TotalMilliseconds);
Assert.AreEqual("Time remaining: One minute", result);
}
[TestMethod]
public void TestOneMinuteAndTwoSeconds()
{
var result = ProgressHelper.ToProgressTime(new TimeCode(0, 1, 2, 0).TotalMilliseconds);
Assert.AreEqual("Time remaining: One minute and 2 seconds", result);
}
[TestMethod]
public void TestTwoMinuteAndTwoSeconds()
{
var result = ProgressHelper.ToProgressTime(new TimeCode(0, 2, 2, 0).TotalMilliseconds);
Assert.AreEqual("Time remaining: 2 minutes and 2 seconds", result);
}
[TestMethod]
public void TestOneSecond()
{
var result = ProgressHelper.ToProgressTime(new TimeCode(0, 0, 1, 0).TotalMilliseconds);
Assert.AreEqual("Time remaining: A few seconds", result);
}
}
}

View File

@ -105,6 +105,7 @@
<Compile Include="Logic\SubtitleFormats\Cea708Test.cs" />
<Compile Include="Logic\SubtitleFormats\SubtitleFormatFunctionsTest.cs" />
<Compile Include="Logic\TarFileTest.cs" />
<Compile Include="Logic\ProgressHelperTest.cs" />
<Compile Include="Logic\TransportStream\TransportStreamTest.cs" />
<Compile Include="Logic\ParagraphTest.cs" />
<Compile Include="Logic\StrippableTextTest.cs" />

View File

@ -253,6 +253,7 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private void ButtonGenerate_Click(object sender, EventArgs e)
{
_cancel = false;
if (comboBoxModels.Items.Count == 0)
{
buttonDownload_Click(null, null);
@ -1761,17 +1762,31 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
private void contextMenuStripWhisperAdvanced_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperCppModelLocation) &&
Directory.Exists(Configuration.Settings.Tools.WhisperCppModelLocation))
runOnlyPostProcessingToolStripMenuItem.Visible = buttonGenerate.Enabled;
toolStripSeparatorRunOnlyPostprocessing.Visible = buttonGenerate.Enabled;
if (Configuration.Settings.Tools.WhisperChoice == WhisperChoice.Cpp ||
Configuration.Settings.Tools.WhisperChoice == WhisperChoice.ConstMe)
{
setCPPConstmeModelsFolderToolStripMenuItem.Text = $"{LanguageSettings.Current.AudioToText.SetCppConstMeFolder} [{Configuration.Settings.Tools.WhisperCppModelLocation}]";
if (!string.IsNullOrEmpty(Configuration.Settings.Tools.WhisperCppModelLocation) &&
Directory.Exists(Configuration.Settings.Tools.WhisperCppModelLocation))
{
setCPPConstmeModelsFolderToolStripMenuItem.Text = $"{LanguageSettings.Current.AudioToText.SetCppConstMeFolder} [{Configuration.Settings.Tools.WhisperCppModelLocation}]";
}
else
{
setCPPConstmeModelsFolderToolStripMenuItem.Text = LanguageSettings.Current.AudioToText.SetCppConstMeFolder;
}
setCPPConstmeModelsFolderToolStripMenuItem.Visible = true;
}
else
{
setCPPConstmeModelsFolderToolStripMenuItem.Text = LanguageSettings.Current.AudioToText.SetCppConstMeFolder;
setCPPConstmeModelsFolderToolStripMenuItem.Visible = false;
}
downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Visible = Configuration.Settings.Tools.WhisperChoice == WhisperChoice.PurfviewFasterWhisper;
downloadCUDAForPerfviewsWhisperFasterToolStripMenuItem.Visible =
buttonGenerate.Enabled &&
Configuration.Settings.Tools.WhisperChoice == WhisperChoice.PurfviewFasterWhisper;
var whisperLogFile = SeLogger.GetWhisperLogFilePath();
if (File.Exists(whisperLogFile))
@ -1789,6 +1804,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
{
try
{
labelProgress.Text = LanguageSettings.Current.AudioToText.PostProcessing;
_languageCode = LanguageAutoDetect.AutoDetectGoogleLanguage(_subtitle);
var postProcessor = new AudioToTextPostProcessor(_languageCode)
{

View File

@ -1231,9 +1231,11 @@ namespace Nikse.SubtitleEdit.Logic
InfoAssaOn = "Note: Advanced SubStation Alpha styling will be used :)",
XGeneratedWithBurnedInSubsInX = "\"{0}\" generated with burned-in subtitle in {1}.",
TimeRemainingMinutes = "Time remaining: {0} minutes",
TimeRemainingOneMinute = "Time remaining: One minute",
TimeRemainingSeconds = "Time remaining: {0} seconds",
TimeRemainingAFewSeconds = "Time remaining: A few seconds",
TimeRemainingMinutesAndSeconds = "Time remaining: {0} minutes and {1} seconds",
TimeRemainingOneMinuteAndSeconds = "Time remaining: One minute and {0} seconds",
TargetFileName = "Target file name: {0}",
TargetFileSize = "Target file size (requires 2 pass encoding)",
FileSizeMb = "File size in MB",

View File

@ -2581,6 +2581,9 @@ namespace Nikse.SubtitleEdit.Logic
case "GenerateVideoWithBurnedInSubs/TimeRemainingMinutes":
language.GenerateVideoWithBurnedInSubs.TimeRemainingMinutes = reader.Value;
break;
case "GenerateVideoWithBurnedInSubs/TimeRemainingOneMinute":
language.GenerateVideoWithBurnedInSubs.TimeRemainingOneMinute = reader.Value;
break;
case "GenerateVideoWithBurnedInSubs/TimeRemainingSeconds":
language.GenerateVideoWithBurnedInSubs.TimeRemainingSeconds = reader.Value;
break;
@ -2590,6 +2593,9 @@ namespace Nikse.SubtitleEdit.Logic
case "GenerateVideoWithBurnedInSubs/TimeRemainingMinutesAndSeconds":
language.GenerateVideoWithBurnedInSubs.TimeRemainingMinutesAndSeconds = reader.Value;
break;
case "GenerateVideoWithBurnedInSubs/TimeRemainingOneMinuteAndSeconds":
language.GenerateVideoWithBurnedInSubs.TimeRemainingOneMinuteAndSeconds = reader.Value;
break;
case "GenerateVideoWithBurnedInSubs/TargetFileName":
language.GenerateVideoWithBurnedInSubs.TargetFileName = reader.Value;
break;

View File

@ -1055,9 +1055,11 @@
public string InfoAssaOn { get; set; }
public string XGeneratedWithBurnedInSubsInX { get; set; }
public string TimeRemainingMinutes { get; set; }
public string TimeRemainingOneMinute { get; set; }
public string TimeRemainingSeconds { get; set; }
public string TimeRemainingAFewSeconds { get; set; }
public string TimeRemainingMinutesAndSeconds { get; set; }
public string TimeRemainingOneMinuteAndSeconds { get; set; }
public string TargetFileName { get; set; }
public string TargetFileSize { get; set; }
public string FileSizeMb { get; set; }

View File

@ -7,20 +7,38 @@ namespace Nikse.SubtitleEdit.Logic
{
public static string ToProgressTime(double estimatedTotalMs)
{
var totalSeconds = (int)Math.Round(estimatedTotalMs / 1000.0);
var totalSeconds = (int)Math.Round(estimatedTotalMs / 1000.0, MidpointRounding.AwayFromZero);
if (totalSeconds < 60)
{
return totalSeconds < 3
? string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingAFewSeconds)
: string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingSeconds, totalSeconds);
if (totalSeconds < 3)
{
return string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingAFewSeconds);
}
return string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingSeconds, totalSeconds);
}
if (totalSeconds / 60 > 5)
{
return string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingMinutes, (int)Math.Round(totalSeconds / 60.0));
return string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingMinutes, (int)Math.Round(totalSeconds / 60.0, MidpointRounding.AwayFromZero));
}
var timeCode = new TimeCode(estimatedTotalMs);
if (timeCode.Seconds == 0 && timeCode.Minutes > 0)
{
if (timeCode.Minutes == 1)
{
return string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingOneMinute);
}
return string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingMinutes, timeCode.Minutes);
}
if (timeCode.Hours == 0 && timeCode.Minutes == 1)
{
return string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingOneMinuteAndSeconds, timeCode.Seconds);
}
return string.Format(LanguageSettings.Current.GenerateVideoWithBurnedInSubs.TimeRemainingMinutesAndSeconds, timeCode.Minutes + timeCode.Hours * 60, timeCode.Seconds);
}
}