Dolphin: expose language and region tokens (answering the question left open in #2293)

Author: kuyazeeCreated Aug 28, 2026Updated Sep 25, 2026

Summary

OfflineDolphinModelConfig exposes only model, so there is no way to pin a language or region. This has been asked three times — #2293, #2587, #2963 — and closed each time. In #2293 the answer was:

You need to also export the decoder model to onnx and change the c++ code to add it.

Please list the advantages of adding this feature and the disadvantages of not having this feature.

Nobody answered that question, so this issue answers it with a concrete case and numbers.

The disadvantage of not having it

Without language and region tokens, the CTC branch re-guesses the language on every decode. On short or noisy segments it guesses wrong, and it emits the wrong script.

#2587 reported Arabic recognised as Japanese. I am hitting the same failure in a different pair: a Philippine dialogue app decoding 6-second segments gets Chinese, Japanese and Korean characters inside otherwise Filipino speech. There is no configuration that prevents it, because there is no configuration at all.

The only workaround available to a downstream user is to throw away output whose script is wrong. That works for CJK and fails completely for a wrong guess in the same script — Malay and Indonesian pass straight through a Latin-script filter. Filtering after the fact cannot recover the words the model should have produced.

The advantage of having it

Dolphin's own inference path already takes both tokens:

dolphin audio.wav --lang_sym "zh" --region_sym "CN"

languages.md carries the pairs, including tl/fil with region PH. The paper reports Dolphin base at 16.5% WER on Filipino and 20.4% on Tagalog, small at 10.5% and 15.5%, with the attention decoder and explicit tokens. Those are the numbers that make the model attractive; the CTC branch cannot be asked for them.

Concretely, exporting the decoder would give:

  • Language selection at all for the 40 languages and 22 dialects the model was trained on. Today a multilingual model is usable only where guessing happens to work.
  • A 77 MB on-device model with a real language setting. Among the offline models sherpa-onnx ships, only Whisper accepts a language, and its multilingual weights start at 153 MB for base and 358 MB for small. For languages in Whisper's tail, Dolphin base is both smaller and more accurate.
  • The lang field in the result JSON becomes meaningful. It is currently always empty (noted in #2963), because nothing sets it.

Scope

Understood as two pieces of work, matching the guidance in #2293:

  1. Export Dolphin's attention decoder to ONNX beside the existing model.onnx.
  2. Add language and region to OfflineDolphinModelConfig, prepend the <lang><region> tokens to the decoder prompt, and surface both through the C, C++ and language bindings.

Both tokens are already present in the shipped tokens.txt — <fil>, <tl> and <PH> are all in the vocabulary of sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02. Only the decoder that consumes them is missing.

An intermediate step that would help even without the decoder export: document on the Dolphin pretrained-models page that language selection is unavailable and that the model auto-detects per utterance. Three issues have been filed by people who assumed otherwise from the upstream README.

Environment

  • sherpa_onnx 1.13.6, Flutter/Dart API, Android arm64
  • sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02