Skip to content

A TTS that fits in your CPU (and pocket)

Python

Training loader: keep the file end when the last word is unaligned (#394)

manu-lmedbd17c8d9e5
diff --git a/training/dataloader/loader.py b/training/dataloader/loader.py
index cb25dbf..eea5322 100644
--- a/training/dataloader/loader.py
+++ b/training/dataloader/loader.py
@@ -128,9 +128,12 @@ 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`.
+ 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.
"""
- if not entry.words:
+ if not entry.words or entry.words[-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
diff --git a/training/tests/test_dataloader.py b/training/tests/test_dataloader.py
index 1dfc889..35cb038 100644
--- a/training/tests/test_dataloader.py
+++ b/training/tests/test_dataloader.py
@@ -9,7 +9,7 @@ import numpy.typing as npt
import pytest
import sphn
-from training.dataloader import DataLoader, load_entries
+from training.dataloader import DataLoader, Entry, load_entries
SR = 24000
@@ -152,3 +152,12 @@ def test_startup_check_rejects_manifests_too_small_for_the_loaders(tmp_path: Pat
check_manifest_sizes(args, world_size=1) # 12 // 3 = 4 entries per shard, 2 x 2 needed
with pytest.raises(SystemExit, match="num_bucket_batches"):
check_manifest_sizes(args, world_size=2) # 12 // 6 = 2 < 4
+
+
+def test_unaligned_last_word_keeps_the_end_of_the_file():
+ def entry(last_end: float | None) -> Entry:
+ words = [{"word": "in", "start": 0.1, "end": 0.3}, {"word": "1943.", "end": last_end}]
+ return Entry("a.wav", 2.0, "in 1943.", words)
+
+ assert DataLoader._last_word_end(entry(None)) is None
+ assert DataLoader._last_word_end(entry(1.2)) == 1.2