Page MenuHomePhabricator

Add word-level timestamps in TTS prototype
Closed, ResolvedPublic

Description

In the ML<>Apps sync, the Apps team mentioned that it would be useful to have a follow-along reading experience while audio is playing:

In ML<>Apps sync, @JTannerWMF mentioned:

Ideally we also have the text on the screen like captions (ie. “follow along”); this is not a hard requirement for the early iterations but is pretty important later on

To support this, we are going to add word-level timestamps so that the spoken audio can be synchronized with the corresponding text in a way that is compatible with standard web caption formats such as W3C WebVTT.

Event Timeline

We have added word-level timestamps to the TTS prototype. Each audio section (.mp3) now comes with a companion WebVTT caption file (.vtt) with per-word start and end times:

EndpointPurposeResponses
https://wiki-tts.toolforge.org/audio/Earth/Lead.mp3Serving of .mp3 (existed)HTTP 200 if .mp3 exists, HTTP 404 if .mp3 doesn't exist on disk
https://wiki-tts.toolforge.org/audio/Earth/Lead.vttServing of .vtt (new)HTTP 200 if .vtt exists, HTTP 404 if .vtt doesn't exist on disk

The caption files are produced alongside the audio during the existing audio generation pipeline. They can be consumed directly from the static URL path (same base URL as the .mp3, just with a .vtt extension).

We have also added a demo of this feature in the TTS prototype UI. Now when you play a section's audio, the transcript below the audio player highlights each spoken word in real-time so that you can follow-along:

Sharing this from slack for posterity:

In #text-to-speech-models on slack, @Dbrant wrote:

Terrific! Just for my own understanding - the caption data  is available because the Kokoro model supports outputting it, correct? I just want to be careful that we don't start locking ourselves into using Kokoro specifically, since the eventual goal is to move to using larger AI-based models like VibeVoice.

In #text-to-speech-models on slack, @kevinbazira wrote:

the caption data actually doesn't come from Kokoro at all, it's generated by a separate Wav2Vec2-CTC forced alignment model that runs as a post-processing step after the audio is produced. here's the flow:

  1. Kokoro generates the raw audio (24kHz waveform)
  2. Wav2Vec2-CTC takes that audio + the original text, and independently computes word-level timestamps via CTC alignment.

this means the caption feature is completely decoupled from the TTS engine. swapping Kokoro for VibeVoice (or any other model) will work seamlessly i.e as long as VibeVoice outputs audio and we know its sample rate, we can resample it to Wav2Vec2's expected 16kHz input and align it against the text. no changes to the alignment pipeline needed!

NOTE: Before we added caption generation, the prototype was only generating .mp3 files in an already resource-constrained Toolforge environment (T419288#11948239). With .vtt now being generated alongside .mp3 using the same hosting resources, the overall audio generation speed and serving throughput for the pipeline are now slower. This is an expected limitation for the Toolforge prototype and will be resolved when we migrate the compute-heavy inference to LiftWing's dedicated GPU infrastructure in V1.