Skip to content

Operations Module#

soundevent.operations #

Operations Module.

This module provides generic operations for manipulating sound event data.

Modules:

Name Description
data

Data Module.

Functions:

Name Description
segment_clip

Segments a clip into smaller clips of a specified duration.

Attributes#

Functions#

segment_clip(clip, duration, hop=None, include_incomplete=False) #

Segments a clip into smaller clips of a specified duration.

This function iterates yields segments of a given duration, with a specified hop size between segments. It can optionally include the last segment even if it is shorter than the specified duration.

Parameters:

Name Type Description Default
clip Clip

The input audio clip to be segmented.

required
duration float

The duration of each segment in seconds.

required
hop Optional[float]

The hop size between segments in seconds. If None (default), the hop size is set equal to the duration, resulting in non-overlapping segments.

None
include_incomplete bool

Whether to include the last segment if it is shorter than the specified duration. Defaults to False.

False

Yields:

Type Description
Clip

A segmented clip with a unique UUID, start time, end time, and the same recording as the input clip.

Raises:

Type Description
ValueError

If the duration or hop size is negative or zero.

Notes

If include_incomplete is True, the last segment might be shorter than the specified duration, as its end time is clamped to the end time of the input clip.

Examples:

>>> from soundevent import data
>>> clip = data.Clip(
...     start_time=0.0,
...     end_time=10.0,
...     recording="...",
... )
>>> segments = segment_clip(clip, duration=2.0, hop=1.0)
>>> for segment in segments:
...     print(segment.start_time, segment.end_time)
0.0 2.0
1.0 3.0
2.0 4.0
3.0 5.0
4.0 6.0
5.0 7.0
6.0 8.0
7.0 9.0
8.0 10.0