Skip to content

Add CTC word timestamps to Granite Speech 5.0 TurboCTC - #903

Merged
0xShug0 merged 3 commits into
0xShug0:mainfrom
bradmurray-dt:granite5asr-ctc-word-timestamps
Oct 14, 2026
Merged

0xShug0 merged 3 commits into
0xShug0:mainfrom
bradmurray-dt:granite5asr-ctc-word-timestamps

Conversation

@bradmurray-dt

@bradmurray-dt bradmurray-dt commented Oct 14, 2026 •

Copy link
Copy Markdown

Summary

  • Granite Speech 5.0 TurboCTC now fills word_timestamps for offline run and streaming finish_stream. supports_timestamps is true in the loader, inspect path, and load_granite5asr_model, and the model spec advertises word_timestamps.
  • Transcript text for a given waveform is unchanged. Words come from collapsed CTC pieces: a token ends at the next different label, including blank, and a word runs from its first subword piece through its last. confidence is the geometric mean of the greedy-class probability on the non-blank frames of that word.
  • Frame positions are converted from the frontend's 16 kHz clock to the input buffer's sample rate. With fixed or VAD chunking, each word's sample indexes are offset by its chunk start, and its end is clamped to the end of its chunk, so a word cannot run into the next chunk.
  • Streaming still returns one final result. Words are attached there only. The server JSON and C API are unchanged.

Test plan

Machine: Apple M4 Pro, macOS. Model: ibm-granite/granite-speech-5.0-470m-turboctc (safetensors snapshot, package id granite5asr_safetensors). Audio: assets/asr_validation/librispeech/librispeech_test_clean_6930-75918-0000.wav (16 kHz mono, 56080 samples).

cmake -S . -B build/macos-metal-release -G "Unix Makefiles" \
  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
  -DENGINE_ENABLE_CUDA=OFF -DENGINE_ENABLE_VULKAN=OFF -DENGINE_ENABLE_METAL=ON \
  -DENGINE_ENABLE_OPENMP=OFF -DENGINE_ENABLE_LLAMAFILE=ON -DENGINE_ENABLE_NATIVE_CPU=ON \
  -DGGML_OPENMP=OFF -DGGML_METAL_EMBED_LIBRARY=ON \
  -DENGINE_BUILD_TESTS=ON -DENGINE_BUILD_MODEL_TESTS=ON \
  -DENGINE_BUILD_EXAMPLES=OFF -DENGINE_BUILD_WARMBENCH=OFF \
  -DAUDIOCPP_DEPLOYMENT_BUILD=OFF -DAUDIOCPP_BUILD_NATIVE_MODEL_MANAGER=OFF \
  -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS=granite5asr

cmake --build build/macos-metal-release --target \
  granite5asr_ctc_timestamps_test test_granite5asr_golden_transcription model_spec_system_test

ctest --test-dir build/macos-metal-release \
  -R 'granite5asr_ctc_timestamps_test|model_spec_system_test' --output-on-failure

for b in cpu metal; do
  ./build/macos-metal-release/bin/test_granite5asr_golden_transcription \
    --model <granite5asr safetensors snapshot> --backend $b
done

The golden test runs offline, offline with 1 s fixed chunks (--chunk-seconds, default 1), and streaming in 512-sample chunks. For each run it checks that words are non-empty, do not overlap, stay inside the buffer, and join to the normalized transcript. The offline and streaming transcripts must also match the expected text.

Results, identical on --backend cpu and --backend metal:

Run Transcript First word Last word
offline concord returned to its place amidst the tents concord 0–14080 tents 44800–46080
fixed 1 s chunks concord return to its place place amidstst the10 s concord 0–12800 s 48000–49280
streaming concord returned to its place amidst the tents concord 0–14080 tents 44800–46080
  • granite5asr_ctc_timestamps_test and model_spec_system_test passed.
  • Indexes increase and stay inside the clip in every run.
  • Fixed chunks at 0.5, 0.7, 0.9, 1.1, 1.3, and 1.7 s also passed the word checks. The 1 s chunked text is worse because the chunks are far shorter than the 30 s default; that comes from the existing chunking, not from this change.
  • Without the checkpoint and wav, test_granite5asr_golden_transcription exits 125.

Limits

  • The frame is 80 ms, so word boundaries are only as precise as one frame at any input rate. Indexes are samples of the input buffer at its own rate (checked at 8, 16, and 48 kHz).
  • Confidence is the greedy-class probability, not a marginal CTC probability. A piece with a non-positive frame probability makes that word's confidence 0.
  • A repeated non-blank label occupies every frame of that run.
  • Blanks between subword pieces of one word are inside the word's time span and outside its confidence.
  • Streaming words arrive on the final result only.

bradmurray-dt and others added 2 commits October 14, 2026 09:38
Word spans and greedy-class confidence now follow the encoder clock, while the transcript text stays the same.

Co-authored-by: Cursor <[email protected]>
…reaming runs

Word ends are limited to the clip they came from, so fixed and VAD chunks cannot produce words that run into the next chunk. The golden test now also checks a fixed-chunk run and a streaming run, and takes --backend and --chunk-seconds.

Co-authored-by: Cursor <[email protected]>
@0xShug0

0xShug0 commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

@bradmurray-dt Thanks for adding this missing path! One minor issue to fix then the PR is ready to merge.

The frontend resamples to 16 kHz, but the timestamps combine that clock with offsets and buffer lengths from the original sample rate.

Test input: librispeech_test_clean_6930-75918-0000.wav --- “Concord returned to its place amidst the tents.”

Input Rate Last Word tents Result
16 kHz [44800,46080) Correct clock
48 kHz [44800,46080) Three times too early in input samples
8 kHz [44800,44801) Outside the 28040-sample buffer

Relevent commit for fixing a similar issue #167: 622cadd

The frontend resamples to 16 kHz, so CTC frame positions are converted to the input buffer's sample rate before chunk offsets and the chunk-end clamp are applied. The golden test now checks 48 kHz and 8 kHz input against the 16 kHz word times.

Co-authored-by: Cursor <[email protected]>
@bradmurray-dt

Copy link
Copy Markdown
Author

Thanks for catching this. Fixed in 3ebf477.

The frontend resamples each clip to 16 kHz, so CTC frame positions are on the 16 kHz clock. Each frame position is now converted to the input buffer's sample rate before the chunk offset and the chunk-end clamp are applied, following the rescale pattern in 622cadd. Nothing new is resampled and no rates are rejected; only the reported indexes change.

Same clip, offline, --backend cpu and --backend metal (identical results):

Input rate Buffer samples Last word tents Seconds
16 kHz 56080 [44800, 46080) 2.80–2.88 s
48 kHz 168240 [134400, 138240) 2.80–2.88 s
8 kHz 28040 [22400, 23040) 2.80–2.88 s

test_granite5asr_golden_transcription now resamples the clip to 48 kHz and 8 kHz and requires the first and last words to match the 16 kHz times within one 80 ms frame, and every word to stay inside that rate's buffer, both for a single clip and for 1 s fixed chunks. granite5asr_ctc_timestamps_test covers the frame-to-sample conversion at 48 kHz and 8 kHz, including the 8 kHz end clamp.

@0xShug0
0xShug0 merged commit 571c92c into 0xShug0:main Oct 14, 2026
6 checks passed
@0xShug0

0xShug0 commented Oct 14, 2026

Copy link
Copy Markdown
Owner

@bradmurray-dt Thanks and PR merged! A follow-up PR addressing the timestamp inconsistency between streaming and offline would be appreciated. Currently, offline timestamps use the input sample rate, while streaming timestamps always use 16 kHz.

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