From 6218b5bd58fdfed8dd2df340ea52adee1c67ad59 Mon Sep 17 00:00:00 2001 From: Omid Sadjadi Date: Fri, 5 Apr 2024 15:30:02 -0400 Subject: [PATCH 1/3] select a random sub-region of the noise based on the delta duration we select a random sub-region of the noise based on the delta duration needed to reach the target duration --- lhotse/cut/set.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lhotse/cut/set.py b/lhotse/cut/set.py index 4f0872f3d..7d7830142 100644 --- a/lhotse/cut/set.py +++ b/lhotse/cut/set.py @@ -3564,7 +3564,7 @@ def noise_gen(): # where we mix in some noise cut that effectively has 0 frames of features. while mixed_in_duration < target_mixed_duration: to_mix = next(mix_in_cuts) - to_mix = self._maybe_truncate_cut(to_mix, target_mixed_duration, rng) + to_mix = self._maybe_truncate_cut(to_mix, target_mixed_duration - mixed_in_duration, rng) # Keep the SNR constant for each cut from "self". mixed = mixed.mix( other=to_mix, From 734c56a57ed2ffa2dd6d8067154c198cc29162ed Mon Sep 17 00:00:00 2001 From: Omid Sadjadi Date: Fri, 5 Apr 2024 20:40:21 -0400 Subject: [PATCH 2/3] fix failing unit tests in cut mix --- lhotse/cut/set.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lhotse/cut/set.py b/lhotse/cut/set.py index 7d7830142..5c41b1832 100644 --- a/lhotse/cut/set.py +++ b/lhotse/cut/set.py @@ -3562,9 +3562,15 @@ def noise_gen(): # Keep sampling until we mixed in a "duration" amount of noise. # Note: we subtract 0.05s (50ms) from the target duration to avoid edge cases # where we mix in some noise cut that effectively has 0 frames of features. - while mixed_in_duration < target_mixed_duration: + while mixed_in_duration < ( + target_mixed_duration - 0.05 + if self.duration is None + else target_mixed_duration + ): to_mix = next(mix_in_cuts) - to_mix = self._maybe_truncate_cut(to_mix, target_mixed_duration - mixed_in_duration, rng) + to_mix = self._maybe_truncate_cut( + to_mix, target_mixed_duration - mixed_in_duration, rng + ) # Keep the SNR constant for each cut from "self". mixed = mixed.mix( other=to_mix, From 63e7476fea9300562d649edd202362dd231b8ec0 Mon Sep 17 00:00:00 2001 From: Omid Sadjadi Date: Tue, 9 Apr 2024 15:36:53 -0400 Subject: [PATCH 3/3] apply tolerance in while loop condition unconditionally --- lhotse/cut/set.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lhotse/cut/set.py b/lhotse/cut/set.py index 5c41b1832..58900306b 100644 --- a/lhotse/cut/set.py +++ b/lhotse/cut/set.py @@ -3562,11 +3562,7 @@ def noise_gen(): # Keep sampling until we mixed in a "duration" amount of noise. # Note: we subtract 0.05s (50ms) from the target duration to avoid edge cases # where we mix in some noise cut that effectively has 0 frames of features. - while mixed_in_duration < ( - target_mixed_duration - 0.05 - if self.duration is None - else target_mixed_duration - ): + while mixed_in_duration < target_mixed_duration - 0.05: to_mix = next(mix_in_cuts) to_mix = self._maybe_truncate_cut( to_mix, target_mixed_duration - mixed_in_duration, rng