Skip to content

OmniVoice: match Python duration weights for Bengali marks, danda and digits - #1110

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
kawshikbuet17:omnivoice
Oct 27, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
kawshikbuet17:omnivoice

Conversation

@kawshikbuet17

Copy link
Copy Markdown
Contributor

Summary

OmniVoice's duration estimator (char_weight() in src/models/omnivoice/prompt_builder.cpp) gives Bengali combining marks and punctuation different weights from the reference Python implementation (RuleDurationEstimator in k2-fsa/OmniVoice). As a result, audio.cpp picks a different number of target frames for Bengali text, and the speech comes out noticeably too fast or too slow. This PR makes the Bengali weights match Python.

Problem

Python decides each character's weight from its Unicode category. char_weight() only treats the Latin combining-mark blocks as marks, so every Bengali code point (U+0980–U+09FF) falls into the indic range and gets 1.8:

Character type Examples Python audio.cpp (before)
Vowel signs, hasanta, candrabindu/anusvara/visarga, nukta া ি ী ু ে ো ্ ঁ ং ঃ ় 0 (mark) 1.8
Danda / double danda । ॥ 0.5 (punctuation) 1.8
Bengali digits ০–৯ 3.5 (digit) 1.8
Bengali currency / symbols ৳ ৺ 0.5 (punctuation) 1.8

The estimate is target_weight / ref_weight × ref_frames, so the error does not cancel out. It depends on how many marks the target and reference each contain, and it can go either way. Without a reference voice, the fallback reference is English and is not inflated, so Bengali output is always too long.

Fix

Inside char_weight(), just before the script-range lookup, classify Bengali-block marks, punctuation/symbols and digits (plus U+0964/U+0965 dandas) using the same categories as Python's unicodedata (Unicode 13.0). Bengali letters are unchanged (still 1.8). No other scripts are affected.

Results

Same model, text, reference audio and settings in Python OmniVoice and audio.cpp:

Case Python frames audio.cpp before audio.cpp after
Long sentence, voice clone 514 453 (−12%) 514
Short sentence, voice clone 124 118 124
Short sentence, no reference 117 174 (+49%) 117

For the long sentence, the output WAV goes from 18.17 s to 20.76 s, matching Python's 20.76 s.

Testing

  • Compared target frame counts with Python OmniVoice on the cases above (CUDA, RTX 4090).
  • Text and reference audio tokens were confirmed identical between the two implementations, so the only change in output is the frame count. The generated audio still differs in fine detail because the samplers use different RNGs (torch vs std::mt19937), as before.

… digits

The duration estimator's char_weight() only treated Latin combining-mark
blocks as marks, so every Bengali code point fell into the "indic" range
and weighed 1.8. Python's RuleDurationEstimator classifies by Unicode
category instead: vowel signs, hasanta, candrabindu/anusvara/visarga and
nukta are marks (0), danda/double danda and Bengali currency/symbols are
punctuation (0.5), Bengali digits are digits (3.5).

The mismatch made audio.cpp pick a different number of target frames for
Bengali text, so speech came out too fast or too slow depending on the
mark density of the target vs. the reference text. Examples (same model,
text and reference):

  long sentence, clone:  Python 514 frames, audio.cpp 453 -> now 514
  short sentence, clone: Python 124 frames, audio.cpp 118 -> now 124
  short sentence, auto:  Python 117 frames, audio.cpp 174 -> now 117

Code points are taken from Python's unicodedata (Unicode 13.0).
@0xShug0
0xShug0 merged commit 8d336a2 into 0xShug0:main Oct 27, 2026
7 checks passed
@0xShug0

0xShug0 commented Oct 27, 2026

Copy link
Copy Markdown
Owner

@kawshikbuet17 Good catch! 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