String

pipecat.utils.string.replace_match(text, match, old, new)[source]

Replace occurrences of a substring within a matched section of a given text.

Parameters:
  • text (str) – The input text in which replacements will be made.

  • match (re.Match) – A regex match object representing the section of text to modify.

  • old (str) – The substring to be replaced.

  • new (str) – The substring to replace old with.

Returns:

The modified text with the specified replacements made within the matched section.

Return type:

str

pipecat.utils.string.match_endofsentence(text)[source]

Finds the position of the end of a sentence in the provided text string.

This function processes the input text by replacing periods in email addresses and numbers with ampersands to prevent them from being misidentified as sentence terminals. It then searches for the end of a sentence using a specified regex pattern.

Parameters:

text (str) – The input text in which to find the end of the sentence.

Returns:

The position of the end of the sentence if found, otherwise 0.

Return type:

int

pipecat.utils.string.parse_start_end_tags(text, tags, current_tag, current_tag_index)[source]

Parses the given text to identify a pair of start/end tags.

If a start tag was previously found (i.e. current_tags is valid), wait for the corresponding end tag. Otherwise, wait for a start tag.

This function will return the index in the text that we should start parsing in the next call and the current or new tags.

Parameters: - text (str): The text to be parsed. - tags (Sequence[StartEndTags]): List of tuples containing start and end tags. - current_tags (Optional[StartEndTags]): The currently active tags, if any. - current_tags_index (int): The current index in the text.

Returns: Tuple[Optional[StartEndTags], int]: A tuple containing None or the current tag and the index of the text.

Parameters:
  • text (str)

  • tags (Sequence[Tuple[str, str]])

  • current_tag (Tuple[str, str] | None)

  • current_tag_index (int)

Return type:

Tuple[Tuple[str, str] | None, int]