继续操作前请注册或者登录。
Fangjun Kuang
Committed by GitHub

Fix java test (#2496)

... ... @@ -85,7 +85,7 @@ jobs:
- name: Install Python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile setuptools wheel
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile setuptools wheel librosa
- name: Install sherpa-onnx
shell: bash
... ...
... ... @@ -80,7 +80,7 @@ jobs:
- name: Install Python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile
python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile librosa
python3 -m pip install wheel twine setuptools
- uses: afoley587/setup-ffmpeg@main
... ...
... ... @@ -47,7 +47,7 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
} else {
SHERPA_ONNX_LOGE("Unsupported decoding method: %s",
config_.decoding_method.c_str());
exit(-1);
SHERPA_ONNX_EXIT(-1);
}
PostInit();
}
... ... @@ -62,11 +62,11 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
mgr, config_.model_config)) {
if (config_.decoding_method == "greedy_search") {
decoder_ = std::make_unique<OfflineTransducerGreedySearchNeMoDecoder>(
model_.get(), config_.blank_penalty);
model_.get(), config_.blank_penalty, model_->IsTDT());
} else {
SHERPA_ONNX_LOGE("Unsupported decoding method: %s",
config_.decoding_method.c_str());
exit(-1);
SHERPA_ONNX_EXIT(-1);
}
PostInit();
... ... @@ -175,18 +175,18 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
// check the blank ID
if (!symbol_table_.Contains("<blk>")) {
SHERPA_ONNX_LOGE("tokens.txt does not include the blank token <blk>");
exit(-1);
SHERPA_ONNX_EXIT(-1);
}
if (symbol_table_["<blk>"] != vocab_size - 1) {
SHERPA_ONNX_LOGE("<blk> is not the last token!");
exit(-1);
SHERPA_ONNX_EXIT(-1);
}
if (symbol_table_.NumSymbols() != vocab_size) {
SHERPA_ONNX_LOGE("number of lines in tokens.txt %d != %d (vocab_size)",
symbol_table_.NumSymbols(), vocab_size);
exit(-1);
SHERPA_ONNX_EXIT(-1);
}
}
... ...
... ... @@ -6,7 +6,8 @@ out_jar := $(out_dir)/sherpa-onnx.jar
package_dir := com/k2fsa/sherpa/onnx
java_files := LibraryLoader.java
java_files := LibraryUtils.java
java_files += LibraryLoader.java
java_files += VersionInfo.java
java_files += WaveReader.java
... ...
package com.k2fsa.sherpa.onnx;
import com.k2fsa.sherpa.onnx.utils.LibraryUtils;
public class LibraryLoader {
private static volatile boolean autoLoadEnabled = true;
private static volatile boolean isLoaded = false;
... ...
package com.k2fsa.sherpa.onnx.utils;
package com.k2fsa.sherpa.onnx;
import java.io.File;
import java.io.IOException;
... ... @@ -7,31 +7,34 @@ import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Locale;
import com.k2fsa.sherpa.onnx.core.Core;
public class LibraryUtils {
// System property to override native library path
private static final String NATIVE_PATH_PROP = "sherpa_onnx.native.path";
private static final String LIB_NAME = "sherpa-onnx-jni";
public static void load() {
String libFileName = System.mapLibraryName(Core.NATIVE_LIBRARY_NAME);
String libFileName = System.mapLibraryName(LIB_NAME);
// 1. Try loading from external directory if provided
String nativePath = System.getProperty(NATIVE_PATH_PROP);
if (nativePath != null) {
File nativeDir = new File(nativePath);
File libInDir = new File(nativeDir, libFileName);
if (nativeDir.isDirectory() && libInDir.exists()) {
System.out.println("Loading native lib from external directory: " + libInDir.getAbsolutePath());
System.load(libInDir.getAbsolutePath());
return;
try {
// 1. Try loading from external directory if provided
String nativePath = System.getProperty(NATIVE_PATH_PROP);
if (nativePath != null) {
File nativeDir = new File(nativePath);
File libInDir = new File(nativeDir, libFileName);
if (nativeDir.isDirectory() && libInDir.exists()) {
System.out.println("Loading native lib from external directory: " + libInDir.getAbsolutePath());
System.load(libInDir.getAbsolutePath());
return;
}
}
}
// 2. Fallback to extracting and loading from the JAR
File libFile = init(libFileName);
System.out.println("Loading native lib from: " + libFile.getAbsolutePath());
System.load(libFile.getAbsolutePath());
// 2. Fallback to extracting and loading from the JAR
File libFile = init(libFileName);
System.out.println("Loading native lib from: " + libFile.getAbsolutePath());
System.load(libFile.getAbsolutePath());
} catch (RuntimeException ex) {
System.loadLibrary(LIB_NAME);
}
}
/* Computes and initializes OS_ARCH_STR (such as linux-x64) */
... ...
package com.k2fsa.sherpa.onnx.core;
public interface Core {
String NATIVE_LIBRARY_NAME = "sherpa-onnx-jni";
}