zhaomingwork
Committed by GitHub

For java ci actions (#231)

  1 +name: run-java-test
  2 +
  3 +on:
  4 + push:
  5 + branches:
  6 + - master
  7 + paths:
  8 + - '.github/workflows/run-java-test.yaml'
  9 + - 'CMakeLists.txt'
  10 + - 'cmake/**'
  11 + - 'java-api-examples/**'
  12 + - 'sherpa-onnx/csrc/*'
  13 + - 'sherpa-onnx/jni/*'
  14 + pull_request:
  15 + branches:
  16 + - master
  17 + paths:
  18 + - '.github/workflows/run-java-test.yaml'
  19 + - 'CMakeLists.txt'
  20 + - 'cmake/**'
  21 + - 'java-api-examples/**'
  22 + - 'sherpa-onnx/csrc/*'
  23 + - 'sherpa-onnx/jni/*'
  24 +
  25 +concurrency:
  26 + group: jni-${{ github.ref }}
  27 + cancel-in-progress: true
  28 +
  29 +permissions:
  30 + contents: read
  31 +
  32 +jobs:
  33 + jni:
  34 + runs-on: ${{ matrix.os }}
  35 + strategy:
  36 + fail-fast: false
  37 + matrix:
  38 + os: [ubuntu-latest]
  39 +
  40 + steps:
  41 + - uses: actions/checkout@v2
  42 + with:
  43 + fetch-depth: 0
  44 +
  45 + - name: Display java version
  46 + shell: bash
  47 + run: |
  48 + java -version
  49 + echo "JAVA_HOME is: ${JAVA_HOME}"
  50 +
  51 + - name: Run java test
  52 + shell: bash
  53 + run: |
  54 + cd ./java-api-examples
  55 + ./runtest.sh
@@ -73,10 +73,10 @@ runmic: @@ -73,10 +73,10 @@ runmic:
73 java -cp ./lib/sherpaonnx.jar:build $(RUNJFLAGS) DecodeMic 73 java -cp ./lib/sherpaonnx.jar:build $(RUNJFLAGS) DecodeMic
74 74
75 runsrv: 75 runsrv:
76 - java -cp $(BUILD_DIR):lib/Java-WebSocket-1.5.3.jar:lib/slf4j-simple-1.7.25.jar:lib/slf4j-api-1.7.25.jar:../lib/sherpaonnx.jar $(RUNJFLAGS) websocketsrv.AsrWebsocketServer /sherpa-onnx/20230515/zhaoming/sherpa-onnx/build/lib/libsherpa-onnx-jni.so ./modelconfig.cfg 76 + java -cp $(BUILD_DIR):lib/Java-WebSocket-1.5.3.jar:lib/slf4j-simple-1.7.25.jar:lib/slf4j-api-1.7.25.jar:../lib/sherpaonnx.jar $(RUNJFLAGS) websocketsrv.AsrWebsocketServer ../build/lib/libsherpa-onnx-jni.so ./modeltest.cfg
77 77
78 runclient: 78 runclient:
79 - java -cp $(BUILD_DIR):lib/Java-WebSocket-1.5.3.jar:lib/slf4j-simple-1.7.25.jar:lib/slf4j-api-1.7.25.jar:../lib/sherpaonnx.jar $(RUNJFLAGS) websocketsrv.AsrWebsocketClient /sherpa-onnx/20230515/zhaoming/sherpa-onnx/build/lib/libsherpa-onnx-jni.so 127.0.0.1 8890 ./test.wav 32 79 + java -cp $(BUILD_DIR):lib/Java-WebSocket-1.5.3.jar:lib/slf4j-simple-1.7.25.jar:lib/slf4j-api-1.7.25.jar:../lib/sherpaonnx.jar $(RUNJFLAGS) websocketsrv.AsrWebsocketClient ../build/lib/libsherpa-onnx-jni.so 127.0.0.1 8890 ./test.wav 32
80 80
81 buildlib: $(LIB_FILES:.java=.class) 81 buildlib: $(LIB_FILES:.java=.class)
82 82
@@ -185,3 +185,9 @@ json result example: {"text":"甚至出现交易几乎停滞的情况","eof":"tr @@ -185,3 +185,9 @@ json result example: {"text":"甚至出现交易几乎停滞的情况","eof":"tr
185 make runclient /**change path in Makefile according to your env**/ 185 make runclient /**change path in Makefile according to your env**/
186 ``` 186 ```
187 187
  188 +7 runtest
  189 +this script will download model, compile codes and run test
  190 +```bash
  191 + cd sherpa-onnx/java-api-examples
  192 + runtest.sh
  193 +```
  1 +#!/usr/bin/env bash
  2 +#
  3 +# This scripts shows how to test java for sherpa-onnx
  4 +# Note: This scripts runs only on Linux and macOS
  5 +
  6 +set -e
  7 +
  8 +log() {
  9 + # This function is from espnet
  10 + local fname=${BASH_SOURCE[1]##*/}
  11 + echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*"
  12 +}
  13 +
  14 +
  15 +
  16 +
  17 +echo "PATH: $PATH"
  18 +
  19 +
  20 +
  21 +
  22 +
  23 +log "------------------------------------------------------------"
  24 +log "Run download model"
  25 +log "------------------------------------------------------------"
  26 +
  27 +repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
  28 +log "Start testing ${repo_url}"
  29 +repo=$(basename $repo_url)
  30 +log "download dir is $(basename $repo_url)"
  31 +if [ ! -d $repo ];then
  32 + log "Download pretrained model and test-data from $repo_url"
  33 +
  34 + GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
  35 + pushd $repo
  36 + git lfs pull --include "*.onnx"
  37 + ls -lh *.onnx
  38 + popd
  39 +fi
  40 +
  41 +log $(pwd)
  42 +
  43 +sed -e 's?/sherpa/?'$(pwd)'/?g' modelconfig.cfg > modeltest.cfg
  44 +
  45 +log "display model cfg"
  46 +cat modeltest.cfg
  47 +
  48 +cd ..
  49 +
  50 +export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
  51 +
  52 +mkdir -p build
  53 +cd build
  54 +
  55 +cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSHERPA_ONNX_ENABLE_JNI=ON ..
  56 +
  57 +make -j4
  58 +ls -lh lib
  59 +
  60 +export LD_LIBRARY_PATH=$PWD/build/lib:$LD_LIBRARY_PATH
  61 +
  62 +cd ../java-api-examples
  63 +
  64 +make all
  65 +
  66 +make runfile
@@ -159,7 +159,7 @@ public class DecodeFile { @@ -159,7 +159,7 @@ public class DecodeFile {
159 String appDir = System.getProperty("user.dir"); 159 String appDir = System.getProperty("user.dir");
160 System.out.println("appdir=" + appDir); 160 System.out.println("appdir=" + appDir);
161 String fileName = appDir + "/test.wav"; 161 String fileName = appDir + "/test.wav";
162 - String cfgPath = appDir + "/modelconfig.cfg"; 162 + String cfgPath = appDir + "/modeltest.cfg";
163 String soPath = appDir + "/../build/lib/libsherpa-onnx-jni.so"; 163 String soPath = appDir + "/../build/lib/libsherpa-onnx-jni.so";
164 OnlineRecognizer.setSoPath(soPath); 164 OnlineRecognizer.setSoPath(soPath);
165 DecodeFile rcgDemo = new DecodeFile(fileName); 165 DecodeFile rcgDemo = new DecodeFile(fileName);