Fix for divide by zero in tts

This commit is contained in:
Nikolaj Olsson 2024-09-11 09:21:36 +02:00
parent 0b90c931a6
commit ddeee56e03

View File

@ -454,7 +454,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts
progressBar1.Value = 0; progressBar1.Value = 0;
progressBar1.Maximum = subtitle.Paragraphs.Count; progressBar1.Maximum = subtitle.Paragraphs.Count;
progressBar1.Visible = true; progressBar1.Visible = true;
var ext = ".wav"; const string ext = ".wav";
for (var index = 0; index < subtitle.Paragraphs.Count; index++) for (var index = 0; index < subtitle.Paragraphs.Count; index++)
{ {
@ -524,7 +524,15 @@ namespace Nikse.SubtitleEdit.Forms.Tts
continue; continue;
} }
var factor = (decimal)waveInfo.TotalMilliseconds / (decimal)(p.DurationTotalMilliseconds + addDuration); var divisor = (decimal)(p.DurationTotalMilliseconds + addDuration);
if (divisor <= 0)
{
SeLogger.Error($"TextToSpeech: Duration is zero (skipping): {pFileName}, {p}");
fileNames.Add(new FileNameAndSpeedFactor { Filename = pFileName, Factor = 1 });
continue;
}
var factor = (decimal)waveInfo.TotalMilliseconds / divisor;
var outputFileName2 = Path.Combine(_waveFolder, $"{index}_{Guid.NewGuid()}{ext}"); var outputFileName2 = Path.Combine(_waveFolder, $"{index}_{Guid.NewGuid()}{ext}");
if (!string.IsNullOrEmpty(overrideFileName) && File.Exists(Path.Combine(_waveFolder, overrideFileName))) if (!string.IsNullOrEmpty(overrideFileName) && File.Exists(Path.Combine(_waveFolder, overrideFileName)))
{ {