ldc_bpcsad.segment.Segment

class ldc_bpcsad.segment.Segment(onset: float, offset: float)[source]

Speech segment.

Parameters:
  • onset (float) – Onset of segment in seconds from beginning of recording.

  • offset (float) – Offset of segment in seconds from beginning of recording.

static allclose(lsegs, rsegs, atol=1e-07)[source]

Return True if two lists of segments are element-wise equal within a tolerance.

Two segments are considered equal if their onsets/offsets are within atol of each other.

Parameters:
  • lsegs (Iterable[Segment]) – Lists of segments to compare.

  • rsegs (Iterable[Segment]) – Lists of segments to compare.

  • atol (float, optional) – Times within atol seconds are considered close. (Default: 1e-7)

clip(lb, ub, in_place=False)[source]

Clip segment so that its onset/offset lay within [lb, ub].

Parameters:
  • lb (float) – Lowerbound of interval.

  • ub (float) – Upperbound of interval.

  • in_place (bool, optional) – If True, perform operation in place.

Returns:

Clipped segment.

Return type:

Segment

copy()[source]

Return deep copy of segment.

property duration

Segment duration in seconds.

gap(other)[source]

Return gap between segment and another segment.

If the two segments overlap, the gap will have duration <= 0.

Parameters:

other (Segment) – Other segment.

Returns:

Gap segment.

Return type:

Segment

isclose(other, atol=1e-07)[source]

Return True if onsets/offsets of segments are equal within a tolerance.

Parameters:
  • other (Segment) – Segment to compare with.

  • atol (float, optional) – Times within atol seconds are considered close. (Default: 1e-7)

static merge_segs(segs, thresh=0.0, is_sorted=False, copy=True)[source]

Merge segments.

Produces a new segmentation from segs by:

  • merging overlapping segments

  • merging segments separated by <= thresh seconds.

Parameters:
  • segs (Iterable[Segment]) – Segments to be merged.

  • thresh (float, optional) – Tolerance for merging. Segments separated by <= thresh seconds will be merged. (Default: 0.0)

  • is_sorted (bool, optional) – If True, treat segs as already sorted. Otherwise, sort before performing mergers. (Default: False)

  • copy (bool, optional) – If True, create copy of segs and perform merger on this copy. (Default: True)

Returns:

Merged segments.

Return type:

List[Segment]

round(precision=3, in_place=False)[source]

Round onset/offset to precision digits.

shift(delta, in_place=False)[source]

Shift segment by delta seconds.

union(*other)[source]

Return union of segments.

The union of a set of segments is defined as the minimal segment containing each segment in the set.

Parameters:

other (Segment) – Other segment.

Returns:

Union of the segments.

Return type:

Segment