A TTS that fits in your CPU (and pocket)
Python
Training loader: skip punctuation-only trailing words when trimming (#397)
manu-lm3396b66bf364
diff --git a/training/dataloader/loader.py b/training/dataloader/loader.pyindex eea5322..350ca46 100644--- a/training/dataloader/loader.py+++ b/training/dataloader/loader.py@@ -128,15 +128,16 @@ class DataLoader:"""End of the last aligned word, i.e. where the speech actually stops.None when the entry carries no alignment, which is the documented- manifest format without `words`, or when its last word is unaligned:- aligners leave words such as "1943" without times, and trimming at the- word before would cut a sentence-final number out of the audio while- the transcript keeps it.+ manifest format without `words`, or when its last spoken word is+ unaligned: aligners leave words such as "1943" without times, and+ trimming at the word before would cut a sentence-final number out of+ the audio while the transcript keeps it. Trailing punctuation-only+ words ("»", "?") are not spoken and are skipped."""- if not entry.words or entry.words[-1].get("end") is None:+ spoken = [w for w in entry.words or [] if any(c.isalnum() for c in w["word"])]+ if not spoken or spoken[-1].get("end") is None:return None- ends = [w["end"] for w in entry.words if w.get("end") is not None]- return max(ends) if ends else None+ return max(w["end"] for w in spoken if w.get("end") is not None)def _choose_cut(self, entry: Entry) -> tuple[float, str] | None:"""(cut in seconds, transcript of the words after it), None without alignment."""diff --git a/training/tests/test_dataloader.py b/training/tests/test_dataloader.pyindex 35cb038..9c0810c 100644--- a/training/tests/test_dataloader.py+++ b/training/tests/test_dataloader.py@@ -161,3 +161,6 @@ def test_unaligned_last_word_keeps_the_end_of_the_file():assert DataLoader._last_word_end(entry(None)) is Noneassert DataLoader._last_word_end(entry(1.2)) == 1.2+ quote = {"word": "»", "end": None} # unaligned punctuation is not spoken+ words = [{"word": "oui", "start": 0.1, "end": 0.3}, quote]+ assert DataLoader._last_word_end(Entry("a.wav", 2.0, "oui »", words)) == 0.3