From ddeee56e035debc5176a73dc137d8edb17824620 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Wed, 11 Sep 2024 09:21:36 +0200 Subject: [PATCH] Fix for divide by zero in tts --- src/ui/Forms/Tts/TextToSpeech.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ui/Forms/Tts/TextToSpeech.cs b/src/ui/Forms/Tts/TextToSpeech.cs index 41db3de4d..e107a14ec 100644 --- a/src/ui/Forms/Tts/TextToSpeech.cs +++ b/src/ui/Forms/Tts/TextToSpeech.cs @@ -454,7 +454,7 @@ namespace Nikse.SubtitleEdit.Forms.Tts progressBar1.Value = 0; progressBar1.Maximum = subtitle.Paragraphs.Count; progressBar1.Visible = true; - var ext = ".wav"; + const string ext = ".wav"; for (var index = 0; index < subtitle.Paragraphs.Count; index++) { @@ -524,7 +524,15 @@ namespace Nikse.SubtitleEdit.Forms.Tts 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}"); if (!string.IsNullOrEmpty(overrideFileName) && File.Exists(Path.Combine(_waveFolder, overrideFileName))) {