Skip to content

Fix building errors - #2893

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:fix-zipvoice-python
Dec 11, 2025
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:fix-zipvoice-python

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Dec 11, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Refactor

    • Renamed TTS configuration parameter from "pinyin dictionary" to "lexicon" across all language bindings and APIs for improved terminology consistency.
    • Updated ZipVoice model configuration to use the new lexicon field throughout the codebase.
  • Documentation

    • Updated command-line help text and parameter descriptions to reference "lexicon" instead of "pinyin dictionary."

✏️ Tip: You can customize this high-level summary in your review settings.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 11, 2025
@coderabbitai

coderabbitai Bot commented Dec 11, 2025 •

Copy link
Copy Markdown

Walkthrough

A comprehensive field rename across multiple language bindings and implementations, renaming pinyinDict or pinyin_dict to lexicon in the offline TTS Zipvoice model configuration. The change affects FFI bindings, C/C++ API definitions, Python, Go, Swift, WebAssembly implementations, and examples while maintaining consistent naming across all layers.

Changes

Cohort / File(s) Summary
Dart bindings and TTS
flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart, flutter/sherpa_onnx/lib/src/tts.dart
Renamed pinyinDict to lexicon in struct field and class property; updated JSON serialization (fromJson/toJson), constructor initialization, string representation, and FFI binding references throughout.
C API
sherpa-onnx/c-api/c-api.h, sherpa-onnx/c-api/c-api.cc
Renamed public struct field from pinyin_dict to lexicon in SherpaOnnxOfflineTtsZipvoiceModelConfig; updated config mapping to use new field name.
C++ API
sherpa-onnx/c-api/cxx-api.h, sherpa-onnx/c-api/cxx-api.cc
Renamed public member pinyin_dict to lexicon in OfflineTtsZipvoiceModelConfig struct; updated field assignment in OfflineTts::Create.
C++ core config
sherpa-onnx/csrc/offline-tts-zipvoice-model-config.h, sherpa-onnx/csrc/offline-tts-zipvoice-model-config.cc
Removed pinyin_dict field from struct and constructor parameter; removed corresponding command-line option registration for "zipvoice-pinyin-dict".
Go bindings
scripts/go/sherpa_onnx.go
Renamed PinyinDict to Lexicon in OfflineTtsZipvoiceModelConfig; updated all references in NewOfflineTts function.
Python bindings and examples
sherpa-onnx/python/csrc/offline-tts-zipvoice-model-config.cc, python-api-examples/offline-zeroshot-tts.py
Updated pybind11 parameter name and exposed field from pinyin_dict to lexicon; renamed command-line argument --zipvoice-pinyin-dict to --zipvoice-lexicon and updated model configuration usage.
Swift API
swift-api-examples/SherpaOnnx.swift
Renamed function parameter pinyinDict to lexicon and updated field mapping in returned config structure.
WebAssembly
wasm/tts/sherpa-onnx-tts.js, wasm/tts/sherpa-onnx-wasm-main-tts.cc
Replaced all references to pinyinDict/pinyin_dict with lexicon in buffer offset calculations, field assignments, and debug output printing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • Highly consistent and repetitive rename pattern applied uniformly across all files
  • No functional logic changes or control flow modifications
  • Each change is straightforward field name substitution
  • Large file count mitigated by predictable pattern

Areas requiring attention:

  • Verify the C++ config removal (removal of pinyin_dict field and command-line option) doesn't break backward compatibility expectations
  • Confirm WebAssembly buffer offset calculations remain correct after field name substitution
  • Check that Python bindings properly expose the renamed field in documentation/help strings

Possibly related PRs

Suggested labels

size:L

Poem

🐰 A lexicon hops where pinyin once grew,
Through bindings and APIs, the rename rings true.
From C to the Swift, from Python to Go,
Each field finds its new name—a tidy renaming flow! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'Fix building errors' is vague and does not accurately describe the main changes, which involve renaming 'pinyinDict' to 'lexicon' across multiple language bindings and APIs. Use a more specific title that reflects the primary change, such as 'Rename pinyinDict to lexicon in offline TTS zipvoice configuration' or 'Update offline TTS zipvoice API to use lexicon field'
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @csukuangfj, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses and resolves building errors by refactoring the OfflineTtsZipVoiceModelConfig across various language bindings. The core change involves renaming the pinyinDict parameter to lexicon to standardize terminology and improve clarity in text-to-speech configurations. Additionally, the Python example script for offline zero-shot TTS has been updated to align with these changes, including new model paths and example content, ensuring the examples remain functional and up-to-date.

Highlights

  • Unified Terminology for TTS Configuration: The parameter pinyinDict has been consistently renamed to lexicon across all language bindings (Flutter, Go, C/C++, Python, Swift, WASM) for the OfflineTtsZipVoiceModelConfig. This standardizes the terminology for text-to-speech configurations.
  • Updated Python Example Script: The offline-zeroshot-tts.py example script has been updated to reflect the new lexicon parameter name, incorporate new int8 model paths, and provide fresh example audio and text, enhancing its relevance and correctness.
  • Build Error Resolution: The changes, particularly the parameter renaming and associated code adjustments, are intended to fix building errors, ensuring the project compiles and runs correctly across different platforms and language integrations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request primarily refactors the codebase by renaming pinyinDict to lexicon across various files and languages, including Dart, Python, Go, C++, Swift, and JavaScript. This change improves clarity and consistency. The updates have been applied correctly and consistently throughout the project. Additionally, an example in python-api-examples/offline-zeroshot-tts.py has been updated to use a newer model, and some minor style improvements have been made. The changes are well-executed and I don't see any issues.

@csukuangfj
csukuangfj merged commit 1e4ac57 into k2-fsa:master Dec 11, 2025
9 of 27 checks passed
@csukuangfj
csukuangfj deleted the fix-zipvoice-python branch December 11, 2025 11:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
sherpa-onnx/c-api/cxx-api.cc (1)

154-157: Fix loop variable in multi‑stream decode to avoid UB

The loop uses for (int32_t i = 0; i != n; ++n) instead of incrementing i, which can overrun the streams vector or loop indefinitely.

This should be:

-  for (int32_t i = 0; i != n; ++n) {
+  for (int32_t i = 0; i != n; ++i) {
     streams[i] = ss[i].Get();
   }

There is an identical pattern later in KeywordSpotter::Decode(const OfflineStream *ss, int32_t n) that should be corrected the same way.

🧹 Nitpick comments (2)
python-api-examples/offline-zeroshot-tts.py (1)

13-30: Zipvoice example: lexicon flag and config wiring are consistent

  • The usage example, download commands, and CLI invocation all use --zipvoice-lexicon and point to .../lexicon.txt in the new distill-int8-zh-en-emilia model tree (lines 13–30).
  • add_zipvoice_args() defines --zipvoice-lexicon with a matching help string (lines 73–77).
  • OfflineTtsZipvoiceModelConfig is constructed with lexicon=args.zipvoice_lexicon, aligning the example script with the new API surface (lines 236–247).
  • Minor style nit: Ruff flags an ambiguous fullwidth comma in the docstring (RUF002). If you care about lint cleanliness, replace any , with a standard ASCII , in comments/usage text.

Functionally, this script matches the renamed Zipvoice field and updated model bundle paths.

Also applies to: 43-78, 234-247, 272-291

flutter/sherpa_onnx/lib/src/tts.dart (1)

195-252: Dart ZipVoice config: lexicon rename and FFI wiring look correct

  • OfflineTtsZipVoiceModelConfig cleanly introduces lexicon:
    • Included in the ctor with a default of '' (lines 195–207).
    • Parsed from json['lexicon'] in fromJson, emitted as 'lexicon' in toJson, and shown in toString() (lines 209–241).
    • Stored as a final String lexicon field (lines 242–252).
  • The FFI bridge sets c.ref.model.zipvoice.lexicon from config.model.zipvoice.lexicon.toNativeUtf8() and later frees it with calloc.free(c.ref.model.zipvoice.lexicon) (lines 404–409, 430–436, 455–458), mirroring how other lexicon fields (VITS, Matcha, Kokoro) are handled.

This keeps the Dart config, JSON, and native interop in sync with the new lexicon field, with no apparent leaks or mismatches. Just be aware that old JSON using a pinyinDict key will no longer populate this field.

Also applies to: 404-436, 430-458

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b59efd and 912efe2.

📒 Files selected for processing (14)
  • flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart (1 hunks)
  • flutter/sherpa_onnx/lib/src/tts.dart (7 hunks)
  • python-api-examples/offline-zeroshot-tts.py (5 hunks)
  • scripts/go/sherpa_onnx.go (3 hunks)
  • sherpa-onnx/c-api/c-api.cc (2 hunks)
  • sherpa-onnx/c-api/c-api.h (1 hunks)
  • sherpa-onnx/c-api/cxx-api.cc (1 hunks)
  • sherpa-onnx/c-api/cxx-api.h (1 hunks)
  • sherpa-onnx/csrc/offline-tts-zipvoice-model-config.cc (0 hunks)
  • sherpa-onnx/csrc/offline-tts-zipvoice-model-config.h (1 hunks)
  • sherpa-onnx/python/csrc/offline-tts-zipvoice-model-config.cc (1 hunks)
  • swift-api-examples/SherpaOnnx.swift (2 hunks)
  • wasm/tts/sherpa-onnx-tts.js (4 hunks)
  • wasm/tts/sherpa-onnx-wasm-main-tts.cc (1 hunks)
💤 Files with no reviewable changes (1)
  • sherpa-onnx/csrc/offline-tts-zipvoice-model-config.cc
🧰 Additional context used
🧬 Code graph analysis (4)
sherpa-onnx/c-api/c-api.cc (1)
sherpa-onnx/csrc/offline-stream.cc (2)
  • r (257-257)
  • r (257-257)
scripts/go/sherpa_onnx.go (3)
sherpa-onnx/c-api/cxx-api.h (1)
  • OfflineOmnilingualAsrCtcModelConfig (271-273)
sherpa-onnx/csrc/lexicon.cc (4)
  • Lexicon (105-122)
  • Lexicon (125-145)
  • Lexicon (402-405)
  • Lexicon (409-412)
sherpa-onnx/csrc/lexicon.h (1)
  • Lexicon (20-62)
wasm/tts/sherpa-onnx-tts.js (1)
wasm/asr/sherpa-onnx-asr.js (17)
  • lexiconLen (374-374)
  • n (99-99)
  • n (133-133)
  • n (157-157)
  • n (173-173)
  • n (189-189)
  • n (647-647)
  • n (678-678)
  • n (695-695)
  • n (712-712)
  • n (729-729)
  • n (746-746)
  • n (763-763)
  • n (785-785)
  • n (829-829)
  • n (876-877)
  • n (921-921)
swift-api-examples/SherpaOnnx.swift (1)
sherpa-onnx/csrc/kokoro-multi-lang-lexicon.cc (2)
  • lexicon (470-481)
  • lexicon (470-470)
🪛 Ruff (0.14.8)
python-api-examples/offline-zeroshot-tts.py

29-29: Docstring contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?

(RUF002)

🔇 Additional comments (13)
wasm/tts/sherpa-onnx-wasm-main-tts.cc (1)

76-83: Zipvoice lexicon print matches renamed field

The new lexicon line is consistent with other model configs and the underlying zipvoice->lexicon field; no issues.

sherpa-onnx/c-api/c-api.cc (2)

706-713: ys_log_probs export is correctly guarded and owned

Allocating r->ys_log_probs only when result.ys_log_probs is non-empty and matches r->count, and setting it to nullptr otherwise, lines up with the struct definition and destructor and avoids OOB or double-free.


1243-1256: Zipvoice lexicon wiring in OfflineTtsConfig is consistent

Mapping config->model.zipvoice.lexicon into tts_config.model.zipvoice.lexicon with SHERPA_ONNX_OR(..., "") matches the other TTS models’ lexicon handling and the C API struct layout.

sherpa-onnx/python/csrc/offline-tts-zipvoice-model-config.cc (1)

18-36: Python binding now exposes lexicon cleanly

Renaming the ctor parameter and .def_readwrite member to lexicon aligns this pybind surface with the underlying C++ config and other language bindings; no issues.

sherpa-onnx/c-api/cxx-api.h (1)

429-441: C++ Zipvoice model config field rename is layout‑safe

OfflineTtsZipvoiceModelConfig now uses std::string lexicon in the expected slot between data_dir and the float fields, matching the C API struct and other TTS configs. No ABI/layout concerns.

sherpa-onnx/c-api/cxx-api.cc (1)

416-423: Zipvoice lexicon propagation into C API looks correct

Assigning config.model.zipvoice.lexicon.c_str() into c.model.zipvoice.lexicon keeps the C++ wrapper in sync with the C struct and new field name; the whole Zipvoice block is now consistently configured.

sherpa-onnx/c-api/c-api.h (1)

1069-1080: C API Zipvoice struct now exposes lexicon consistently

Adding const char *lexicon between data_dir and the float fields matches the internal config and all bindings; struct size and field order remain compatible with prior layouts.

flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart (1)

217-236: Dart FFI ZipVoice config stays layout‑aligned with C API

The new lexicon pointer is placed between dataDir and the four @Float() fields, matching the native SherpaOnnxOfflineTtsZipvoiceModelConfig layout; this keeps the struct ABI‑compatible while reflecting the renamed field.

If these bindings are not auto‑generated, double‑check against SherpaOnnxOfflineTtsZipvoiceModelConfig in c-api.h after any future changes to avoid drift.

scripts/go/sherpa_onnx.go (2)

474-505: Offline omnilingual ASR config is wired correctly end-to-end

The new Omnilingual OfflineOmnilingualAsrCtcModelConfig field is properly threaded through:

  • Added to OfflineModelConfig (line 487) so it’s part of the public Go config.
  • newCOfflineRecognizerConfig populates c.model_config.omnilingual.model from config.ModelConfig.Omnilingual.Model (line 591).
  • freeCOfflineRecognizerConfig frees c.model_config.omnilingual.model symmetrically (lines 745–748).

This matches the existing patterns for other offline model configs and should be safe from leaks or missed initialization.

Also applies to: 547-592, 628-748


962-975: Zipvoice lexicon field is correctly added to Go config and C bridge

For the Zipvoice TTS model:

  • OfflineTtsZipvoiceModelConfig gains a Lexicon string field with a clear comment (lines 962–974).
  • NewOfflineTts now sets c.model.zipvoice.lexicon from config.Model.Zipvoice.Lexicon and defers C.free on the allocated C string (lines 1151–1152).

This keeps the Go API aligned with the C++ OfflineTtsZipvoiceModelConfig lexicon field and follows the same allocation/free pattern as the existing VITS/Matcha/Kokoro lexicon fields. No correctness or lifetime issues apparent.

Also applies to: 1151-1157

wasm/tts/sherpa-onnx-tts.js (1)

265-276: ZipVoice WASM config: lexicon field and struct layout look consistent

  • lexiconLen is computed and included in the total buffer size n (lines 272, 275).
  • Lexicon is written after dataDir into the contiguous buffer, and the string offset is advanced accordingly (lines 299–301).
  • Pointer layout (len = 10 * 4) correctly reflects 6 string pointers (tokens, textModel, flowMatchingModel, vocoder, dataDir, lexicon) followed by 4 floats (featScale, tShift, targetRMS, guidanceScale), with the lexicon pointer at ptr + 20 (lines 279–324).
  • Default offlineTtsZipVoiceModelConfig now includes lexicon: '' so callers that omit it won’t hit undefined access (lines 377–390).

This matches the expected C struct shape for Zipvoice and should fix the previous mismatch without introducing alignment or bounds issues.

Also applies to: 299-301, 318-325, 377-390

sherpa-onnx/csrc/offline-tts-zipvoice-model-config.h (1)

15-47: C++ Zipvoice model config now cleanly exposes lexicon

  • The struct member lexicon (line 22) replaces the old pinyin_dict and is included in both the ctor parameters and initializer list (lines 31–46).
  • Parameter ordering matches member ordering: tokens, text_model, flow_matching_model, vocoder, data_dir, lexicon, feat_scale, t_shift, target_rms, guidance_scale, preserving ABI layout.
  • Float defaults in the ctor match the in-class member defaults, so existing call sites that relied on defaults remain valid.

The rename is internally consistent and should just require downstream users to access lexicon instead of pinyin_dict.

swift-api-examples/SherpaOnnx.swift (1)

930-954: Swift Zipvoice helper correctly switched to lexicon

  • The helper’s signature now exposes lexicon: String = "" instead of the previous pinyin dict parameter (line 936).
  • The C-bridge call forwards this via the named lexicon: field (line 948), keeping the argument order unchanged for the other parameters.

This keeps the Swift convenience API aligned with the C++/C lexicon field without introducing ABI or call-site issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant