espnet3.contract.kinds.segments.SegmentsKind
Less than 1 minute
espnet3.contract.kinds.segments.SegmentsKind
class espnet3.contract.kinds.segments.SegmentsKind
Bases: Kind
segments: dicts with text, start and end in seconds.
The shape espnet align prints; score is optional. Pieces append.
check(value, field, model, , output)
Require a list of dicts with text, start and end.
- Parameters:
- value – What the caller gave, or what the hook returned.
- field – The declaration, for the name in the error.
- model – Unused.
- output – Whether
valueis a hook’s result.
- Returns:
valueitself; extra keys such asscorepass through. - Raises:TypeError – If
valueis not a list, or an element lacks one of the three keys.
####### Examples
>>> SegmentsKind().check(
... [{"text": "hi", "start": 0.0, "end": 0.4, "score": 0.9}],
... Field("segments", "segments"), model, output=True)
[{'text': 'hi', 'start': 0.0, 'end': 0.4, 'score': 0.9}]
>>> SegmentsKind().check(
... [(0.0, 0.4)], Field("segments", "segments"), model, output=True)
Traceback (most recent call last):
TypeError: 'segments' returned must be a list of dicts with text, ...join(first, second)
Append the segments.
- Parameters:
- first – The segments gathered so far.
- second – The segments that follow.
- Returns: One list holding both.
####### Examples
>>> a = [{"text": "hi", "start": 0.0, "end": 0.4}]
>>> b = [{"text": "yo", "start": 0.4, "end": 0.8}]
>>> len(SegmentsKind().join(a, b))
2