word_timestamp_tracker
Timestamps for the words a TTS service speaks.
- class pipecat.utils.context.word_timestamp_tracker.WordTimestamp(word: str, timestamp: float, context_id: str | None, includes_inter_frame_spaces: bool = False)[source]
Bases:
objectA word a TTS provider reported, and when it is spoken.
- Parameters:
word – The word.
timestamp – Seconds from the start of the word’s audio.
context_id – The audio context the word belongs to.
includes_inter_frame_spaces – Whether the word carries its own spacing.
- class pipecat.utils.context.word_timestamp_tracker.WordTimestampTracker[source]
Bases:
objectTurns word times reported from the start of their audio into PTS.
Timing starts when a context’s audio starts playing, or after the last word if that is later, so words keep their order across contexts. Words reported before then are cached and handed back by
start().last_ptsis the PTS of the last word frame, anduninterruptible_last_ptsthat of the last uninterruptible one.reply_last_ptsis that of the last word sincestart_reply().- property reply_last_pts: int | None
The PTS of the reply’s last word, or
Noneif the reply timed no words.
- start_reply()[source]
Note where a reply’s words start, for
reply_last_pts.
- start(now: int) list[WordTimestamp][source]
Start timing words, if not started yet.
- Parameters:
now – The current clock time, in nanoseconds.
- Returns:
The words cached until now, to time in order.
- cache(word: WordTimestamp)[source]
Hold a word until timing starts.
- Parameters:
word – The word reported before timing started.