Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cutconcat fixed max duration #1292

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading