Skip to content

omnivoice: size automatic long-form chunks in code points, not bytes - #1108

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
linyqh:omnivoice-cjk-chunk-size
Oct 27, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
linyqh:omnivoice-cjk-chunk-size

Conversation

@linyqh

@linyqh linyqh commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Symptom

Chinese (and other CJK) text longer than audio_chunk_threshold_sec (30 s) is split into chunks about three times larger than audio_chunk_duration_sec (15 s). A ~220-character Chinese paragraph (~35 s) is not split at all. The model then generates 35–45 s in one pass. The output has long pauses inside phrases, words split in the middle, and in the auto-voice case whole clauses dropped or garbled toward the end. This may be related to #842.

Cause

The automatic path in OmniVoiceSession computes

avg_tokens_per_char = target_audio_tokens / prompt.text.size();
text_chunk_size = audio_chunk_duration_sec * frame_rate / avg_tokens_per_char;

prompt.text.size() is the UTF-8 byte length. chunk_text_punctuation then measures text_chunk_size in code points. For ASCII the two are equal. For CJK each character is 3 bytes, so the chunk budget comes out 3x too large. Upstream Python uses len(text), which counts characters.

Fix

Use engine::text::utf8_codepoint_count for the per-character rate, in both the offline path (run) and the streaming path (plan_text_chunks). There is no other change. ASCII input is unaffected by construction, and text at or under the 30 s threshold never reaches this code.

Validation

Apple M5, macOS 27.0.1, Metal. omnivoice-f16.gguf from audio-cpp/audio.cpp-gguf, seed 7, default 32 steps. "Before" is upstream main 950b5db4 and "after" is this branch; both builds are identical apart from this commit.

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENGINE_ENABLE_METAL=ON -DENGINE_ENABLE_OPENMP=OFF -DGGML_OPENMP=OFF \
  -DGGML_METAL_EMBED_LIBRARY=ON -DAUDIOCPP_MODEL_SET=custom "-DAUDIOCPP_MODELS=omnivoice;qwen3_forced_aligner"
cmake --build build --target audiocpp_cli
build/bin/audiocpp_cli --task tts --family omnivoice --model omnivoice-f16.gguf --backend metal \
  --text "<text>" --seed 7 --out out.wav --log-file trace.log   # clone runs add --voice-ref assets/resources/b.wav --reference-text "<b.wav transcript>"

Texts: a 309-character Chinese narration paragraph (281 Han characters), its first 80 characters (under the 30 s threshold), and a 633-character English paragraph (over the threshold). The chunk sizes come from the omnivoice.text_chunk_size / omnivoice.text_chunk_count trace keys. CER uses Qwen3-ASR-1.7B Q8 on Han characters only. "Mid-phrase pauses" are gaps of at least 150 ms between consecutive Qwen3-ForcedAligner words with no punctuation between them.

Case Chunk size (count) before → after Duration CER before → after Mid-phrase pauses (max) before → after
zh long, auto voice 228 (2) → 76 (5) 56.8 s → 61.1 s 25.27% → 0.36% 10 (1120 ms) → 2 (400 ms)
zh long, clone b.wav 138 (3) → 46 (8) 96.3 s → 98.9 s 5.34% → 0.71% 26 (1840 ms) → 13 (1760 ms)
zh short (< 30 s) not chunked — — WAV byte-identical
en long (> 30 s) 251 (3) → 251 (3) — — WAV byte-identical

In the auto-voice "before" run, the second chunk drops about 60 of 281 characters and garbles the end (e.g. 教他怎样风向怎样,在浪头之间。). After the fix every character is read.

The clone case uses the English reference speaker for Chinese text, so it is slow (about 3 characters per second) and still has some long pauses after the fix. The improvement there shows mainly in CER.

I also reproduced this on v0.9.2 (0097d365) with a Chinese voice-clone reference and a 417-character paragraph. Chunks went from 227 to 96 characters. Mid-phrase pauses dropped from 17 (longest 1.92 s) to 5 (longest 320 ms). Paragraphs under the threshold were byte-identical.

git diff --check passes. Not tested: CUDA, Vulkan, CPU. The change only touches host-side integer arithmetic before generation, with no backend code involved.

The automatic chunk size divided target audio tokens by the UTF-8 byte
length while chunk_text_punctuation counts code points, so CJK chunks
came out about 3x the intended 15 s (e.g. a 222-character Chinese
paragraph of ~35 s was never split). Long single passes produced
mid-phrase pauses. Fixed in both offline and streaming paths.
@linyqh
linyqh force-pushed the omnivoice-cjk-chunk-size branch from 9e8a5d6 to 622195f Compare October 27, 2026 03:46
@0xShug0
0xShug0 merged commit 0bf8577 into 0xShug0:main Oct 27, 2026
7 checks passed
@0xShug0

0xShug0 commented Oct 27, 2026

Copy link
Copy Markdown
Owner

@linyqh Thanks for the fix! 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