Skip to content

Fix various language bindings - #3166

Merged
csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:fix-api-bindings
Feb 10, 2026
Merged

csukuangfj merged 1 commit into
k2-fsa:masterfrom
csukuangfj:fix-api-bindings

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Feb 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Whisper models now support token-level and segment-level timestamp generation options for improved temporal precision
    • FunASR Nano models now support language configuration, inverse text normalization, and hotwords capability for enhanced customization

@csukuangfj
csukuangfj requested a review from Copilot February 10, 2026 03:23
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 10, 2026
@coderabbitai

coderabbitai Bot commented Feb 10, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR extends offline ASR model configuration across multiple language bindings and C++ core. It adds timestamp flags (enable_token_timestamps, enable_segment_timestamps) to Whisper model config and language customization fields (language, itn, hotwords) to FunASR Nano model config. Changes include field declarations, constructor updates, C struct mappings, and memory cleanup.

Changes

Cohort / File(s) Summary
C++ Core Config Parsing
harmony-os/.../non-streaming-asr.cc, sherpa-onnx/jni/offline-recognizer.cc
Extended offline model config parsing to populate new Whisper timestamp fields (enable_token_timestamps, enable_segment_timestamps) and FunASR Nano fields (language, itn, hotwords). Updated FreeConfig to clean up newly added string fields.
Go Language Binding
scripts/go/sherpa_onnx.go
Added EnableTokenTimestamps and EnableSegmentTimestamps to OfflineWhisperModelConfig; added Language, UseInverseTextNormalization, and Hotwords to OfflineFunASRNanoModelConfig. Updated newCOfflineRecognizerConfig and freeCOfflineRecognizerConfig to map and clean up the new fields.
Java Language Binding
sherpa-onnx/java-api/.../OfflineWhisperModelConfig.java
Added enableTokenTimestamps and enableSegmentTimestamps boolean fields with getters and builder setter methods; both default to false.
Kotlin Language Binding
sherpa-onnx/kotlin-api/OfflineRecognizer.kt
Added enableTokenTimestamps and enableSegmentTimestamps properties to OfflineWhisperModelConfig data class, both defaulting to false.
Pascal Language Binding
sherpa-onnx/pascal-api/sherpa_onnx.pas
Added Language and UseItn fields to TSherpaOnnxOfflineFunAsrNanoModelConfig; added EnableTokenTimestamps and EnableSegmentTimestamps to TSherpaOnnxOfflineWhisperModelConfig. Updated ToString and config conversion logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Whisper speaks with timestamps true,
FunASR learns what hotwords do,
Language fields bloom across the bindings,
From C++ core to Java's findings! ✨
Config grows as models take their flight,
Speech recognition, shining bright! 🎤

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix various language bindings' accurately describes the pull request, which adds configuration fields across multiple language bindings (Go, Java, Kotlin, Pascal) and C++ code.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 significantly enhances the configuration capabilities for both FunASR Nano and Whisper models by introducing new parameters related to language, text normalization, hotwords, and timestamp generation. These changes are propagated across multiple language bindings, including Go, Java, Kotlin, and Pascal, to ensure that developers using these languages can leverage the expanded functionality. The update aims to provide greater flexibility and control over the automatic speech recognition process.

Highlights

  • Enhanced FunASR Nano Model Configuration: Added support for language, inverse text normalization (ITN), and hotwords parameters to the FunASR Nano model configuration across C++, Go, and Pascal bindings, allowing for more fine-grained control over transcription.
  • Extended Whisper Model Configuration: Introduced enable token timestamps and enable segment timestamps parameters for the Whisper model configuration in C++, Go, Java, Kotlin, and Pascal bindings, providing more detailed timing information in transcription results.
  • Cross-Language Binding Updates: Updated the Go, Java, Kotlin, and Pascal APIs to expose these new configuration options, ensuring consistency and feature parity across different language integrations.
  • Memory Management Improvements: Implemented necessary memory deallocation for new string-based configuration parameters in the C++ core and Go bindings to prevent memory leaks.
Changelog
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/non-streaming-asr.cc
    • Added language, itn, and hotwords attributes to SherpaOnnxOfflineFunASRNanoModelConfig.
    • Added enable_token_timestamps and enable_segment_timestamps attributes to SherpaOnnxOfflineWhisperModelConfig.
    • Ensured proper memory deallocation for new funasr_nano string attributes in FreeConfig.
  • scripts/go/sherpa_onnx.go
    • Added EnableTokenTimestamps and EnableSegmentTimestamps fields to OfflineWhisperModelConfig struct.
    • Added Language, UseInverseTextNormalization, and Hotwords fields to OfflineFunASRNanoModelConfig struct.
    • Mapped new Whisper configuration fields from Go to C.
    • Mapped new FunASR Nano configuration fields from Go to C.
    • Added new FunASR Nano string fields to the C string freeing mechanism.
    • Refactored ToBuffer function with explicit curly braces for an if statement.
  • sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineWhisperModelConfig.java
    • Added enableTokenTimestamps and enableSegmentTimestamps fields to OfflineWhisperModelConfig class and its constructor.
    • Provided getter methods for enableTokenTimestamps and enableSegmentTimestamps.
    • Added setter methods for enableTokenTimestamps and enableSegmentTimestamps in the Builder class.
  • sherpa-onnx/jni/offline-recognizer.cc
    • Implemented JNI reading for enable_token_timestamps and enable_segment_timestamps for Whisper model configuration.
  • sherpa-onnx/kotlin-api/OfflineRecognizer.kt
    • Added enableTokenTimestamps and enableSegmentTimestamps properties to OfflineWhisperModelConfig data class.
  • sherpa-onnx/pascal-api/sherpa_onnx.pas
    • Added Language, UseItn, and Hotwords fields to TSherpaOnnxOfflineFunAsrNanoModelConfig record.
    • Added EnableTokenTimestamps and EnableSegmentTimestamps fields to TSherpaOnnxOfflineWhisperModelConfig record.
    • Updated C-compatible structs with new FunASR Nano and Whisper configuration fields.
    • Extended ToString methods for FunASR Nano and Whisper configs to include new parameters.
    • Mapped new Whisper configuration fields from Pascal to C.
    • Mapped new FunASR Nano configuration fields from Pascal to C.
    • Initialized UseItn to False in TSherpaOnnxOfflineFunAsrNanoModelConfig initialization.
    • Initialized EnableTokenTimestamps and EnableSegmentTimestamps to False in TSherpaOnnxOfflineWhisperModelConfig initialization.
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 correctly adds new configuration options for the FunASR Nano and Whisper models. The changes are consistently propagated across various language bindings, including C++ for HarmonyOS, Go, Java, Kotlin, and Pascal. The new fields are properly handled in data structures, configuration parsing, and memory management. The code is clean and I found no issues.

@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.

Caution

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

⚠️ Outside diff range comments (1)
sherpa-onnx/pascal-api/sherpa_onnx.pas (1)

2238-2245: ⚠️ Potential issue | 🟡 Minor

Change Pascal default for UseItn to True to align with other language bindings.

All other bindings (C++, Java, Kotlin, Python) default itn to true. The Pascal implementation at line 2244 currently sets UseItn := False, creating an inconsistency across the API surface. Update it to match the standard default.

Fix
-  Dest.UseItn := False;
+  Dest.UseItn := True;

@csukuangfj
csukuangfj merged commit 2ea8c9a into k2-fsa:master Feb 10, 2026
3 checks passed
@csukuangfj
csukuangfj deleted the fix-api-bindings branch February 10, 2026 03:36

Copilot AI 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.

Pull request overview

This PR updates multiple language bindings to expose newly added offline model configuration options (Whisper timestamp toggles; FunASR Nano language/ITN/hotwords) so they can be set consistently across supported SDKs.

Changes:

  • Pascal API: add FunASR Nano Language/UseItn/Hotwords and Whisper EnableTokenTimestamps/EnableSegmentTimestamps, including ToString, defaults, and C-struct conversion.
  • JVM/JNI APIs: add Whisper timestamp flags in Kotlin + Java, and plumb them through JNI to the native config.
  • Go + HarmonyOS bindings: add the same fields and wire them into C config conversion/freeing.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sherpa-onnx/pascal-api/sherpa_onnx.pas Adds new config fields for FunASR Nano + Whisper and converts them into the C config struct.
sherpa-onnx/kotlin-api/OfflineRecognizer.kt Exposes Whisper timestamp toggles in Kotlin config.
sherpa-onnx/jni/offline-recognizer.cc Reads Whisper timestamp toggles from Kotlin config into native config.
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineWhisperModelConfig.java Adds Whisper timestamp toggles to the Java builder/config object.
scripts/go/sherpa_onnx.go Adds new config fields to Go binding and wires them into C config creation/freeing; minor formatting tweak in ToBuffer().
harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/non-streaming-asr.cc Adds FunASR Nano + Whisper fields for HarmonyOS config parsing and frees newly allocated strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/go/sherpa_onnx.go
Comment on lines 1493 to 1494
fs := C.SherpaOnnxWaveFileSize(C.int(n)) // SHERPA_ONNX_API int64_t SherpaOnnxWaveFileSize(int32_t n_samples);
buf := make([]byte, fs)

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

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

fs is a C.int64_t (from SherpaOnnxWaveFileSize) but it is passed directly to make([]byte, fs), which requires an int length. This will not compile with Go; convert fs to int (with a range check to avoid overflow on 32-bit platforms) before allocating the buffer.

Suggested change
fs := C.SherpaOnnxWaveFileSize(C.int(n)) // SHERPA_ONNX_API int64_t SherpaOnnxWaveFileSize(int32_t n_samples);
buf := make([]byte, fs)
fsC := C.SherpaOnnxWaveFileSize(C.int(n)) // SHERPA_ONNX_API int64_t SherpaOnnxWaveFileSize(int32_t n_samples);
if fsC <= 0 {
return nil
}
fs := int64(fsC)
maxInt := int64(^uint(0) >> 1)
if fs > maxInt {
// Avoid integer overflow when converting to int (especially on 32-bit platforms).
return nil
}
bufLen := int(fs)
buf := make([]byte, bufLen)

Copilot uses AI. Check for mistakes.
Comment thread scripts/go/sherpa_onnx.go
@@ -1472,10 +1484,12 @@ func (audio *GeneratedAudio) Save(filename string) bool {
}

Copilot AI Feb 10, 2026

Copy link

Choose a reason for hiding this comment

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

Save() can panic when audio.Samples is empty because it takes &audio.Samples[0] earlier in the function. Consider adding a len(audio.Samples)==0 guard (returning false) to match the defensive check used in ToBuffer().

Copilot uses AI. Check for mistakes.
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.

2 participants