Repository navigation
sense_asr: return word timestamps from CTC emission frames - #1236
Merged
Merged
Conversation
SenseVoice decodes with greedy CTC, and since 0xShug0#1214 its decoding goes through CtcHostDecoder, which already reports each token's frame span. Those spans were dropped after text decoding. Keep them and, when the request sets return_timestamps (or the CLI gets --words-out), return them as word timestamps. - Encoder output frames start with the query-token prefix (language, event, emotion, ITN); drop it, then convert at one LFR frame (frame_shift_ms * lfr_n = 60 ms) to the input's sample rate. - Chinese, Japanese kana and Thai give one entry per character; other scripts join SentencePiece pieces into words at the boundary marker. Punctuation joins the preceding word without extending its time; language/event/emotion tags are skipped. - Chunked offline runs and streaming windows shift times to the whole input. - Times are token emission frames, as for GigaAM and Granite, not a forced alignment: starts track onsets, ends fall at the last emission. The default path is unchanged: without return_timestamps no words are built and transcripts are identical. The spec gains the word_timestamps capability and the return_timestamps request option, so the C API's audiocpp_model_supports_timestamps() now reports 1 for sense_asr; no C ABI declarations change. Grouping and frame conversion live in sense_asr/word_timestamps.h, covered by the new sense_asr_word_timestamps_test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Streaming windows are final once decoded, but each window republished the whole word list through publish_transcript(), so every stream event carried all words so far. On a 167 s clip with 2 s windows the events held 19,857 words for a 479-word transcript, growing quadratically with stream length, and a caller appending event words got duplicates. Use append_transcript() with only the window's text delta and words, as other finalized-segment streams do. The transcript is joined exactly as before, and the session no longer keeps its own copy of the words. Also make the word-boundary marker a constexpr string_view. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
Metal validation for the PR head ( Setup: Apple M2 Pro, macOS, AppleClang 21. Built with the repo's scripts/build_metal.sh --build-dir build-metal --build-type Release \
--model-set custom --models "sense_asr,nemotron_3_diar" --with-tests \
--target audiocpp_cli --target sense_asr_word_timestamps_test \
--target ctc_host_decoder_test --target model_spec_system_testUnit tests: CPU vs. Metal: the same requests ran with
The one difference in the 167 s clip is capitalization: CPU gives |
Owner
|
@jiabochao Thanks! PR merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in word timestamps to
sense_asr(SenseVoice-Small).SenseVoice decodes with greedy CTC. Since #1214 that decoding goes through
CtcHostDecoder, which already reports each token's frame span, butsense_asrdropped the spans after building the text. This PR keeps the spans and, whenreturn_timestamps=trueis set, returns them asword_timestamps. The CLI sets that option automatically for--words-out. The approach matches GigaAM and Granite, which also derive word times from CTC emission frames.My use case is meeting transcription: matching SenseVoice text against
nemotron_3_diarspeaker turns, word by word. Validation for that is below.Changes
sense_asr/word_timestamps.h(new, model-local):▁marker.<|...|>tags are skipped.frame_shift_ms × lfr_n), converted at the input's sample rate.session.cpp: keeps the decoder spans. Chunked offline runs (vad,fixed,auto) and streaming windows shift the times to the whole input.append_transcript()with only its new text and words, the pattern finalized-segment streams use. Each stream event carries only that window's words; the final result has all of them.model_specs/sense_asr.json: adds theword_timestampscapability and thereturn_timestampsrequest option.sense_asr_word_timestamps_test, plus docs indocs/models/sense_asr.md,docs/asr.mdand the README model row.Compatibility
return_timestamps, no words are built. Transcripts with the option on and off are byte-identical; see the measurements below.audiocpp_result_word*functions. Because the spec now declaresword_timestamps,audiocpp_model_supports_timestamps()returns 1 forsense_asr.text/chunking.cpp(is_cjk_letter,is_cjk_punctuation_delimiter) are file-local. To keep this PR model-local,word_timestamps.hhas its own small script and punctuation checks. I can follow up with a framework PR that exports and shares them, if you prefer.Validation
Environment:
main@408935bsensevoice-small-q8-audiocpp-v1.gguf(FunAudioLLM/SenseVoiceSmall-GGUF-audiocpp, sha2564dedf169…)zh,yue,jaanden(FunAudioLLM/SenseVoiceSmall/example/*.mp3, resampled to 16 kHz mono), plusassets/resources/sample_16k.wavandfour_speaker_short.wavBuild:
Run:
Output
Checks
zhwith 3.0 s of leading silencezh+0.02 s,yue−0.17 s,ja−0.03 szh,en,yueandjajoined with 0.3 s gaps (26.1 s), run withaudio_chunk_modenone,vad,fixed(7 s) and--mode streaming(7 s windows)audiocpp_stream_push→ event words; 167 s clip, 2 s and 5 s windows)audiocpp_stream_finishreturns: 476 of 479 and 480 of 487. At most 9 and 20 words per event. No duplicates.audio_chunk_mode=vad, 3 runs each)Downstream use: speaker-attributed transcripts with
nemotron_3_diar(Q8)Each word was assigned to the diarization turn that contains its start time.
zh→yue→ja→zh→yue(3 speakers return, 0.4 s gaps)four_speaker_short.wavfour_speaker_short.txt.vibevoice_two_speaker_longform.wav(167 s)Known limitations
confidenceis 0, as in GigaAM.🤖 Generated with Claude Code