speaker_helper.text module
Text segmentation for low-latency streaming synthesis.
Module summary
In streaming mode the time to first audio (TTFA) is dominated by how much text the engine must synthesise before it can emit anything. Splitting a paragraph into sentence-sized units lets speaker-helper synthesise and emit the first unit quickly while later units are still being produced. This module holds the deterministic, dependency-free splitter used for that.
Usage example
>>> from speaker_helper.text import split_sentences
>>> split_sentences("Bonjour. Comment ça va ? Bien !")
['Bonjour.', 'Comment ça va ?', 'Bien !']
- speaker_helper.text.chunk_for_streaming(text, first_chunk_sentences=1)[source]
Group sentences into synthesis chunks, keeping the first one small.
- Parameters:
- Returns:
Chunks of text to synthesise in order. The first chunk holds
first_chunk_sentencessentences; every remaining sentence is its own chunk so downstream audio keeps flowing steadily.- Return type:
Examples
>>> chunk_for_streaming("A. B. C.", first_chunk_sentences=1) ['A.', 'B.', 'C.'] >>> chunk_for_streaming("A. B. C.", first_chunk_sentences=2) ['A. B.', 'C.']
- speaker_helper.text.split_sentences(text)[source]
Split text into sentence-sized, non-empty, stripped units.
- Parameters:
text (str) – Arbitrary text, possibly multi-sentence and multi-line.
- Returns:
Sentences in order, each stripped of surrounding whitespace, with their terminating punctuation preserved. Text without any terminator returns a single-element list (the whole stripped input); empty or whitespace-only input returns an empty list.
- Return type:
Examples
>>> split_sentences("Un. Deux. Trois.") ['Un.', 'Deux.', 'Trois.'] >>> split_sentences("no terminator here") ['no terminator here'] >>> split_sentences(" ") []