Fangjun Kuang
Committed by GitHub

Fix java test (#2496)

@@ -85,7 +85,7 @@ jobs: @@ -85,7 +85,7 @@ jobs:
85 - name: Install Python dependencies 85 - name: Install Python dependencies
86 shell: bash 86 shell: bash
87 run: | 87 run: |
88 - python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile setuptools wheel 88 + python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile setuptools wheel librosa
89 89
90 - name: Install sherpa-onnx 90 - name: Install sherpa-onnx
91 shell: bash 91 shell: bash
@@ -80,7 +80,7 @@ jobs: @@ -80,7 +80,7 @@ jobs:
80 - name: Install Python dependencies 80 - name: Install Python dependencies
81 shell: bash 81 shell: bash
82 run: | 82 run: |
83 - python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile 83 + python3 -m pip install --upgrade pip numpy pypinyin sentencepiece>=0.1.96 soundfile librosa
84 python3 -m pip install wheel twine setuptools 84 python3 -m pip install wheel twine setuptools
85 85
86 - uses: afoley587/setup-ffmpeg@main 86 - uses: afoley587/setup-ffmpeg@main
@@ -47,7 +47,7 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl { @@ -47,7 +47,7 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
47 } else { 47 } else {
48 SHERPA_ONNX_LOGE("Unsupported decoding method: %s", 48 SHERPA_ONNX_LOGE("Unsupported decoding method: %s",
49 config_.decoding_method.c_str()); 49 config_.decoding_method.c_str());
50 - exit(-1); 50 + SHERPA_ONNX_EXIT(-1);
51 } 51 }
52 PostInit(); 52 PostInit();
53 } 53 }
@@ -62,11 +62,11 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl { @@ -62,11 +62,11 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
62 mgr, config_.model_config)) { 62 mgr, config_.model_config)) {
63 if (config_.decoding_method == "greedy_search") { 63 if (config_.decoding_method == "greedy_search") {
64 decoder_ = std::make_unique<OfflineTransducerGreedySearchNeMoDecoder>( 64 decoder_ = std::make_unique<OfflineTransducerGreedySearchNeMoDecoder>(
65 - model_.get(), config_.blank_penalty); 65 + model_.get(), config_.blank_penalty, model_->IsTDT());
66 } else { 66 } else {
67 SHERPA_ONNX_LOGE("Unsupported decoding method: %s", 67 SHERPA_ONNX_LOGE("Unsupported decoding method: %s",
68 config_.decoding_method.c_str()); 68 config_.decoding_method.c_str());
69 - exit(-1); 69 + SHERPA_ONNX_EXIT(-1);
70 } 70 }
71 71
72 PostInit(); 72 PostInit();
@@ -175,18 +175,18 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl { @@ -175,18 +175,18 @@ class OfflineRecognizerTransducerNeMoImpl : public OfflineRecognizerImpl {
175 // check the blank ID 175 // check the blank ID
176 if (!symbol_table_.Contains("<blk>")) { 176 if (!symbol_table_.Contains("<blk>")) {
177 SHERPA_ONNX_LOGE("tokens.txt does not include the blank token <blk>"); 177 SHERPA_ONNX_LOGE("tokens.txt does not include the blank token <blk>");
178 - exit(-1); 178 + SHERPA_ONNX_EXIT(-1);
179 } 179 }
180 180
181 if (symbol_table_["<blk>"] != vocab_size - 1) { 181 if (symbol_table_["<blk>"] != vocab_size - 1) {
182 SHERPA_ONNX_LOGE("<blk> is not the last token!"); 182 SHERPA_ONNX_LOGE("<blk> is not the last token!");
183 - exit(-1); 183 + SHERPA_ONNX_EXIT(-1);
184 } 184 }
185 185
186 if (symbol_table_.NumSymbols() != vocab_size) { 186 if (symbol_table_.NumSymbols() != vocab_size) {
187 SHERPA_ONNX_LOGE("number of lines in tokens.txt %d != %d (vocab_size)", 187 SHERPA_ONNX_LOGE("number of lines in tokens.txt %d != %d (vocab_size)",
188 symbol_table_.NumSymbols(), vocab_size); 188 symbol_table_.NumSymbols(), vocab_size);
189 - exit(-1); 189 + SHERPA_ONNX_EXIT(-1);
190 } 190 }
191 } 191 }
192 192
@@ -6,7 +6,8 @@ out_jar := $(out_dir)/sherpa-onnx.jar @@ -6,7 +6,8 @@ out_jar := $(out_dir)/sherpa-onnx.jar
6 6
7 package_dir := com/k2fsa/sherpa/onnx 7 package_dir := com/k2fsa/sherpa/onnx
8 8
9 -java_files := LibraryLoader.java 9 +java_files := LibraryUtils.java
  10 +java_files += LibraryLoader.java
10 11
11 java_files += VersionInfo.java 12 java_files += VersionInfo.java
12 java_files += WaveReader.java 13 java_files += WaveReader.java
1 package com.k2fsa.sherpa.onnx; 1 package com.k2fsa.sherpa.onnx;
2 2
3 -import com.k2fsa.sherpa.onnx.utils.LibraryUtils;  
4 -  
5 public class LibraryLoader { 3 public class LibraryLoader {
6 private static volatile boolean autoLoadEnabled = true; 4 private static volatile boolean autoLoadEnabled = true;
7 private static volatile boolean isLoaded = false; 5 private static volatile boolean isLoaded = false;
1 -package com.k2fsa.sherpa.onnx.utils; 1 +package com.k2fsa.sherpa.onnx;
2 2
3 import java.io.File; 3 import java.io.File;
4 import java.io.IOException; 4 import java.io.IOException;
@@ -7,15 +7,15 @@ import java.nio.file.Files; @@ -7,15 +7,15 @@ import java.nio.file.Files;
7 import java.nio.file.StandardCopyOption; 7 import java.nio.file.StandardCopyOption;
8 import java.util.Locale; 8 import java.util.Locale;
9 9
10 -import com.k2fsa.sherpa.onnx.core.Core;  
11 -  
12 public class LibraryUtils { 10 public class LibraryUtils {
13 // System property to override native library path 11 // System property to override native library path
14 private static final String NATIVE_PATH_PROP = "sherpa_onnx.native.path"; 12 private static final String NATIVE_PATH_PROP = "sherpa_onnx.native.path";
  13 + private static final String LIB_NAME = "sherpa-onnx-jni";
15 14
16 public static void load() { 15 public static void load() {
17 - String libFileName = System.mapLibraryName(Core.NATIVE_LIBRARY_NAME); 16 + String libFileName = System.mapLibraryName(LIB_NAME);
18 17
  18 + try {
19 // 1. Try loading from external directory if provided 19 // 1. Try loading from external directory if provided
20 String nativePath = System.getProperty(NATIVE_PATH_PROP); 20 String nativePath = System.getProperty(NATIVE_PATH_PROP);
21 if (nativePath != null) { 21 if (nativePath != null) {
@@ -32,6 +32,9 @@ public class LibraryUtils { @@ -32,6 +32,9 @@ public class LibraryUtils {
32 File libFile = init(libFileName); 32 File libFile = init(libFileName);
33 System.out.println("Loading native lib from: " + libFile.getAbsolutePath()); 33 System.out.println("Loading native lib from: " + libFile.getAbsolutePath());
34 System.load(libFile.getAbsolutePath()); 34 System.load(libFile.getAbsolutePath());
  35 + } catch (RuntimeException ex) {
  36 + System.loadLibrary(LIB_NAME);
  37 + }
35 } 38 }
36 39
37 /* Computes and initializes OS_ARCH_STR (such as linux-x64) */ 40 /* Computes and initializes OS_ARCH_STR (such as linux-x64) */
1 -package com.k2fsa.sherpa.onnx.core;  
2 -  
3 -public interface Core {  
4 - String NATIVE_LIBRARY_NAME = "sherpa-onnx-jni";  
5 -}