Skip to content

fix: scale Qwen3 forced aligner timestamps to the input sample rate (#1147) - #1148

Merged
0xShug0 merged 3 commits into
0xShug0:mainfrom
m-abs:fix/1147-qwen3-aligner-timestamp-sample-rate
Oct 31, 2026
Merged

0xShug0 merged 3 commits into
0xShug0:mainfrom
m-abs:fix/1147-qwen3-aligner-timestamp-sample-rate

Conversation

@m-abs

@m-abs m-abs commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

parse_timestamps converted the model's millisecond predictions with
assets_->config.sample_rate (16 kHz), while audio_frames, the clamp
bounds and the JSON seconds all live in the uploaded audio's sample
domain.
Every span was compressed by model_rate/input_rate: on a 24 kHz take
the last word landed at 27.89 s instead of 41.84 s, and
clamp_timestamps_to_audio became a no-op because the compressed spans
never reach audio_frames.
Pass request.audio_input->sample_rate, the same rescale the MMS forced
aligner and the ASR chunk merge already do.

Adds a processor unit test pinning the sample-domain contract:
2000 ms is 48000 samples at 24 kHz, and the zero-length-span repair
and clamp bounds use that rate. Verified on a 42 s 24 kHz take, mean
sentence-boundary error against ground truth drops from 8557 ms to 30 ms,
identical to the 16 kHz run.

Fixes #1147

…xShug0#1147)

parse_timestamps converted the model's millisecond predictions with
assets_->config.sample_rate (16 kHz), while audio_frames, the clamp
bounds and the JSON seconds all live in the uploaded audio's sample
domain.
Every span was compressed by model_rate/input_rate: on a 24 kHz take
the last word landed at 27.89 s instead of 41.84 s, and
clamp_timestamps_to_audio became a no-op because the compressed spans
never reach audio_frames.
Pass request.audio_input->sample_rate, the same rescale the MMS forced
aligner and the ASR chunk merge already do.

Adds a processor unit test pinning the sample-domain contract:
2000 ms is 48000 samples at 24 kHz, and the zero-length-span repair
and clamp bounds use that rate. Verified on a 42 s 24 kHz take, mean
sentence-boundary error against ground truth drops from 8557 ms to 30 ms,
identical to the 16 kHz run.
@0xShug0

0xShug0 commented Oct 31, 2026

Copy link
Copy Markdown
Owner

@m-abs Thanks! Could you also update the Qwen3 ASR integration in this PR? The aligner now returns timestamps in the input sample rate, but ASR’s chunk merger still expects 16 kHz positions. Please convert timestamps back to 16 kHz in the ASR caller before merging.

E.g.,

48-second, 24 kHz WAV
Qwen3-ASR-1.7B plus Qwen3 ForcedAligner
audio_chunk_mode=fixed
audio_chunk_duration_sec=12
return_timestamps=true

Main 162 words → PR: 111 words

…xShug0#1147)

The aligner now returns word spans in the uploaded audio's sample domain,
but the Qwen3 ASR chunk loop still told append_chunk_word_timestamps() that
the timestamps were at assets_->config.sample_rate (16 kHz). The merge then
scaled every span by 24000/16000 before testing it against the keep window,
so words past two thirds of each chunk fell outside it and were dropped.

On a 42 s 24 kHz take with fixed 12 s chunks: 66 of 105 words survived, the
last kept word ending at 28.0 s instead of 41.88 s. Passing audio.sample_rate
keeps all 105, and the merged spans stay in the domain the JSON seconds are
computed from, so no extra conversion is needed.

Same correction in the outetts reference alignment, which handed the aligner
the model rate instead of the audio rate; align_reference() no longer needs
the aligner assets, so the unused parameter is dropped.

Adds a chunking unit test: 24 kHz audio, four 12 s chunks, eight words,
out-of-window spans dropped and in-window spans left untouched. Verified on
the 42 s 24 kHz take: 105 words, last word at 41.88 s, matching the 16 kHz
run.
@m-abs

m-abs commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Could you also update the Qwen3 ASR integration in this PR?

Of course.

Please convert timestamps back to 16 kHz in the ASR caller before merging.

My bot disagreed with that solution and recommended this solution instead.

This is its explanation:


What was happening

append_chunk_word_timestamps() is already rate-aware: it interprets the incoming
word spans in timestamp_sample_rate and rescales the chunk's source_span /
keep_span into that same domain before the keep-window test.

The Qwen3 ASR loop passed assets_->config.sample_rate (16 kHz) for that argument
while the aligner — after #1147 — emits spans in the uploaded audio's domain. For a
24 kHz take with 12 s chunks:

  • timestamp_source_span = 288000 * 16000/24000 = 192000 samples
  • every aligner span past 8 s of the chunk is clamped to local_end = 192000, so
    local_start >= local_end and the word is dropped ("dropping word timestamp
    outside chunk span")
  • the survivors get global_start = timestamp_source_span.start_sample + local_start,
    i.e. samples in the 16 kHz domain

That explains both halves of your number: 162 → 111 words (only the first two thirds
of each chunk survive), and the surviving timestamps are 2/3 of their true length, so
the reported seconds are wrong even when the count is right.

Why I didn't convert back to 16 kHz in the caller

Three reasons, in order of weight:

  1. The output has to be in the audio domain. merged.word_timestamps is the
    final result: clamp_timestamps_to_audio, the JSON start_seconds/end_seconds
    and subtitle.cpp all divide by the input rate. Converting the spans to 16 kHz
    before merging means they must be converted back afterwards, or Bug: Qwen3 forced aligner reports word timestamps in a 16 kHz sample frame regardless of the input sample rate #1147 reappears in
    the chunked path. Passing the real rate makes the rescale a no-op and the output
    is already correct.
  2. The round-trip is lossy. rescale_time_span is integer multiply/divide.
    24 kHz → 16 kHz → 24 kHz quantises every span (e.g. 100 samples → 66 → 99); at
    44.1 kHz it's worse. Word selection is identical either way, so the conversion
    buys nothing but rounding error.
  3. There is no second consumer of 16 kHz positions. The only reason the caller
    knew about 16 kHz at all was this argument.

Net change is four arguments — two merges and the two diagnostics calls — and the
diagnostic line now reports the truth (timestamp_sample_rate=24000) instead of the
assumption.

Verification

42.06 s, 24 kHz WAV, Qwen3-ASR-1.7B q8_0 + ForcedAligner-0.6B f16,
audio_chunk_mode=fixed, audio_chunk_duration_sec=12, return_timestamps=true:

state words kept last word reported end sample actual time
PR as merged (merger at 16 kHz) 66 boat 673027 28.0 s — the tail of the file is gone
011d2215 105 harbor 1005120 41.88 s ✅
main (16 kHz aligner + 16 kHz merger) 105 harbor 670080 27.9 s ❌ — same instant, wrong domain

Per-chunk merged_delta in the broken state: 17/22/19/8 = 66; after the fix: 17/22/19/12 = 105. The transcript text is identical in all three runs, so the loss is purely timestamp-driven. Your 48 s case matches the arithmetic: 162 × 2/3 ≈
111.

Also touched

src/community_models/outetts/session.cpp had the same assumption in the reference
alignment — it returned aligner_assets.config.sample_rate as the alignment rate.
Now it returns audio.sample_rate; align_reference() no longer needs the aligner
assets, so that parameter is gone.

Test

test_chunk_word_timestamp_merge_keeps_input_rate_domain in
tests/unittests/test_audio_chunking.cpp: 24 kHz audio, four 12 s chunks, eight
words, asserts out-of-window spans are dropped and in-window spans are left
untouched — i.e. that the merge does not silently rescale.


Passing audio.sample_rate as both source and timestamp rate is the identity
rescale, and the chunker already has an overload without rate arguments for
spans that are already in the uploaded audio's sample domain. Behaviour is
unchanged: 105 words on the 42 s 24 kHz take, last word at 41.88 s.
@m-abs

m-abs commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

I pushed another small change.

engine::audio::append_chunk_word_timestamps(...) was called with the same audio.sample_rate twice.

@0xShug0
0xShug0 merged commit bd02977 into 0xShug0:main Oct 31, 2026
6 of 7 checks passed
@0xShug0

0xShug0 commented Oct 31, 2026

Copy link
Copy Markdown
Owner

@m-abs Thanks! Yes your solution is better. PR merged!

@m-abs
m-abs deleted the fix/1147-qwen3-aligner-timestamp-sample-rate branch October 31, 2026 19:48
delebash added a commit to delebash/audio.cpp that referenced this pull request Nov 6, 2026
Conflicts: the Qwen3 aligner's sample rate — upstream's fix (0xShug0#1148) is ours, so its two
files are upstream's again; Qwen3-TTS's CustomVoice base assets kept beside upstream's talker
backend; our CustomVoice clone test under upstream's ENGINE_BUILD_MODEL_TESTS (0xShug0#1182).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PFJ4wux8AZfMeuyaL63Fca
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.

Bug: Qwen3 forced aligner reports word timestamps in a 16 kHz sample frame regardless of the input sample rate

2 participants