word_count

Spoken-word counting for transcripts that may omit spaces.

pipecat.utils.text.word_count.count_spoken_words(text: str) → int[source]

Count spoken words, treating each Chinese or Japanese character as a word.

Whitespace-separated tokens count as one word, the same as str.split. Chinese and Japanese are written without spaces between words, so each ideograph, hiragana, or katakana character inside a token counts as one word. Punctuation in that token does not. A run of other characters in the same token, such as a Latin word or a number, still counts as one word.

Parameters:

text – Transcript or reply text.

Returns:

The number of spoken words.