nemo_voice_agent.pipecat.utils.text.simple_text_aggregator

View as Markdown

Module Contents

Classes

NameDescription
SimpleSegmentedTextAggregatorA simple text aggregator that segments the text into sentences based on punctuation marks.

Functions

NameDescription
find_last_comma_indexFind the last occurrence of a valid comma in the text,
find_last_period_indexFind the last occurrence of a period in the text,
has_partial_decimalCheck if the text ends with a partial decimal.

API

class nemo_voice_agent.pipecat.utils.text.simple_text_aggregator.SimpleSegmentedTextAggregator(
punctuation_marks: str | list[str] = '.,!?;:\n',
ignore_marks: str | list[str] = '*',
min_sentence_length: int = 0,
use_legacy_eos_detection: bool = False,
kwargs = {}
)

Bases: SimpleTextAggregator

A simple text aggregator that segments the text into sentences based on punctuation marks.

_ignore_marks
_punctuation_marks
= list()
nemo_voice_agent.pipecat.utils.text.simple_text_aggregator.SimpleSegmentedTextAggregator._find_segment_end(
text: str
) -> typing.Optional[int]

find the end of text segment.

Parameters:

text
str

The text to find the end of the segment.

Returns: Optional[int]

The index of the end of the segment, or None if the text is too short.

nemo_voice_agent.pipecat.utils.text.simple_text_aggregator.SimpleSegmentedTextAggregator.aggregate(
text: str
) -> typing.AsyncIterator[pipecat.utils.text.base_text_aggregator.Aggregation]
async

Aggregate the input text and return the first complete sentence in the text.

Parameters:

text
str

The text to aggregate.

Returns: AsyncIterator[Aggregation]

The first complete sentence in the text, or None if none is found.

nemo_voice_agent.pipecat.utils.text.simple_text_aggregator.find_last_comma_index(
text: str,
min_residual_length: int = 5
) -> int

Find the last occurrence of a valid comma in the text, ignoring the commas in the numbers (e.g., “1,234,567”). If the leftover text after the comma is too short, it may be an abbreviation, return -1.

Returns: The index of the last occurrence of a valid comma, or -1 if no valid comma is found.

Parameters:

text
str

The text to find the last occurrence of a valid comma.

min_residual_length
int" default="5

The minimum length of the leftover text after the rightmost comma to be considered as a valid sentence (e.g., “Santa Clara, CA, US.”).

nemo_voice_agent.pipecat.utils.text.simple_text_aggregator.find_last_period_index(
text: str
) -> int

Find the last occurrence of a period in the text, but return -1 if the text doesn’t seem to be a complete sentence.

nemo_voice_agent.pipecat.utils.text.simple_text_aggregator.has_partial_decimal(
text: str
) -> bool

Check if the text ends with a partial decimal.

Returns True if the text ends with a number that looks like it could be a partial decimal (e.g., “3.”, “3.14”, “(3.14)"),butNOTifitsclearlyacompletesentence(e.g.,"Itcosts3.14)"), but NOT if it's clearly a complete sentence (e.g., "It costs 3.14.”) or a bullet point (e.g., “1. Alpha; 2.”).