Add Java and Kotlin API for Cohere Transcribe - #3461
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds Cohere Transcribe offline model support across Java/Kotlin APIs, JNI/native parsing, examples and CI: new model config types, JNI parsing for cohereTranscribe, example programs and scripts to run them, exported JNI option symbols, and CI workflow updates to run the new examples on the Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Example as Example (Java/Kotlin)
participant API as Java/Kotlin API
participant JNI as JNI bridge
participant Native as Native C++ Runtime
participant Model as Cohere Transcribe ONNX files
Example->>API: build OfflineModelConfig (cohereTranscribe)
API->>JNI: call native createOfflineRecognizer(config)
JNI->>Native: translate Java config -> native GetOfflineConfig
Native->>Model: load encoder/decoder ONNX, tokens
Example->>API: create OfflineStream, setOption(language)
Example->>API: acceptWaveform(samples, sample_rate)
API->>JNI: recognizer.decode(stream) -> JNI -> Native
Native->>Native: run decode with Cohere Transcribe models
Native-->>JNI: return result
JNI-->>API: wrap result
API-->>Example: getResult(text, metrics)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
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. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Code Review
This pull request introduces support for the Cohere Transcribe model across the Java and Kotlin APIs. Key changes include the addition of the OfflineCohereTranscribeModelConfig class, updated JNI bindings to handle the new configuration, and new example scripts and source files for both languages. The review feedback suggests improving the maintainability of the shell scripts by using variables for model names and cleaning up the Kotlin compilation command by removing an unused source file.
| if [ ! -f ./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/encoder.int8.onnx ]; then | ||
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | ||
| tar xvf sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | ||
| rm sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | ||
| ls -lh sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01 | ||
| fi |
There was a problem hiding this comment.
The model name sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01 is repeated multiple times. To improve maintainability, it would be better to store it in a variable and reuse it. This makes it easier to update the model version in the future.
| if [ ! -f ./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/encoder.int8.onnx ]; then | |
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | |
| tar xvf sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | |
| rm sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | |
| ls -lh sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01 | |
| fi | |
| MODEL_NAME="sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01" | |
| if [ ! -f ./${MODEL_NAME}/encoder.int8.onnx ]; then | |
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${MODEL_NAME}.tar.bz2 | |
| tar xvf ${MODEL_NAME}.tar.bz2 | |
| rm ${MODEL_NAME}.tar.bz2 | |
| ls -lh ${MODEL_NAME} | |
| fi |
| if [ ! -f ./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/encoder.int8.onnx ]; then | ||
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | ||
| tar xvf sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | ||
| rm sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | ||
| fi |
There was a problem hiding this comment.
The model name sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01 is repeated. To improve maintainability, consider defining it as a local variable at the beginning of the function. This will make it easier to update in the future.
| if [ ! -f ./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/encoder.int8.onnx ]; then | |
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | |
| tar xvf sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | |
| rm sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01.tar.bz2 | |
| fi | |
| local model_name="sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01" | |
| if [ ! -f ./${model_name}/encoder.int8.onnx ]; then | |
| curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${model_name}.tar.bz2 | |
| tar xvf ${model_name}.tar.bz2 | |
| rm ${model_name}.tar.bz2 | |
| fi |
| kotlinc-jvm -include-runtime -d $out_filename \ | ||
| test_offline_cohere_transcribe.kt \ | ||
| FeatureConfig.kt \ | ||
| QnnConfig.kt \ | ||
| HomophoneReplacerConfig.kt \ | ||
| OfflineRecognizer.kt \ | ||
| OfflineStream.kt \ | ||
| WaveReader.kt \ | ||
| faked-asset-manager.kt |
There was a problem hiding this comment.
The file faked-asset-manager.kt is included in the compilation but does not seem to be used by test_offline_cohere_transcribe.kt. To keep the build dependencies clean, it's better to remove unused files from the compilation list.
| kotlinc-jvm -include-runtime -d $out_filename \ | |
| test_offline_cohere_transcribe.kt \ | |
| FeatureConfig.kt \ | |
| QnnConfig.kt \ | |
| HomophoneReplacerConfig.kt \ | |
| OfflineRecognizer.kt \ | |
| OfflineStream.kt \ | |
| WaveReader.kt \ | |
| faked-asset-manager.kt | |
| kotlinc-jvm -include-runtime -d $out_filename \ | |
| test_offline_cohere_transcribe.kt \ | |
| FeatureConfig.kt \ | |
| QnnConfig.kt \ | |
| HomophoneReplacerConfig.kt \ | |
| OfflineRecognizer.kt \ | |
| OfflineStream.kt \ | |
| WaveReader.kt |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
kotlin-api-examples/test_offline_cohere_transcribe.kt (1)
26-28: Use an explicit locale for numeric formatting.Lines 26–28 use
String.format()without an explicit locale, causing numeric output (decimal separator, grouping) to vary based on the system's default locale. This can lead to inconsistent results across environments.Suggested patch
+import java.util.Locale ... - println(String.format("-- elapsed : %.3f seconds", timeElapsedSeconds)) - println(String.format("-- audio duration: %.3f seconds", audioDuration)) - println(String.format("-- real-time factor (RTF): %.3f", realTimeFactor)) + println(String.format(Locale.US, "-- elapsed : %.3f seconds", timeElapsedSeconds)) + println(String.format(Locale.US, "-- audio duration: %.3f seconds", audioDuration)) + println(String.format(Locale.US, "-- real-time factor (RTF): %.3f", realTimeFactor))🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@kotlin-api-examples/test_offline_cohere_transcribe.kt` around lines 26 - 28, The String.format calls used in println in test_offline_cohere_transcribe.kt produce locale-dependent numeric output; update those String.format invocations (the three lines that print timeElapsedSeconds, audioDuration, and realTimeFactor) to pass an explicit Locale (e.g., Locale.US or Locale.ROOT) as the first argument so decimal separators and formatting are consistent across environments.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@java-api-examples/run-non-streaming-decode-file-cohere-transcribe.sh`:
- Line 36: The JVM library path argument is unquoted in the shell script causing
word-splitting/globbing for paths with spaces; update the invocation that sets
-Djava.library.path (in run-non-streaming-decode-file-cohere-transcribe.sh) to
quote the value (e.g., "-Djava.library.path=$PWD/../build/lib") so the entire
path is treated as a single argument.
---
Nitpick comments:
In `@kotlin-api-examples/test_offline_cohere_transcribe.kt`:
- Around line 26-28: The String.format calls used in println in
test_offline_cohere_transcribe.kt produce locale-dependent numeric output;
update those String.format invocations (the three lines that print
timeElapsedSeconds, audioDuration, and realTimeFactor) to pass an explicit
Locale (e.g., Locale.US or Locale.ROOT) as the first argument so decimal
separators and formatting are consistent across environments.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a4bbc366-39f9-463f-8157-8030754bffbe
📒 Files selected for processing (12)
.github/workflows/jni.yaml.github/workflows/run-java-test.yamljava-api-examples/NonStreamingDecodeFileCohereTranscribe.javajava-api-examples/run-non-streaming-decode-file-cohere-transcribe.shkotlin-api-examples/run.shkotlin-api-examples/test_offline_cohere_transcribe.ktsherpa-onnx/java-api/Makefilesherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineCohereTranscribeModelConfig.javasherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineModelConfig.javasherpa-onnx/jni/offline-recognizer.ccsherpa-onnx/jni/sherpa-onnx-symbols.expsherpa-onnx/kotlin-api/OfflineRecognizer.kt
| fi | ||
|
|
||
| java \ | ||
| -Djava.library.path=$PWD/../build/lib \ |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n '\-Djava\.library\.path=\$PWD/\.\./build/lib' java-api-examples/run-non-streaming-decode-file-cohere-transcribe.sh -C1Repository: k2-fsa/sherpa-onnx
Length of output: 173
Quote the JVM library path value.
Line 36 expands an unquoted path, which can split or glob in bash if the path contains spaces or special characters.
Suggested patch
- -Djava.library.path=$PWD/../build/lib \
+ -Djava.library.path="$PWD/../build/lib" \📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| -Djava.library.path=$PWD/../build/lib \ | |
| -Djava.library.path="$PWD/../build/lib" \ |
🧰 Tools
🪛 Shellcheck (0.11.0)
[info] 36-36: Double quote to prevent globbing and word splitting.
(SC2086)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@java-api-examples/run-non-streaming-decode-file-cohere-transcribe.sh` at line
36, The JVM library path argument is unquoted in the shell script causing
word-splitting/globbing for paths with spaces; update the invocation that sets
-Djava.library.path (in run-non-streaming-decode-file-cohere-transcribe.sh) to
quote the value (e.g., "-Djava.library.path=$PWD/../build/lib") so the entire
path is treated as a single argument.
Summary by CodeRabbit
New Features
Chores