nemo_curator.stages.audio.tagging.prepare_module_segments

View as Markdown

Prepare Module Segments Stage. Merges adjacent same-speaker segments and splits by duration, punctuation, and bandwidth.

Module Contents

Classes

NameDescription
PrepareModuleSegmentsStageStage that prepares segments for TTS or ASR by merging and splitting based on

API

class nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage(
module: str = 'tts',
min_duration: float = 5.0,
max_duration: float = 20.0,
max_pause: float = 2.0,
text_key: str = 'text',
words_key: str = 'words',
terminal_punct_marks: str = '.!?。??!。',
full_utterance_ratio: float = 1.0,
punctuation_split_only: bool = False,
name: str = 'PrepareModuleSegments'
)
Dataclass

Bases: ProcessingStage[AudioTask, AudioTask]

Stage that prepares segments for TTS or ASR by merging and splitting based on duration, punctuation, and bandwidth.

Merges adjacent same-speaker segments, then splits by max duration, pauses, terminal punctuation, and bandwidth changes.

Parameters:

module
strDefaults to 'tts'

Target module: “tts” (single-speaker segments) or “asr” (multi-speaker ok).

min_duration
floatDefaults to 5.0

Minimum segment duration in seconds. Defaults to 5.0.

max_duration
floatDefaults to 20.0

Maximum segment duration in seconds. Defaults to 20.0.

max_pause
floatDefaults to 2.0

Max pause between words to stay in same segment (TTS).

text_key
strDefaults to 'text'

Key for segment text. Defaults to “text”.

words_key
strDefaults to 'words'

Key for word-level alignments in segments. Defaults to “words”.

terminal_punct_marks
strDefaults to '.!?。??!。'

Punctuation that ends an utterance (e.g. ”.!?”). Defaults to CJK/Latin punct string.

full_utterance_ratio
floatDefaults to 1.0

Ratio of content to segment at terminal punctuation (0-1).

punctuation_split_only
boolDefaults to False

If True, split only at punctuation; else also by duration. Defaults to False.

name
strDefaults to 'PrepareModuleSegments'

Stage name for logging and output files. Defaults to “PrepareModuleSegments”.

Returns:

The same data as in the input manifest, but with the new segments added to the metadata.

full_utterance_ratio
float = 1.0
max_duration
float = 20.0
max_pause
float = 2.0
min_duration
float = 5.0
module
str = 'tts'
name
str = 'PrepareModuleSegments'
punctuation_split_only
bool = False
terminal_punct_marks
str = '.!?。??!。'
text_key
str = 'text'
words_key
str = 'words'
nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.__post_init__()
nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.add_new_segments_to_metadata(
metadata: dict[str, typing.Any],
new_segments: list[dict[str, typing.Any]]
) -> None

Write new segment list into metadata with text, words, and metrics keys.

nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.get_words_list_from_all_segments(
metadata: dict[str, typing.Any]
) -> list[dict[str, typing.Any]]

This method gets the words list from all the speaker segments

Parameters:

metadata
dict[str, Any]

A dictionary containing the metadata of the audio file

Returns: list[dict[str, Any]]

A list of words with the following fields:

  • word: The word
  • start: The start time of the word
  • end: The end time of the word
  • speaker: The speaker of the word
  • pesq_squim: The PESQ score of the word if available
  • stoi_squim: The STOI score of the word if available
  • sisdr_squim: The SI-SDR score of the word if available
  • bandwidth: The bandwidth of the word if available
nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.inputs() -> tuple[list[str], list[str]]
nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.is_valid_segment(
segment: dict[str, typing.Any]
) -> bool

Return False if segment is a single over-long word or has no text.

nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.prepare_asr_segments(
words: list[dict[str, typing.Any]],
metadata: dict[str, typing.Any]
) -> None

Prepare ASR segments (multi-speaker per segment allowed).

nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.prepare_tts_segments(
words: list[dict[str, typing.Any]],
metadata: dict[str, typing.Any]
) -> None

Prepare TTS segments (single speaker per segment).

nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.process(
task: nemo_curator.tasks.AudioTask
) -> nemo_curator.tasks.AudioTask

Process one entry: build words from segments, then prepare TTS or ASR segments.

nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.split_segment_by_duration(
segment: dict[str, typing.Any]
) -> list[dict[str, typing.Any]]

Split one segment by duration, pause, and bandwidth (TTS) or duration only (ASR).

nemo_curator.stages.audio.tagging.prepare_module_segments.PrepareModuleSegmentsStage.split_segment_by_punctuation(
segment: dict[str, typing.Any]
) -> list[dict[str, typing.Any]]

Split segment at terminal punctuation; fallback to duration split if none, or when over max_duration.