Skip to content

sanotts: return word timestamps with the NEON decoder - #1221

Merged
0xShug0 merged 3 commits into
0xShug0:mainfrom
tarelerulz:sanotts-word-timestamps
Nov 7, 2026
Merged

0xShug0 merged 3 commits into
0xShug0:mainfrom
tarelerulz:sanotts-word-timestamps

Conversation

@tarelerulz

Copy link
Copy Markdown
Contributor

Summary

  • The sanoTTS synthesize path reports each token's rounded duration in decoder frames.
  • The session turns those into word spans when return_timestamps is requested, so the NEON decoder (sanotts.cpu_decoder=neon) can serve read-along timing as well as audio.
  • Adds SanoTtsFrontend::symbol_for_id for the token-to-symbol lookup.

Testing

  • Heart voice, one test sentence, NEON decoder on a Raspberry Pi 400 (Cortex-A72, 3 threads): the server returns 22 word spans; the audio matches the GGML decoder output.
  • Not yet built against the current upstream main (this branch is the feature commit cherry-picked onto origin/main at d2da530).

🤖 Generated with Claude Code

Port the duration-based word timestamps onto the NEON decoder branch.
The synthesize path can report each token's frame count, and the session
turns those into word spans when return_timestamps is requested.

Co-Authored-By: Claude Haiku 5.5 <[email protected]>
@0xShug0

0xShug0 commented Nov 6, 2026

Copy link
Copy Markdown
Owner

@tarelerulz Thanks for the PR! Two potential issues found:

(1) Word labels contain phonemes. "Hello world" returns "həlˈO, wˈɜɹld". Is this expected?

(2) Punctuation merges words. "Hello,world!" produces one span because punctuation doesn’t terminate the current word.

Word spans were built from phoneme symbols, so labels read as IPA
("həlˈO"), and punctuation tokens were skipped without ending the current
word, so "Hello,world!" merged into one span.

Labels now come from the chunk text: runs between whitespace and
word-end marks. Phoneme groups (runs between spaces and word-end marks)
pair with them by index. Apostrophes and hyphens stay inside a word.
If the counts disagree, the chunk gets one span labeled with its text
rather than words attached to the wrong audio.

Co-Authored-By: Claude Haiku 5.5 <[email protected]>
@tarelerulz

Copy link
Copy Markdown
Contributor Author

Thanks for catching these. Both are fixed in 979d336 on this branch.

  1. Phonemes in labels: labels now come from the chunk text (runs between whitespace and punctuation), not from the phoneme symbols. Words pair with the phoneme groups by index. If the counts disagree for a chunk, that chunk gets one span labeled with its full text rather than mislabeled words.
  2. Punctuation merging words: , . ! ? ; : ( ), quotes and the em dash now end a word, so "Hello,world!" gives two spans. Apostrophes and hyphens stay inside a word ("don't", "well-known").

Testing: a standalone harness with synthetic token sequences passes 6/6 cases (comma with and without a space, apostrophe/hyphen, dash and curly quotes, count mismatch, empty input), and session.cpp passes a syntax check. I have not yet rebuilt the library and run the Heart voice end to end on the Pi, so the real espeak word grouping is still unverified. I'll run that next and report back here.

Phoneme groups and text words can disagree: espeak merges words with no
space ("was a" -> one group) and splits some words ("$5" -> two groups).
Index pairing then labeled whole sentences as one span.

When the counts differ, each word is phonemized alone and its phonemes
are aligned to the stream's phonemes by edit distance. Frames are spread
over each group's phonemes, so a shared group is split in time. If fewer
than half the phonemes match, the chunk still gets one span.

The word-timestamp helpers move to word_timestamps.{h,cpp}, which take
the symbol lookup and per-word phonemizer as arguments. New unit test
sanotts_word_timestamps_test covers merged, split and poor-match cases.

Tested: unit test passes on Pi and Pixel 9 VM. Heart clips through the
CLI and server: all word labels match the text. Word starts vs the canary
CTC aligner on six clips: 83 words, median |err| 0.048 s, 96% within 0.25 s.

Co-Authored-By: Claude Haiku 5.5 <[email protected]>
@tarelerulz

Copy link
Copy Markdown
Contributor Author

Follow-up on the two issues from earlier. New commit b6a9e812 on this branch.

Fixed

  • Labels are words now, not phonemes. Hello world gives Hello, world.
  • Hello,world! gives two spans.
  • Sentences where espeak merges or splits words (e.g. "was a" with no space, "$5") used to fall back to one span for the whole chunk. Those now get one label per word. A plain English sentence went from 1 span to 18.

What changed: when the phoneme groups and the text words don't line up, each word is pronounced on its own and aligned to the phoneme stream by edit distance. The word helpers moved to word_timestamps.{h,cpp}, with a new unit test sanotts_word_timestamps_test.

Testing

  • Unit test: passes.
  • Heart voice through audiocpp_cli and audiocpp_server (/v1/tasks/run): neon and default decoders give identical spans; timestamps don't change the audio.
  • Pre-fix commit e1bfbcf6 reproduces both original bugs, so the fix is what changed the output.

Timing accuracy: I compared word start times with canary-ctc-aligner (CrispASR) on six clips, using the same text. 83 words matched, median error 0.048 s, 96% within 0.25 s. The outliers are in the long paragraph: "east" is 0.81 s late, "Numbers" 0.48 s. Word ends weren't compared. The reference is another model, not hand-marked truth.

@0xShug0
0xShug0 merged commit 39a2470 into 0xShug0:main Nov 7, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 7, 2026

Copy link
Copy Markdown
Owner

@tarelerulz Thanks! PR merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants