Repository navigation
Add Kotlin and Java API for FunASR Nano models - #3030
Conversation
|
Warning Rate limit exceeded@csukuangfj has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 16 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds comprehensive FunASR Nano offline recognition support across Java and Kotlin APIs, including new model configuration classes, JNI parsing logic, build infrastructure, example programs, and workflow integration to enable non-streaming decoding of WAV files using the FunASR Nano model. Changes
Sequence Diagram(s)sequenceDiagram
participant App as Java/Kotlin App
participant API as Sherpa-onnx API
participant JNI as JNI Layer
participant Native as Native C++
participant Model as FunASR Nano Model
App->>API: Create OfflineFunAsrNanoModelConfig<br/>(with encoder, LLM, embedding paths)
API->>API: Build OfflineModelConfig<br/>(funasrNano field set)
API->>API: Create OfflineRecognizer
API->>JNI: Call JNI with config
JNI->>Native: GetOfflineConfig parses<br/>funasr_nano fields
Native->>Native: Initialize FunASR Nano model<br/>(encoder adaptor, LLM, embedding)
App->>API: Load WAV file & create input stream
App->>API: Feed waveform data
API->>JNI: Invoke recognition
JNI->>Native: Run offline recognition
Native->>Model: Decode with FunASR Nano
Model-->>Native: Return result
Native-->>JNI: Return recognized text
JNI-->>API: Return to caller
API-->>App: Retrieve & print result
App->>API: Release resources
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
Summary of ChangesHello @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 expands the project's capabilities by integrating the FunASR Nano automatic speech recognition models into its Java and Kotlin APIs. It provides developers with new, dedicated configuration options and clear examples for performing non-streaming audio decoding. The changes ensure seamless model loading and execution across these platforms, enhancing the project's support for advanced speech processing tasks. Highlights
Ignored Files
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds support for FunASR Nano models to the Java and Kotlin APIs. The changes are well-structured and follow existing patterns. I've provided some suggestions to improve the example code for robustness and flexibility, mainly concerning resource management with try-finally blocks to prevent leaks, and parameterizing hardcoded file paths. I've also pointed out some areas in the Kotlin example where more idiomatic and safer code can be used. The accompanying shell scripts have also been reviewed with suggestions for better maintainability.
| OfflineRecognizer recognizer = new OfflineRecognizer(config); | ||
| OfflineStream stream = recognizer.createStream(); | ||
| stream.acceptWaveform(reader.getSamples(), reader.getSampleRate()); | ||
|
|
||
| recognizer.decode(stream); | ||
|
|
||
| String text = recognizer.getResult(stream).getText(); | ||
|
|
||
| System.out.printf("filename:%s\nresult:%s\n", waveFilename, text); | ||
|
|
||
| stream.release(); | ||
| recognizer.release(); |
There was a problem hiding this comment.
There's a potential resource leak here. If an exception occurs after recognizer and stream are created but before release() is called, these resources will not be cleaned up. It's safer to use a try-finally block to ensure release() is always called.
OfflineRecognizer recognizer = null;
OfflineStream stream = null;
try {
recognizer = new OfflineRecognizer(config);
stream = recognizer.createStream();
stream.acceptWaveform(reader.getSamples(), reader.getSampleRate());
recognizer.decode(stream);
String text = recognizer.getResult(stream).getText();
System.out.printf("filename:%s\nresult:%s\n", waveFilename, text);
} finally {
if (stream != null) {
stream.release();
}
if (recognizer != null) {
recognizer.release();
}
}| var stream = recognizer.createStream() | ||
| stream.acceptWaveform(samples, sampleRate=sampleRate) | ||
| recognizer.decode(stream) | ||
|
|
||
| var result = recognizer.getResult(stream) | ||
| println(result) | ||
|
|
||
| stream.release() | ||
| recognizer.release() |
There was a problem hiding this comment.
There's a potential resource leak if an exception occurs. Using a try-finally block ensures stream and recognizer are always released. Also, stream and result are not reassigned and can be declared with val.
val stream = recognizer.createStream()
try {
stream.acceptWaveform(samples, sampleRate=sampleRate)
recognizer.decode(stream)
val result = recognizer.getResult(stream)
println(result)
} finally {
stream.release()
recognizer.release()
}| String encoderAdaptor = "./sherpa-onnx-funasr-nano-int8-2025-12-30/encoder_adaptor.int8.onnx"; | ||
| String llm = "./sherpa-onnx-funasr-nano-int8-2025-12-30/llm.int8.onnx"; | ||
| String embedding = "./sherpa-onnx-funasr-nano-int8-2025-12-30/embedding.int8.onnx"; | ||
| String tokenizer = "./sherpa-onnx-funasr-nano-int8-2025-12-30/Qwen3-0.6B"; | ||
|
|
||
| String tokens = ""; | ||
|
|
||
| String waveFilename = "./sherpa-onnx-funasr-nano-int8-2025-12-30/test_wavs/lyrics.wav"; |
There was a problem hiding this comment.
The file paths for the model and the wave file are hardcoded. This makes the example less flexible. Consider passing these paths as command-line arguments.
| String encoderAdaptor = "./sherpa-onnx-funasr-nano-int8-2025-12-30/encoder_adaptor.int8.onnx"; | |
| String llm = "./sherpa-onnx-funasr-nano-int8-2025-12-30/llm.int8.onnx"; | |
| String embedding = "./sherpa-onnx-funasr-nano-int8-2025-12-30/embedding.int8.onnx"; | |
| String tokenizer = "./sherpa-onnx-funasr-nano-int8-2025-12-30/Qwen3-0.6B"; | |
| String tokens = ""; | |
| String waveFilename = "./sherpa-onnx-funasr-nano-int8-2025-12-30/test_wavs/lyrics.wav"; | |
| if (args.length != 5) { | |
| System.err.println("Usage: java NonStreamingDecodeFileFunAsrNano <encoder_adaptor.onnx> <llm.onnx> <embedding.onnx> <tokenizer_dir> <wave_file>"); | |
| System.exit(1); | |
| } | |
| String encoderAdaptor = args[0]; | |
| String llm = args[1]; | |
| String embedding = args[2]; | |
| String tokenizer = args[3]; | |
| String tokens = ""; | |
| String waveFilename = args[4]; |
| if [ ! -f ../sherpa-onnx/java-api/build/sherpa-onnx.jar ]; then | ||
| pushd ../sherpa-onnx/java-api | ||
| make | ||
| popd | ||
| fi | ||
|
|
||
| if [ ! -f ./sherpa-onnx-funasr-nano-int8-2025-12-30/embedding.int8.onnx ]; then | ||
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| tar xvf sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| rm sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| fi | ||
|
|
||
| java \ | ||
| -Djava.library.path=$PWD/../build/lib \ | ||
| -cp ../sherpa-onnx/java-api/build/sherpa-onnx.jar \ | ||
| NonStreamingDecodeFileFunAsrNano.java |
There was a problem hiding this comment.
This script can be improved for better readability and maintainability:
- Use a variable for the model directory to avoid repetition.
- Use
[[instead of[for consistency with the rest of the script. - If the Java example is updated to accept command-line arguments, this script should be updated to pass them.
MODEL_DIR=sherpa-onnx-funasr-nano-int8-2025-12-30
if [[ ! -f ../sherpa-onnx/java-api/build/sherpa-onnx.jar ]]; then
pushd ../sherpa-onnx/java-api
make
popd
fi
if [[ ! -f ./$MODEL_DIR/embedding.int8.onnx ]]; then
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/$MODEL_DIR.tar.bz2
tar xvf $MODEL_DIR.tar.bz2
rm $MODEL_DIR.tar.bz2
fi
java \
-Djava.library.path=$PWD/../build/lib \
-cp ../sherpa-onnx/java-api/build/sherpa-onnx.jar \
NonStreamingDecodeFileFunAsrNano.java \
./$MODEL_DIR/encoder_adaptor.int8.onnx \
./$MODEL_DIR/llm.int8.onnx \
./$MODEL_DIR/embedding.int8.onnx \
./$MODEL_DIR/Qwen3-0.6B \
./$MODEL_DIR/test_wavs/lyrics.wav| if [ ! -f ./sherpa-onnx-funasr-nano-int8-2025-12-30/embedding.int8.onnx ]; then | ||
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| tar xvf sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | ||
| rm sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 |
There was a problem hiding this comment.
The model directory name sherpa-onnx-funasr-nano-int8-2025-12-30 is used multiple times. It's good practice to store it in a variable to improve readability and make it easier to update in the future.
| if [ ! -f ./sherpa-onnx-funasr-nano-int8-2025-12-30/embedding.int8.onnx ]; then | |
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | |
| tar xvf sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | |
| rm sherpa-onnx-funasr-nano-int8-2025-12-30.tar.bz2 | |
| local model_dir=sherpa-onnx-funasr-nano-int8-2025-12-30 | |
| if [ ! -f ./$model_dir/embedding.int8.onnx ]; then | |
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/$model_dir.tar.bz2 | |
| tar xvf $model_dir.tar.bz2 | |
| rm $model_dir.tar.bz2 |
| faked-asset-manager.kt | ||
|
|
||
| ls -lh $out_filename | ||
| java -Djava.library.path=../build/lib -jar $out_filename |
There was a problem hiding this comment.
If test_offline_funasr_nano.kt is updated to accept the wave file path as a command-line argument, this line should be updated to pass it.
| java -Djava.library.path=../build/lib -jar $out_filename | |
| java -Djava.library.path=../build/lib -jar $out_filename ./sherpa-onnx-funasr-nano-int8-2025-12-30/test_wavs/lyrics.wav |
| fun main() { | ||
| val recognizer = createOfflineRecognizer() | ||
| val waveFilename = "./sherpa-onnx-funasr-nano-int8-2025-12-30/test_wavs/lyrics.wav" |
There was a problem hiding this comment.
The main function can be updated to accept the wave file path from command-line arguments. This makes the example more flexible and reusable.
| fun main() { | |
| val recognizer = createOfflineRecognizer() | |
| val waveFilename = "./sherpa-onnx-funasr-nano-int8-2025-12-30/test_wavs/lyrics.wav" | |
| fun main(args: Array<String>) { | |
| if (args.isEmpty()) { | |
| println("Usage: please provide a wave file") | |
| return | |
| } | |
| val recognizer = createOfflineRecognizer() | |
| val waveFilename = args[0] |
| val samples: FloatArray = objArray[0] as FloatArray | ||
| val sampleRate: Int = objArray[1] as Int |
There was a problem hiding this comment.
The unchecked cast as can throw a ClassCastException if the types returned from WaveReader.readWaveFromFile are not what's expected. For more robust code, consider using a safe cast as? with an elvis operator ?: to throw a more informative exception, or using require to validate the types before casting.
| val samples: FloatArray = objArray[0] as FloatArray | |
| val sampleRate: Int = objArray[1] as Int | |
| require(objArray.size == 2) { "Expected 2 elements from readWaveFromFile" } | |
| val samples = objArray[0] as? FloatArray ?: error("Element 0 is not a FloatArray") | |
| val sampleRate = objArray[1] as? Int ?: error("Element 1 is not an Int") |
|
|
||
| fun createOfflineRecognizer(): OfflineRecognizer { | ||
| val config = OfflineRecognizerConfig( | ||
| modelConfig = getOfflineModelConfig(type = 46)!!, |
There was a problem hiding this comment.
Using the non-null assertion operator !! is generally discouraged as it can lead to NullPointerExceptions at runtime. It's safer to handle the potential null case explicitly, for example by using the elvis operator ?: to throw a more descriptive exception.
modelConfig = getOfflineModelConfig(type = 46) ?: error("Failed to get model config for type 46"),There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In @java-api-examples/run-non-streaming-decode-file-funasr-nano.sh:
- Around line 34-37: The script incorrectly passes the source file name
NonStreamingDecodeFileFunAsrNano.java to the java launcher (source-file mode)
while the project targets Java 1.8; instead, compile the example with javac
first and then invoke the class by its simple name. Update the run command to
(1) run javac on NonStreamingDecodeFileFunAsrNano.java (ensuring the classpath
includes ../sherpa-onnx/java-api/build/sherpa-onnx.jar), and (2) invoke java
with -Djava.library.path pointing to ../build/lib and -cp including both the jar
and the current directory, calling NonStreamingDecodeFileFunAsrNano (no .java).
Apply the same fix to all scripts in java-api-examples/.
In
@sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineFunAsrNanoModelConfig.java:
- Around line 32-66: The class OfflineFunAsrNanoModelConfig is missing a getter
for the tokenizer field: add a public String getTokenizer() method that returns
the tokenizer field so JNI/config consumers can read it; locate the tokenizer
field and its existing setter setTokenizer(...) and implement the matching
getter in the same style as getEncoderAdaptor()/getLLM() to maintain
consistency.
🧹 Nitpick comments (1)
kotlin-api-examples/test_offline_funasr_nano.kt (1)
25-31: Consider safer null handling for test robustness.Using
!!ongetOfflineModelConfig(type = 46)will throw a NullPointerException if the type is not found. For test code, this is acceptable as it will clearly fail, but you could userequireNotNull()for a more descriptive error message.♻️ Optional: Use requireNotNull for clearer error messages
fun createOfflineRecognizer(): OfflineRecognizer { val config = OfflineRecognizerConfig( - modelConfig = getOfflineModelConfig(type = 46)!!, + modelConfig = requireNotNull(getOfflineModelConfig(type = 46)) { "Model type 46 (FunASR Nano) not found" }, ) return OfflineRecognizer(config = config) }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
.github/workflows/run-java-test.yamljava-api-examples/NonStreamingDecodeFileFunAsrNano.javajava-api-examples/run-non-streaming-decode-file-funasr-nano.shkotlin-api-examples/run.shkotlin-api-examples/test_offline_funasr_nano.ktscripts/apk/generate-vad-asr-apk-script.pysherpa-onnx/java-api/Makefilesherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineFunAsrNanoModelConfig.javasherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.javasherpa-onnx/jni/offline-recognizer.ccsherpa-onnx/kotlin-api/OfflineRecognizer.kt
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-06T04:18:47.981Z
Learnt from: litongjava
Repo: k2-fsa/sherpa-onnx PR: 2440
File: sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/core/Core.java:4-6
Timestamp: 2025-08-06T04:18:47.981Z
Learning: In sherpa-onnx Java API, the native library names in Core.java (WIN_NATIVE_LIBRARY_NAME = "sherpa-onnx-jni.dll", UNIX_NATIVE_LIBRARY_NAME = "libsherpa-onnx-jni.so", MACOS_NATIVE_LIBRARY_NAME = "libsherpa-onnx-jni.dylib") are copied directly from the compiled binary filenames and should not be changed to match other libraries' naming conventions.
Applied to files:
sherpa-onnx/java-api/Makefilejava-api-examples/run-non-streaming-decode-file-funasr-nano.shsherpa-onnx/jni/offline-recognizer.cc
📚 Learning: 2025-08-06T04:23:50.237Z
Learnt from: litongjava
Repo: k2-fsa/sherpa-onnx PR: 2440
File: sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/core/Core.java:4-6
Timestamp: 2025-08-06T04:23:50.237Z
Learning: The sherpa-onnx JNI library files are stored in Hugging Face repository at https://huggingface.co/csukuangfj/sherpa-onnx-libs under versioned directories like jni/1.12.7/, and the actual Windows JNI library filename is "sherpa-onnx-jni.dll" as defined in Core.java constants.
Applied to files:
sherpa-onnx/java-api/Makefilejava-api-examples/run-non-streaming-decode-file-funasr-nano.shsherpa-onnx/jni/offline-recognizer.cc
🧬 Code graph analysis (6)
sherpa-onnx/kotlin-api/OfflineRecognizer.kt (4)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineFunAsrNanoModelConfig.java (1)
OfflineFunAsrNanoModelConfig(3-134)sherpa-onnx/c-api/cxx-api.h (1)
OfflineModelConfig(299-324)scripts/go/sherpa_onnx.go (1)
OfflineModelConfig(491-524)scripts/dotnet/OfflineModelConfig.cs (1)
OfflineModelConfig(11-35)
java-api-examples/NonStreamingDecodeFileFunAsrNano.java (2)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineFunAsrNanoModelConfig.java (1)
OfflineFunAsrNanoModelConfig(3-134)sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.java (1)
OfflineModelConfig(5-281)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineFunAsrNanoModelConfig.java (1)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.java (1)
Builder(143-280)
sherpa-onnx/jni/offline-recognizer.cc (2)
sherpa-onnx/kotlin-api/OfflineRecognizer.kt (1)
encoderAdaptor(53-64)android/SherpaOnnxSimulateStreamingAsr/app/src/main/java/com/k2fsa/sherpa/onnx/OfflineRecognizer.kt (1)
encoderAdaptor(53-64)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.java (1)
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineFunAsrNanoModelConfig.java (1)
OfflineFunAsrNanoModelConfig(3-134)
scripts/apk/generate-vad-asr-apk-script.py (6)
scripts/apk/generate-asr-2pass-apk-script.py (1)
Model(27-43)scripts/apk/generate-qnn-vad-asr-apk-script.py (1)
Model(28-47)scripts/wasm/generate-vad-asr.py (1)
Model(27-32)scripts/apk/generate-asr-apk-script.py (1)
Model(27-44)scripts/lazarus/generate-subtitles.py (1)
Model(28-32)scripts/hap/generate-vad-asr-hap-script.py (1)
Model(28-48)
🔇 Additional comments (12)
scripts/apk/generate-vad-asr-apk-script.py (1)
780-795: The new FunASR Nano model entry (idx=46) is correctly structured and properly mapped.The model definition follows the established pattern with sequential idx values (44 → 45 → 46), and the cmd block with pushd/rm/ls/popd sequence matches other entries. Cross-file verification confirms idx=46 is properly mapped to
OfflineFunAsrNanoModelConfigin the Kotlin API (OfflineRecognizer.ktline 786) and test files, with model paths consistent across all implementations.sherpa-onnx/java-api/Makefile (1)
43-43: LGTM!The new
OfflineFunAsrNanoModelConfig.javais correctly added to the compilation list, following the established pattern for model configuration files..github/workflows/run-java-test.yaml (1)
111-116: LGTM!The new FunASR Nano test step follows the established workflow pattern, including proper cleanup of model files after the test.
sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.java (1)
18-18: LGTM!The
funasrNanofield, getter, and builder methods are correctly implemented following the established pattern used by other model configurations in this class.Also applies to: 42-42, 103-106, 156-156, 211-214
kotlin-api-examples/run.sh (2)
540-560: LGTM!The
testOfflineFunAsrNanofunction correctly follows the established pattern for model testing:
- Downloads model archive if not present
- Compiles the Kotlin test with all required dependencies
- Runs the test jar with the JNI library path
586-586: LGTM!The test function is appropriately placed in the test sequence after
testVersion.sherpa-onnx/jni/offline-recognizer.cc (1)
270-309: LGTM!The JNI parsing for FunASR Nano configuration is correctly implemented, following the established pattern used by other model configurations. All 10 fields are properly read using the appropriate macros (
SHERPA_ONNX_JNI_READ_STRING,SHERPA_ONNX_JNI_READ_INT,SHERPA_ONNX_JNI_READ_FLOAT), and the C++ struct fields match exactly.java-api-examples/NonStreamingDecodeFileFunAsrNano.java (1)
1-58: LGTM!The example correctly demonstrates FunASR Nano usage following the existing patterns in the codebase. The resource handling is appropriate with
stream.release()andrecognizer.release()at the end.sherpa-onnx/kotlin-api/OfflineRecognizer.kt (3)
53-64: LGTM!The
OfflineFunAsrNanoModelConfigdata class is well-defined with sensible defaults that match the Java counterpart. The field names and default values are consistent across both APIs.
114-114: LGTM!The
funasrNanofield is properly added toOfflineModelConfigwith a default instance, consistent with the pattern used for other model configurations.
786-797: LGTM!The case 46 implementation correctly configures the FunASR Nano model with appropriate paths. Using an empty
tokensstring is intentional since this model uses a tokenizer directory path instead.sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineFunAsrNanoModelConfig.java (1)
68-133: LGTM!The Builder class follows the established pattern with appropriate default values that are consistent with the Kotlin API counterpart. The fluent setter pattern is correctly implemented.
| java \ | ||
| -Djava.library.path=$PWD/../build/lib \ | ||
| -cp ../sherpa-onnx/java-api/build/sherpa-onnx.jar \ | ||
| NonStreamingDecodeFileFunAsrNano.java |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# First, let's look at the actual script to see the full context
cat -n java-api-examples/run-non-streaming-decode-file-funasr-nano.shRepository: k2-fsa/sherpa-onnx
Length of output: 1339
🏁 Script executed:
#!/bin/bash
# Check other similar scripts to understand the pattern
find java-api-examples -name "*.sh" -type f | head -10Repository: k2-fsa/sherpa-onnx
Length of output: 651
🏁 Script executed:
#!/bin/bash
# Search for Java execution patterns in all shell scripts
rg '^\s*java\s' java-api-examples/ -A 2 -B 2 | head -60Repository: k2-fsa/sherpa-onnx
Length of output: 3841
🏁 Script executed:
#!/bin/bash
# Check for Java version requirements in common config files
find . -maxdepth 2 -type f \( -name "README*" -o -name "pom.xml" -o -name "build.gradle" -o -name ".github" \) | head -20Repository: k2-fsa/sherpa-onnx
Length of output: 556
🏁 Script executed:
#!/bin/bash
# Check if there's a Makefile in java-api-examples that compiles Java files
cat java-api-examples/Makefile 2>/dev/null || echo "No Makefile found"Repository: k2-fsa/sherpa-onnx
Length of output: 79
🏁 Script executed:
#!/bin/bash
# Check the sherpa-onnx java-api Makefile to see how Java is built
cat ../sherpa-onnx/java-api/Makefile 2>/dev/null | head -50Repository: k2-fsa/sherpa-onnx
Length of output: 44
🏁 Script executed:
#!/bin/bash
# Look for Java version configuration in gradle or maven files
find . -type f \( -name "*.gradle" -o -name "pom.xml" \) -exec grep -l "source\|target\|release\|java.version" {} \;Repository: k2-fsa/sherpa-onnx
Length of output: 590
🏁 Script executed:
#!/bin/bash
# Check if the Java source files actually exist or are compiled
ls -la java-api-examples/*.java 2>/dev/null | head -20Repository: k2-fsa/sherpa-onnx
Length of output: 2178
🏁 Script executed:
#!/bin/bash
# Check the pom.xml to see Java version requirements
cat ./pom.xmlRepository: k2-fsa/sherpa-onnx
Length of output: 857
🏁 Script executed:
#!/bin/bash
# Check the sherpa-onnx java-api pom.xml
cat ./sherpa-onnx/java-api/pom.xmlRepository: k2-fsa/sherpa-onnx
Length of output: 3286
🏁 Script executed:
#!/bin/bash
# Look at one of the Java example files to understand its structure
head -30 java-api-examples/NonStreamingDecodeFileFunAsrNano.javaRepository: k2-fsa/sherpa-onnx
Length of output: 1243
🏁 Script executed:
#!/bin/bash
# Check the java-api-examples README for instructions
cat java-api-examples/README.mdRepository: k2-fsa/sherpa-onnx
Length of output: 2922
Remove .java extension or compile files before execution.
The script passes NonStreamingDecodeFileFunAsrNano.java directly to the Java command (source-file mode), which requires Java 11+. However, the project is configured for Java 1.8 (see sherpa-onnx/java-api/pom.xml), creating an incompatibility. Either compile the Java files with javac first and pass the class name, or remove the .java extension from the command. This issue affects all scripts in java-api-examples/.
🤖 Prompt for AI Agents
In @java-api-examples/run-non-streaming-decode-file-funasr-nano.sh around lines
34 - 37, The script incorrectly passes the source file name
NonStreamingDecodeFileFunAsrNano.java to the java launcher (source-file mode)
while the project targets Java 1.8; instead, compile the example with javac
first and then invoke the class by its simple name. Update the run command to
(1) run javac on NonStreamingDecodeFileFunAsrNano.java (ensuring the classpath
includes ../sherpa-onnx/java-api/build/sherpa-onnx.jar), and (2) invoke java
with -Djava.library.path pointing to ../build/lib and -cp including both the jar
and the current directory, calling NonStreamingDecodeFileFunAsrNano (no .java).
Apply the same fix to all scripts in java-api-examples/.
Summary by CodeRabbit
Release Notes
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.