Skip to content

Commit

Permalink
Cutconcat fixed max duration (#1292)
Browse files Browse the repository at this point in the history
* CutConcatenate: added fixed max_duration parameter

* pre-commit applied
  • Loading branch information
swigls committed Feb 29, 2024
1 parent e2c963f commit 1cd2d88
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lhotse/dataset/cut_transforms/concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,34 @@ class CutConcatenate:
adding some silence between them to avoid a large number of padding frames that waste the computation.
"""

def __init__(self, gap: Seconds = 1.0, duration_factor: float = 1.0) -> None:
def __init__(
self,
gap: Seconds = 1.0,
duration_factor: float = 1.0,
max_duration: Optional[Seconds] = None,
) -> None:
"""
CutConcatenate's constructor.
:param gap: The duration of silence in seconds that is inserted between the cuts;
it's goal is to let the model "know" that there are separate utterances in a single example.
:param duration_factor: Determines the maximum duration of the concatenated cuts;
by default it's 1, setting the limit at the duration of the longest cut in the batch.
:param max_duration: If a value is given (in seconds), the maximum duration of concatenated cuts
is fixed to the value while duration_factor is ignored.
"""
self.gap = gap
self.duration_factor = duration_factor
self.max_duration = max_duration

def __call__(self, cuts: CutSet) -> CutSet:
cuts = cuts.sort_by_duration(ascending=False)
return concat_cuts(
cuts, gap=self.gap, max_duration=cuts[0].duration * self.duration_factor
cuts,
gap=self.gap,
max_duration=self.max_duration
if self.max_duration
else cuts[0].duration * self.duration_factor,
)


Expand Down

0 comments on commit 1cd2d88

Please sign in to comment.