From 3db3f275eab3f6b66faa1f1eeffc5ce405090b6c Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Wed, 20 Mar 2024 20:07:10 +0100 Subject: [PATCH] More post-processing --- src/Test/Core/AudioToTextTest.cs | 28 ++++++++++++++++--- .../AudioToText/AudioToTextPostProcessor.cs | 8 ++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Test/Core/AudioToTextTest.cs b/src/Test/Core/AudioToTextTest.cs index 368a3a4bf..544b3c5aa 100644 --- a/src/Test/Core/AudioToTextTest.cs +++ b/src/Test/Core/AudioToTextTest.cs @@ -129,7 +129,7 @@ Could be fun. 14 00:00:29,660 --> 00:00:32,580 -Well, we could get to know each other a +We could get to know each other a little, maybe loosen things up around 15 @@ -138,7 +138,7 @@ here? 16 00:00:33,680 --> 00:00:39,160 -Well, I've worked with this lot before, +I've worked with this lot before, and, erm... Yeah, this is as loose as they 17 @@ -191,8 +191,8 @@ Wait."; var fixedSubtitle = AudioToTextPostProcessor.TryForWholeSentences(subtitle, "en", 42); Assert.AreEqual(14, fixedSubtitle.Paragraphs.Count); - Assert.IsTrue(fixedSubtitle.Paragraphs[2].Text == "Well, we could get to know each other a" + Environment.NewLine + "little, maybe loosen things up around here?"); - Assert.IsTrue(fixedSubtitle.Paragraphs[3].Text == "Well, I've worked with this lot before, and," + Environment.NewLine + "erm... Yeah, this is as loose as they get."); + Assert.IsTrue(fixedSubtitle.Paragraphs[2].Text == "We could get to know each other a" + Environment.NewLine + "little, maybe loosen things up around here?"); + Assert.IsTrue(fixedSubtitle.Paragraphs[3].Text == "I've worked with this lot before, and," + Environment.NewLine + "erm... Yeah, this is as loose as they get."); Assert.IsTrue(fixedSubtitle.Paragraphs[4].Text == "Hmm."); Assert.IsTrue(fixedSubtitle.Paragraphs[5].Text == "What's the about that, Bob's?"); } @@ -217,5 +217,25 @@ that could be fun indeed my friend."; Assert.IsTrue(fixedSubtitle.Paragraphs[0].Text == "Yes, I think this could" + Environment.NewLine + "indeed be very good."); Assert.IsTrue(fixedSubtitle.Paragraphs[1].Text == "But also that could be" + Environment.NewLine + "fun indeed my friend."); } + + [TestMethod] + public void TryForWholeSentences3() + { + var raw = @"1 +00:04:23,780 --> 00:04:27,340 +In each of the commercials that I'm in, +I'm the one who simply can't go on without + +2 +00:04:27,340 --> 00:04:27,780 +the product."; + + var subtitle = new Subtitle(); + new SubRip().LoadSubtitle(subtitle, raw.SplitToLines(), null); + + var fixedSubtitle = AudioToTextPostProcessor.TryForWholeSentences(subtitle, "en", 42); + + Assert.AreEqual(2, fixedSubtitle.Paragraphs.Count); + } } } diff --git a/src/libse/AudioToText/AudioToTextPostProcessor.cs b/src/libse/AudioToText/AudioToTextPostProcessor.cs index bb73c304a..a1fb9ddd4 100644 --- a/src/libse/AudioToText/AudioToTextPostProcessor.cs +++ b/src/libse/AudioToText/AudioToTextPostProcessor.cs @@ -184,8 +184,10 @@ namespace Nikse.SubtitleEdit.Core.AudioToText var currentOk = arrayCurrent.Count == 1 || (arrayCurrent.Count == 2 && arrayCurrent[0].Length < lineMaxLength * 2); var nextOk = arrayNext.Count == 1 || (arrayNext.Count == 2 && arrayNext[0].Length < lineMaxLength * 2); + var allOk = newCurrentText.Length < lineMaxLength * 2 && + newNextText.Length < lineMaxLength * 2; - if (currentOk && nextOk) + if (currentOk && nextOk && allOk) { p.Text = newCurrentText; next.Text = newNextText; @@ -219,8 +221,10 @@ namespace Nikse.SubtitleEdit.Core.AudioToText var currentOk = arrayCurrent.Count == 1 || (arrayCurrent.Count == 2 && arrayCurrent[0].Length < lineMaxLength * 2); var nextOk = arrayNext.Count == 1 || (arrayNext.Count == 2 && arrayNext[0].Length < lineMaxLength * 2); + var allOk = newCurrentText.Length < lineMaxLength * 2 && + newNextText.Length < lineMaxLength * 2; - if (currentOk && nextOk) + if (currentOk && nextOk && allOk) { p.Text = newCurrentText; next.Text = newNextText;