Fangjun Kuang
Committed by GitHub

Add C++ API for streaming ASR. (#1455)

It is a wrapper around the C API.
正在显示 72 个修改的文件 包含 729 行增加83 行删除
  1 +#!/usr/bin/env bash
  2 +
  3 +set -ex
  4 +
  5 +log() {
  6 + # This function is from espnet
  7 + local fname=${BASH_SOURCE[1]##*/}
  8 + echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*"
  9 +}
  10 +
  11 +echo "CXX_STREAMING_ZIPFORMER_EXE is $CXX_STREAMING_ZIPFORMER_EXE"
  12 +echo "PATH: $PATH"
  13 +
  14 +log "------------------------------------------------------------"
  15 +log "Test streaming zipformer CXX API"
  16 +log "------------------------------------------------------------"
  17 +curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  18 +tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  19 +rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  20 +$CXX_STREAMING_ZIPFORMER_EXE
  21 +rm -rf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
@@ -193,7 +193,7 @@ jobs: @@ -193,7 +193,7 @@ jobs:
193 193
194 rm -rf huggingface 194 rm -rf huggingface
195 export GIT_CLONE_PROTECTION_ACTIVE=false 195 export GIT_CLONE_PROTECTION_ACTIVE=false
196 - GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface 196 + GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-libs huggingface
197 197
198 cd huggingface 198 cd huggingface
199 mkdir -p aarch64 199 mkdir -p aarch64
@@ -184,7 +184,7 @@ jobs: @@ -184,7 +184,7 @@ jobs:
184 184
185 rm -rf huggingface 185 rm -rf huggingface
186 export GIT_CLONE_PROTECTION_ACTIVE=false 186 export GIT_CLONE_PROTECTION_ACTIVE=false
187 - GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface 187 + GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-libs huggingface
188 188
189 cd huggingface 189 cd huggingface
190 mkdir -p aarch64 190 mkdir -p aarch64
@@ -121,7 +121,7 @@ jobs: @@ -121,7 +121,7 @@ jobs:
121 121
122 rm -rf huggingface 122 rm -rf huggingface
123 export GIT_CLONE_PROTECTION_ACTIVE=false 123 export GIT_CLONE_PROTECTION_ACTIVE=false
124 - GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface 124 + GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-libs huggingface
125 125
126 cd huggingface 126 cd huggingface
127 127
@@ -163,7 +163,7 @@ jobs: @@ -163,7 +163,7 @@ jobs:
163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
165 165
166 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 166 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
167 cd huggingface 167 cd huggingface
168 git fetch 168 git fetch
169 git pull 169 git pull
@@ -163,7 +163,7 @@ jobs: @@ -163,7 +163,7 @@ jobs:
163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
165 165
166 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 166 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
167 cd huggingface 167 cd huggingface
168 git fetch 168 git fetch
169 git pull 169 git pull
@@ -163,7 +163,7 @@ jobs: @@ -163,7 +163,7 @@ jobs:
163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
165 165
166 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 166 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
167 cd huggingface 167 cd huggingface
168 git fetch 168 git fetch
169 git pull 169 git pull
@@ -160,7 +160,7 @@ jobs: @@ -160,7 +160,7 @@ jobs:
160 export GIT_LFS_SKIP_SMUDGE=1 160 export GIT_LFS_SKIP_SMUDGE=1
161 export GIT_CLONE_PROTECTION_ACTIVE=false 161 export GIT_CLONE_PROTECTION_ACTIVE=false
162 162
163 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 163 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
164 cd huggingface 164 cd huggingface
165 git fetch 165 git fetch
166 git pull 166 git pull
@@ -160,7 +160,7 @@ jobs: @@ -160,7 +160,7 @@ jobs:
160 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 160 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
161 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 161 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
162 162
163 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 163 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
164 cd huggingface 164 cd huggingface
165 git fetch 165 git fetch
166 git pull 166 git pull
@@ -163,7 +163,7 @@ jobs: @@ -163,7 +163,7 @@ jobs:
163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
165 165
166 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 166 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
167 cd huggingface 167 cd huggingface
168 git fetch 168 git fetch
169 git pull 169 git pull
@@ -163,7 +163,7 @@ jobs: @@ -163,7 +163,7 @@ jobs:
163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
165 165
166 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 166 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
167 cd huggingface 167 cd huggingface
168 git fetch 168 git fetch
169 git pull 169 git pull
@@ -163,7 +163,7 @@ jobs: @@ -163,7 +163,7 @@ jobs:
163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
165 165
166 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 166 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
167 cd huggingface 167 cd huggingface
168 git fetch 168 git fetch
169 git pull 169 git pull
@@ -164,7 +164,7 @@ jobs: @@ -164,7 +164,7 @@ jobs:
164 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 164 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
165 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 165 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
166 166
167 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 167 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
168 cd huggingface 168 cd huggingface
169 git fetch 169 git fetch
170 git pull 170 git pull
@@ -164,7 +164,7 @@ jobs: @@ -164,7 +164,7 @@ jobs:
164 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 164 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
165 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 165 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
166 166
167 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 167 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
168 cd huggingface 168 cd huggingface
169 git fetch 169 git fetch
170 git pull 170 git pull
@@ -163,7 +163,7 @@ jobs: @@ -163,7 +163,7 @@ jobs:
163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 163 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 164 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
165 165
166 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 166 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
167 cd huggingface 167 cd huggingface
168 git fetch 168 git fetch
169 git pull 169 git pull
@@ -160,7 +160,7 @@ jobs: @@ -160,7 +160,7 @@ jobs:
160 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 160 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
161 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 161 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
162 162
163 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface 163 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk huggingface
164 cd huggingface 164 cd huggingface
165 git fetch 165 git fetch
166 git pull 166 git pull
@@ -205,7 +205,7 @@ jobs: @@ -205,7 +205,7 @@ jobs:
205 git config --global user.name "Fangjun Kuang" 205 git config --global user.name "Fangjun Kuang"
206 206
207 rm -rf huggingface 207 rm -rf huggingface
208 - GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface 208 + GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-libs huggingface
209 209
210 cd huggingface 210 cd huggingface
211 mkdir -p arm32 211 mkdir -p arm32
@@ -99,7 +99,7 @@ jobs: @@ -99,7 +99,7 @@ jobs:
99 99
100 d=cpu/$SHERPA_ONNX_VERSION 100 d=cpu/$SHERPA_ONNX_VERSION
101 101
102 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 102 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
103 cd huggingface 103 cd huggingface
104 git fetch 104 git fetch
105 git pull 105 git pull
@@ -102,7 +102,7 @@ jobs: @@ -102,7 +102,7 @@ jobs:
102 102
103 d=cpu/$SHERPA_ONNX_VERSION 103 d=cpu/$SHERPA_ONNX_VERSION
104 104
105 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 105 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
106 cd huggingface 106 cd huggingface
107 git fetch 107 git fetch
108 git pull 108 git pull
@@ -113,7 +113,7 @@ jobs: @@ -113,7 +113,7 @@ jobs:
113 113
114 d=cuda/$SHERPA_ONNX_VERSION 114 d=cuda/$SHERPA_ONNX_VERSION
115 115
116 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 116 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
117 cd huggingface 117 cd huggingface
118 git fetch 118 git fetch
119 git pull 119 git pull
@@ -96,7 +96,7 @@ jobs: @@ -96,7 +96,7 @@ jobs:
96 96
97 d=cpu/$SHERPA_ONNX_VERSION 97 d=cpu/$SHERPA_ONNX_VERSION
98 98
99 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 99 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
100 cd huggingface 100 cd huggingface
101 git fetch 101 git fetch
102 git pull 102 git pull
@@ -68,7 +68,7 @@ jobs: @@ -68,7 +68,7 @@ jobs:
68 68
69 d=cpu/$SHERPA_ONNX_VERSION 69 d=cpu/$SHERPA_ONNX_VERSION
70 70
71 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 71 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
72 cd huggingface 72 cd huggingface
73 git fetch 73 git fetch
74 git pull 74 git pull
@@ -68,7 +68,7 @@ jobs: @@ -68,7 +68,7 @@ jobs:
68 68
69 d=cpu/$SHERPA_ONNX_VERSION 69 d=cpu/$SHERPA_ONNX_VERSION
70 70
71 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 71 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
72 cd huggingface 72 cd huggingface
73 git fetch 73 git fetch
74 git pull 74 git pull
@@ -83,7 +83,7 @@ jobs: @@ -83,7 +83,7 @@ jobs:
83 83
84 d=cpu/$SHERPA_ONNX_VERSION 84 d=cpu/$SHERPA_ONNX_VERSION
85 85
86 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 86 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
87 cd huggingface 87 cd huggingface
88 git fetch 88 git fetch
89 git pull 89 git pull
@@ -67,7 +67,7 @@ jobs: @@ -67,7 +67,7 @@ jobs:
67 67
68 d=cpu/$SHERPA_ONNX_VERSION 68 d=cpu/$SHERPA_ONNX_VERSION
69 69
70 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 70 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
71 cd huggingface 71 cd huggingface
72 git fetch 72 git fetch
73 git pull 73 git pull
@@ -75,7 +75,7 @@ jobs: @@ -75,7 +75,7 @@ jobs:
75 75
76 d=cuda/$SHERPA_ONNX_VERSION 76 d=cuda/$SHERPA_ONNX_VERSION
77 77
78 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 78 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
79 cd huggingface 79 cd huggingface
80 git fetch 80 git fetch
81 git pull 81 git pull
@@ -73,7 +73,7 @@ jobs: @@ -73,7 +73,7 @@ jobs:
73 73
74 d=cpu/$SHERPA_ONNX_VERSION 74 d=cpu/$SHERPA_ONNX_VERSION
75 75
76 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface 76 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-wheels huggingface
77 cd huggingface 77 cd huggingface
78 git fetch 78 git fetch
79 git pull 79 git pull
@@ -135,7 +135,7 @@ jobs: @@ -135,7 +135,7 @@ jobs:
135 135
136 rm -rf huggingface 136 rm -rf huggingface
137 export GIT_CLONE_PROTECTION_ACTIVE=false 137 export GIT_CLONE_PROTECTION_ACTIVE=false
138 - GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface 138 + GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-libs huggingface
139 139
140 cd huggingface 140 cd huggingface
141 141
@@ -4,8 +4,6 @@ on: @@ -4,8 +4,6 @@ on:
4 push: 4 push:
5 branches: 5 branches:
6 - master 6 - master
7 - tags:  
8 - - 'v[0-9]+.[0-9]+.[0-9]+*'  
9 paths: 7 paths:
10 - '.github/workflows/c-api.yaml' 8 - '.github/workflows/c-api.yaml'
11 - 'CMakeLists.txt' 9 - 'CMakeLists.txt'
  1 +name: cxx-api
  2 +
  3 +on:
  4 + push:
  5 + branches:
  6 + - master
  7 + paths:
  8 + - '.github/workflows/cxx-api.yaml'
  9 + - 'CMakeLists.txt'
  10 + - 'cmake/**'
  11 + - 'sherpa-onnx/csrc/*'
  12 + - 'sherpa-onnx/c-api/*'
  13 + - 'cxx-api-examples/**'
  14 + pull_request:
  15 + branches:
  16 + - master
  17 + paths:
  18 + - '.github/workflows/cxx-api.yaml'
  19 + - 'CMakeLists.txt'
  20 + - 'cmake/**'
  21 + - 'sherpa-onnx/csrc/*'
  22 + - 'sherpa-onnx/c-api/*'
  23 + - 'cxx-api-examples/**'
  24 +
  25 + workflow_dispatch:
  26 +
  27 +concurrency:
  28 + group: cxx-api-${{ github.ref }}
  29 + cancel-in-progress: true
  30 +
  31 +jobs:
  32 + cxx_api:
  33 + name: ${{ matrix.os }}
  34 + runs-on: ${{ matrix.os }}
  35 + strategy:
  36 + fail-fast: false
  37 + matrix:
  38 + os: [ubuntu-latest, macos-latest]
  39 +
  40 + steps:
  41 + - uses: actions/checkout@v4
  42 + with:
  43 + fetch-depth: 0
  44 +
  45 + - name: ccache
  46 + uses: hendrikmuhs/ccache-action@v1.2
  47 + with:
  48 + key: ${{ matrix.os }}-cxx-api-shared
  49 +
  50 + - name: Build sherpa-onnx
  51 + shell: bash
  52 + run: |
  53 + export CMAKE_CXX_COMPILER_LAUNCHER=ccache
  54 + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
  55 + cmake --version
  56 +
  57 + mkdir build
  58 + cd build
  59 +
  60 + cmake \
  61 + -D CMAKE_BUILD_TYPE=Release \
  62 + -D BUILD_SHARED_LIBS=ON \
  63 + -D CMAKE_INSTALL_PREFIX=./install \
  64 + -D SHERPA_ONNX_ENABLE_BINARY=OFF \
  65 + ..
  66 +
  67 + make -j2 install
  68 +
  69 + ls -lh install/lib
  70 + ls -lh install/include
  71 +
  72 + if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
  73 + ldd ./install/lib/libsherpa-onnx-c-api.so
  74 + ldd ./install/lib/libsherpa-onnx-cxx-api.so
  75 + echo "---"
  76 + readelf -d ./install/lib/libsherpa-onnx-c-api.so
  77 + readelf -d ./install/lib/libsherpa-onnx-cxx-api.so
  78 + fi
  79 +
  80 + if [[ ${{ matrix.os }} == macos-latest ]]; then
  81 + otool -L ./install/lib/libsherpa-onnx-c-api.dylib
  82 + otool -L ./install/lib/libsherpa-onnx-cxx-api.dylib
  83 + fi
  84 +
  85 + - name: Test streaming zipformer
  86 + shell: bash
  87 + run: |
  88 + g++ -std=c++17 -o streaming-zipformer-cxx-api ./cxx-api-examples/streaming-zipformer-cxx-api.cc \
  89 + -I ./build/install/include \
  90 + -L ./build/install/lib/ \
  91 + -l sherpa-onnx-cxx-api \
  92 + -l sherpa-onnx-c-api \
  93 + -l onnxruntime
  94 +
  95 + ls -lh streaming-zipformer-cxx-api
  96 +
  97 + if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
  98 + ldd ./streaming-zipformer-cxx-api
  99 + echo "----"
  100 + readelf -d ./streaming-zipformer-cxx-api
  101 + fi
  102 +
  103 + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  104 + tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  105 + rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  106 +
  107 + ls -lh sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
  108 + echo "---"
  109 + ls -lh sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/test_wavs
  110 +
  111 + export LD_LIBRARY_PATH=$PWD/build/install/lib:$LD_LIBRARY_PATH
  112 + export DYLD_LIBRARY_PATH=$PWD/build/install/lib:$DYLD_LIBRARY_PATH
  113 +
  114 + ./streaming-zipformer-cxx-api
  115 +
  116 + rm -rf sherpa-onnx-streaming-zipformer-*
  117 + rm ./streaming-zipformer-cxx-api
@@ -90,7 +90,7 @@ jobs: @@ -90,7 +90,7 @@ jobs:
90 export GIT_CLONE_PROTECTION_ACTIVE=false 90 export GIT_CLONE_PROTECTION_ACTIVE=false
91 export GIT_LFS_SKIP_SMUDGE=1 91 export GIT_LFS_SKIP_SMUDGE=1
92 92
93 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface 93 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-libs huggingface
94 94
95 cd huggingface 95 cd huggingface
96 git fetch 96 git fetch
@@ -59,7 +59,7 @@ jobs: @@ -59,7 +59,7 @@ jobs:
59 d=speaker-embedding-models 59 d=speaker-embedding-models
60 export GIT_LFS_SKIP_SMUDGE=1 60 export GIT_LFS_SKIP_SMUDGE=1
61 export GIT_CLONE_PROTECTION_ACTIVE=false 61 export GIT_CLONE_PROTECTION_ACTIVE=false
62 - git clone https://huggingface.co/csukuangfj/$d huggingface 62 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d huggingface
63 mv -v ./*.onnx ./huggingface 63 mv -v ./*.onnx ./huggingface
64 cd huggingface 64 cd huggingface
65 git lfs track "*.onnx" 65 git lfs track "*.onnx"
@@ -66,7 +66,7 @@ jobs: @@ -66,7 +66,7 @@ jobs:
66 export GIT_LFS_SKIP_SMUDGE=1 66 export GIT_LFS_SKIP_SMUDGE=1
67 d=sherpa-onnx-ced-$m-audio-tagging-2024-04-19 67 d=sherpa-onnx-ced-$m-audio-tagging-2024-04-19
68 export GIT_CLONE_PROTECTION_ACTIVE=false 68 export GIT_CLONE_PROTECTION_ACTIVE=false
69 - git clone https://huggingface.co/k2-fsa/$d huggingface 69 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/k2-fsa/$d huggingface
70 mv -v $d/* huggingface 70 mv -v $d/* huggingface
71 cd huggingface 71 cd huggingface
72 git lfs track "*.onnx" 72 git lfs track "*.onnx"
@@ -56,7 +56,7 @@ jobs: @@ -56,7 +56,7 @@ jobs:
56 src=sherpa-onnx-zipformer-en-libriheavy-20230926-$m 56 src=sherpa-onnx-zipformer-en-libriheavy-20230926-$m
57 echo "Process $src" 57 echo "Process $src"
58 58
59 - git clone https://huggingface.co/csukuangfj/$src huggingface 59 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$src huggingface
60 cd huggingface 60 cd huggingface
61 git fetch 61 git fetch
62 git pull 62 git pull
@@ -100,7 +100,7 @@ jobs: @@ -100,7 +100,7 @@ jobs:
100 src=sherpa-onnx-zipformer-en-libriheavy-20230830-$m-punct-case 100 src=sherpa-onnx-zipformer-en-libriheavy-20230830-$m-punct-case
101 echo "Process $src" 101 echo "Process $src"
102 102
103 - git clone https://huggingface.co/csukuangfj/$src huggingface 103 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$src huggingface
104 cd huggingface 104 cd huggingface
105 git fetch 105 git fetch
106 git pull 106 git pull
@@ -56,7 +56,7 @@ jobs: @@ -56,7 +56,7 @@ jobs:
56 export GIT_LFS_SKIP_SMUDGE=1 56 export GIT_LFS_SKIP_SMUDGE=1
57 export GIT_CLONE_PROTECTION_ACTIVE=false 57 export GIT_CLONE_PROTECTION_ACTIVE=false
58 58
59 - git clone https://huggingface.co/csukuangfj/vits-melo-tts-zh_en huggingface 59 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/vits-melo-tts-zh_en huggingface
60 cd huggingface 60 cd huggingface
61 git fetch 61 git fetch
62 git pull 62 git pull
@@ -67,7 +67,7 @@ jobs: @@ -67,7 +67,7 @@ jobs:
67 rm -rf huggingface 67 rm -rf huggingface
68 export GIT_LFS_SKIP_SMUDGE=1 68 export GIT_LFS_SKIP_SMUDGE=1
69 export GIT_CLONE_PROTECTION_ACTIVE=false 69 export GIT_CLONE_PROTECTION_ACTIVE=false
70 - git clone https://huggingface.co/csukuangfj/$m huggingface 70 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$m huggingface
71 cp -av $m/* huggingface 71 cp -av $m/* huggingface
72 cd huggingface 72 cd huggingface
73 git lfs track "*.onnx" 73 git lfs track "*.onnx"
@@ -67,7 +67,7 @@ jobs: @@ -67,7 +67,7 @@ jobs:
67 rm -rf huggingface 67 rm -rf huggingface
68 export GIT_LFS_SKIP_SMUDGE=1 68 export GIT_LFS_SKIP_SMUDGE=1
69 export GIT_CLONE_PROTECTION_ACTIVE=false 69 export GIT_CLONE_PROTECTION_ACTIVE=false
70 - git clone https://huggingface.co/csukuangfj/$m huggingface 70 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$m huggingface
71 cp -av $m/* huggingface 71 cp -av $m/* huggingface
72 cd huggingface 72 cd huggingface
73 git lfs track "*.onnx" 73 git lfs track "*.onnx"
@@ -59,7 +59,7 @@ jobs: @@ -59,7 +59,7 @@ jobs:
59 d=speaker-embedding-models 59 d=speaker-embedding-models
60 export GIT_LFS_SKIP_SMUDGE=1 60 export GIT_LFS_SKIP_SMUDGE=1
61 export GIT_CLONE_PROTECTION_ACTIVE=false 61 export GIT_CLONE_PROTECTION_ACTIVE=false
62 - git clone https://huggingface.co/csukuangfj/$d huggingface 62 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d huggingface
63 mv -v ./*.onnx ./huggingface 63 mv -v ./*.onnx ./huggingface
64 cd huggingface 64 cd huggingface
65 git lfs track "*.onnx" 65 git lfs track "*.onnx"
@@ -75,7 +75,7 @@ jobs: @@ -75,7 +75,7 @@ jobs:
75 d=sherpa-onnx-pyannote-segmentation-3-0 75 d=sherpa-onnx-pyannote-segmentation-3-0
76 export GIT_LFS_SKIP_SMUDGE=1 76 export GIT_LFS_SKIP_SMUDGE=1
77 export GIT_CLONE_PROTECTION_ACTIVE=false 77 export GIT_CLONE_PROTECTION_ACTIVE=false
78 - git clone https://huggingface.co/csukuangfj/$d huggingface 78 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d huggingface
79 cp -v $d/* ./huggingface 79 cp -v $d/* ./huggingface
80 cd huggingface 80 cd huggingface
81 git lfs track "*.onnx" 81 git lfs track "*.onnx"
@@ -75,7 +75,7 @@ jobs: @@ -75,7 +75,7 @@ jobs:
75 d=sherpa-onnx-reverb-diarization-v1 75 d=sherpa-onnx-reverb-diarization-v1
76 export GIT_LFS_SKIP_SMUDGE=1 76 export GIT_LFS_SKIP_SMUDGE=1
77 export GIT_CLONE_PROTECTION_ACTIVE=false 77 export GIT_CLONE_PROTECTION_ACTIVE=false
78 - git clone https://huggingface.co/csukuangfj/$d huggingface 78 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d huggingface
79 cp -v $d/* ./huggingface 79 cp -v $d/* ./huggingface
80 cd huggingface 80 cd huggingface
81 git lfs track "*.onnx" 81 git lfs track "*.onnx"
@@ -66,7 +66,7 @@ jobs: @@ -66,7 +66,7 @@ jobs:
66 export GIT_LFS_SKIP_SMUDGE=1 66 export GIT_LFS_SKIP_SMUDGE=1
67 export GIT_CLONE_PROTECTION_ACTIVE=false 67 export GIT_CLONE_PROTECTION_ACTIVE=false
68 68
69 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17 huggingface 69 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-sense-voice-zh-en-ja-ko-yue-2024-07-17 huggingface
70 cd huggingface 70 cd huggingface
71 git fetch 71 git fetch
72 git pull 72 git pull
@@ -60,7 +60,7 @@ jobs: @@ -60,7 +60,7 @@ jobs:
60 60
61 export GIT_CLONE_PROTECTION_ACTIVE=false 61 export GIT_CLONE_PROTECTION_ACTIVE=false
62 62
63 - GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-telespeech-ctc-zh-2024-06-04 hf 63 + GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-telespeech-ctc-zh-2024-06-04 hf
64 cp -a $src/* hf/ 64 cp -a $src/* hf/
65 cd hf 65 cd hf
66 git lfs track "*.pdf" 66 git lfs track "*.pdf"
@@ -84,7 +84,7 @@ jobs: @@ -84,7 +84,7 @@ jobs:
84 export GIT_CLONE_PROTECTION_ACTIVE=false 84 export GIT_CLONE_PROTECTION_ACTIVE=false
85 85
86 rm -rf hf 86 rm -rf hf
87 - GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04 hf 87 + GIT_LFS_SKIP_SMUDGE=1 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04 hf
88 cp -a $src/* hf/ 88 cp -a $src/* hf/
89 cd hf 89 cd hf
90 git lfs track "*.pdf" 90 git lfs track "*.pdf"
@@ -49,7 +49,7 @@ jobs: @@ -49,7 +49,7 @@ jobs:
49 export GIT_LFS_SKIP_SMUDGE=1 49 export GIT_LFS_SKIP_SMUDGE=1
50 export GIT_CLONE_PROTECTION_ACTIVE=false 50 export GIT_CLONE_PROTECTION_ACTIVE=false
51 51
52 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-aishell huggingface 52 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-aishell huggingface
53 cd huggingface 53 cd huggingface
54 git fetch 54 git fetch
55 git pull 55 git pull
@@ -98,7 +98,7 @@ jobs: @@ -98,7 +98,7 @@ jobs:
98 export GIT_LFS_SKIP_SMUDGE=1 98 export GIT_LFS_SKIP_SMUDGE=1
99 export GIT_CLONE_PROTECTION_ACTIVE=false 99 export GIT_CLONE_PROTECTION_ACTIVE=false
100 100
101 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-aishell2 huggingface 101 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-aishell2 huggingface
102 cd huggingface 102 cd huggingface
103 git fetch 103 git fetch
104 git pull 104 git pull
@@ -147,7 +147,7 @@ jobs: @@ -147,7 +147,7 @@ jobs:
147 export GIT_LFS_SKIP_SMUDGE=1 147 export GIT_LFS_SKIP_SMUDGE=1
148 export GIT_CLONE_PROTECTION_ACTIVE=false 148 export GIT_CLONE_PROTECTION_ACTIVE=false
149 149
150 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-multi-cn huggingface 150 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-multi-cn huggingface
151 cd huggingface 151 cd huggingface
152 git fetch 152 git fetch
153 git pull 153 git pull
@@ -196,7 +196,7 @@ jobs: @@ -196,7 +196,7 @@ jobs:
196 export GIT_LFS_SKIP_SMUDGE=1 196 export GIT_LFS_SKIP_SMUDGE=1
197 export GIT_CLONE_PROTECTION_ACTIVE=false 197 export GIT_CLONE_PROTECTION_ACTIVE=false
198 198
199 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-wenetspeech huggingface 199 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-zh-wenet-wenetspeech huggingface
200 cd huggingface 200 cd huggingface
201 git fetch 201 git fetch
202 git pull 202 git pull
@@ -245,7 +245,7 @@ jobs: @@ -245,7 +245,7 @@ jobs:
245 export GIT_LFS_SKIP_SMUDGE=1 245 export GIT_LFS_SKIP_SMUDGE=1
246 export GIT_CLONE_PROTECTION_ACTIVE=false 246 export GIT_CLONE_PROTECTION_ACTIVE=false
247 247
248 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-en-wenet-librispeech huggingface 248 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-en-wenet-librispeech huggingface
249 cd huggingface 249 cd huggingface
250 git fetch 250 git fetch
251 git pull 251 git pull
@@ -295,7 +295,7 @@ jobs: @@ -295,7 +295,7 @@ jobs:
295 export GIT_LFS_SKIP_SMUDGE=1 295 export GIT_LFS_SKIP_SMUDGE=1
296 export GIT_CLONE_PROTECTION_ACTIVE=false 296 export GIT_CLONE_PROTECTION_ACTIVE=false
297 297
298 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-en-wenet-gigaspeech huggingface 298 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-en-wenet-gigaspeech huggingface
299 cd huggingface 299 cd huggingface
300 git fetch 300 git fetch
301 git pull 301 git pull
@@ -64,7 +64,7 @@ jobs: @@ -64,7 +64,7 @@ jobs:
64 d=speaker-embedding-models 64 d=speaker-embedding-models
65 export GIT_LFS_SKIP_SMUDGE=1 65 export GIT_LFS_SKIP_SMUDGE=1
66 export GIT_CLONE_PROTECTION_ACTIVE=false 66 export GIT_CLONE_PROTECTION_ACTIVE=false
67 - git clone https://huggingface.co/csukuangfj/$d huggingface 67 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d huggingface
68 mv -v ./*.onnx ./huggingface 68 mv -v ./*.onnx ./huggingface
69 cd huggingface 69 cd huggingface
70 git lfs track "*.onnx" 70 git lfs track "*.onnx"
@@ -145,7 +145,7 @@ jobs: @@ -145,7 +145,7 @@ jobs:
145 145
146 export GIT_LFS_SKIP_SMUDGE=1 146 export GIT_LFS_SKIP_SMUDGE=1
147 147
148 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-whisper-${{ matrix.model }} huggingface 148 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-whisper-${{ matrix.model }} huggingface
149 149
150 rm -rf huggingface/* 150 rm -rf huggingface/*
151 151
@@ -214,7 +214,7 @@ jobs: @@ -214,7 +214,7 @@ jobs:
214 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 214 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
215 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 215 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
216 216
217 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface 217 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface
218 cd huggingface 218 cd huggingface
219 git fetch 219 git fetch
220 git pull 220 git pull
@@ -261,7 +261,7 @@ jobs: @@ -261,7 +261,7 @@ jobs:
261 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 261 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
262 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 262 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
263 263
264 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface 264 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface
265 cd huggingface 265 cd huggingface
266 git fetch 266 git fetch
267 git pull 267 git pull
@@ -101,7 +101,7 @@ jobs: @@ -101,7 +101,7 @@ jobs:
101 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 101 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
102 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 102 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
103 103
104 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface 104 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface
105 cd huggingface 105 cd huggingface
106 git fetch 106 git fetch
107 git pull 107 git pull
@@ -207,7 +207,7 @@ jobs: @@ -207,7 +207,7 @@ jobs:
207 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 207 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
208 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 208 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
209 209
210 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface 210 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface
211 cd huggingface 211 cd huggingface
212 git fetch 212 git fetch
213 git pull 213 git pull
@@ -94,7 +94,7 @@ jobs: @@ -94,7 +94,7 @@ jobs:
94 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 94 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
95 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 95 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
96 96
97 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface 97 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface
98 cd huggingface 98 cd huggingface
99 git fetch 99 git fetch
100 git pull 100 git pull
@@ -192,7 +192,7 @@ jobs: @@ -192,7 +192,7 @@ jobs:
192 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 192 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
193 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 193 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
194 194
195 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface 195 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface
196 cd huggingface 196 cd huggingface
197 git fetch 197 git fetch
198 git pull 198 git pull
@@ -355,7 +355,7 @@ jobs: @@ -355,7 +355,7 @@ jobs:
355 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) 355 SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
356 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" 356 echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION"
357 357
358 - git clone https://huggingface.co/csukuangfj/sherpa-onnx-bin huggingface 358 + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-bin huggingface
359 cd huggingface 359 cd huggingface
360 git fetch 360 git fetch
361 git pull 361 git pull
@@ -19,6 +19,8 @@ on: @@ -19,6 +19,8 @@ on:
19 - '.github/scripts/test-offline-punctuation.sh' 19 - '.github/scripts/test-offline-punctuation.sh'
20 - '.github/scripts/test-online-punctuation.sh' 20 - '.github/scripts/test-online-punctuation.sh'
21 - '.github/scripts/test-speaker-diarization.sh' 21 - '.github/scripts/test-speaker-diarization.sh'
  22 + - '.github/scripts/test-c-api.sh'
  23 + - '.github/scripts/test-cxx-api.sh'
22 - 'CMakeLists.txt' 24 - 'CMakeLists.txt'
23 - 'cmake/**' 25 - 'cmake/**'
24 - 'sherpa-onnx/csrc/*' 26 - 'sherpa-onnx/csrc/*'
@@ -40,6 +42,8 @@ on: @@ -40,6 +42,8 @@ on:
40 - '.github/scripts/test-offline-punctuation.sh' 42 - '.github/scripts/test-offline-punctuation.sh'
41 - '.github/scripts/test-online-punctuation.sh' 43 - '.github/scripts/test-online-punctuation.sh'
42 - '.github/scripts/test-speaker-diarization.sh' 44 - '.github/scripts/test-speaker-diarization.sh'
  45 + - '.github/scripts/test-c-api.sh'
  46 + - '.github/scripts/test-cxx-api.sh'
43 - 'CMakeLists.txt' 47 - 'CMakeLists.txt'
44 - 'cmake/**' 48 - 'cmake/**'
45 - 'sherpa-onnx/csrc/*' 49 - 'sherpa-onnx/csrc/*'
@@ -145,6 +149,16 @@ jobs: @@ -145,6 +149,16 @@ jobs:
145 name: release-${{ matrix.build_type }}-with-shared-lib-${{ matrix.shared_lib }}-with-tts-${{ matrix.with_tts }} 149 name: release-${{ matrix.build_type }}-with-shared-lib-${{ matrix.shared_lib }}-with-tts-${{ matrix.with_tts }}
146 path: install/* 150 path: install/*
147 151
  152 + - name: Test C++ API
  153 + shell: bash
  154 + run: |
  155 + du -h -d1 .
  156 + export PATH=$PWD/build/bin:$PATH
  157 + export CXX_STREAMING_ZIPFORMER_EXE=streaming-zipformer-cxx-api
  158 +
  159 + .github/scripts/test-cxx-api.sh
  160 + du -h -d1 .
  161 +
148 - name: Test offline speaker diarization 162 - name: Test offline speaker diarization
149 shell: bash 163 shell: bash
150 run: | 164 run: |
@@ -19,6 +19,8 @@ on: @@ -19,6 +19,8 @@ on:
19 - '.github/scripts/test-offline-punctuation.sh' 19 - '.github/scripts/test-offline-punctuation.sh'
20 - '.github/scripts/test-online-punctuation.sh' 20 - '.github/scripts/test-online-punctuation.sh'
21 - '.github/scripts/test-speaker-diarization.sh' 21 - '.github/scripts/test-speaker-diarization.sh'
  22 + - '.github/scripts/test-c-api.sh'
  23 + - '.github/scripts/test-cxx-api.sh'
22 - 'CMakeLists.txt' 24 - 'CMakeLists.txt'
23 - 'cmake/**' 25 - 'cmake/**'
24 - 'sherpa-onnx/csrc/*' 26 - 'sherpa-onnx/csrc/*'
@@ -39,6 +41,8 @@ on: @@ -39,6 +41,8 @@ on:
39 - '.github/scripts/test-offline-punctuation.sh' 41 - '.github/scripts/test-offline-punctuation.sh'
40 - '.github/scripts/test-online-punctuation.sh' 42 - '.github/scripts/test-online-punctuation.sh'
41 - '.github/scripts/test-speaker-diarization.sh' 43 - '.github/scripts/test-speaker-diarization.sh'
  44 + - '.github/scripts/test-c-api.sh'
  45 + - '.github/scripts/test-cxx-api.sh'
42 - 'CMakeLists.txt' 46 - 'CMakeLists.txt'
43 - 'cmake/**' 47 - 'cmake/**'
44 - 'sherpa-onnx/csrc/*' 48 - 'sherpa-onnx/csrc/*'
@@ -117,6 +121,16 @@ jobs: @@ -117,6 +121,16 @@ jobs:
117 otool -L build/bin/sherpa-onnx 121 otool -L build/bin/sherpa-onnx
118 otool -l build/bin/sherpa-onnx 122 otool -l build/bin/sherpa-onnx
119 123
  124 + - name: Test C++ API
  125 + shell: bash
  126 + run: |
  127 + du -h -d1 .
  128 + export PATH=$PWD/build/bin:$PATH
  129 + export CXX_STREAMING_ZIPFORMER_EXE=streaming-zipformer-cxx-api
  130 +
  131 + .github/scripts/test-cxx-api.sh
  132 + du -h -d1 .
  133 +
120 - name: Test offline speaker diarization 134 - name: Test offline speaker diarization
121 shell: bash 135 shell: bash
122 run: | 136 run: |
@@ -76,6 +76,14 @@ jobs: @@ -76,6 +76,14 @@ jobs:
76 otool -L build/bin/sherpa-onnx 76 otool -L build/bin/sherpa-onnx
77 otool -l build/bin/sherpa-onnx 77 otool -l build/bin/sherpa-onnx
78 78
  79 + - name: Test C++ API
  80 + shell: bash
  81 + run: |
  82 + export PATH=$PWD/build/bin:$PATH
  83 + export CXX_STREAMING_ZIPFORMER_EXE=streaming-zipformer-cxx-api
  84 +
  85 + .github/scripts/test-cxx-api.sh
  86 +
79 - name: Test online punctuation 87 - name: Test online punctuation
80 shell: bash 88 shell: bash
81 run: | 89 run: |
@@ -109,7 +117,6 @@ jobs: @@ -109,7 +117,6 @@ jobs:
109 .github/scripts/test-online-ctc.sh 117 .github/scripts/test-online-ctc.sh
110 118
111 119
112 -  
113 - name: Test C API 120 - name: Test C API
114 shell: bash 121 shell: bash
115 run: | 122 run: |
@@ -18,6 +18,8 @@ on: @@ -18,6 +18,8 @@ on:
18 - '.github/scripts/test-offline-punctuation.sh' 18 - '.github/scripts/test-offline-punctuation.sh'
19 - '.github/scripts/test-online-punctuation.sh' 19 - '.github/scripts/test-online-punctuation.sh'
20 - '.github/scripts/test-speaker-diarization.sh' 20 - '.github/scripts/test-speaker-diarization.sh'
  21 + - '.github/scripts/test-c-api.sh'
  22 + - '.github/scripts/test-cxx-api.sh'
21 - 'CMakeLists.txt' 23 - 'CMakeLists.txt'
22 - 'cmake/**' 24 - 'cmake/**'
23 - 'sherpa-onnx/csrc/*' 25 - 'sherpa-onnx/csrc/*'
@@ -36,6 +38,8 @@ on: @@ -36,6 +38,8 @@ on:
36 - '.github/scripts/test-offline-punctuation.sh' 38 - '.github/scripts/test-offline-punctuation.sh'
37 - '.github/scripts/test-online-punctuation.sh' 39 - '.github/scripts/test-online-punctuation.sh'
38 - '.github/scripts/test-speaker-diarization.sh' 40 - '.github/scripts/test-speaker-diarization.sh'
  41 + - '.github/scripts/test-c-api.sh'
  42 + - '.github/scripts/test-cxx-api.sh'
39 - 'CMakeLists.txt' 43 - 'CMakeLists.txt'
40 - 'cmake/**' 44 - 'cmake/**'
41 - 'sherpa-onnx/csrc/*' 45 - 'sherpa-onnx/csrc/*'
@@ -89,10 +93,17 @@ jobs: @@ -89,10 +93,17 @@ jobs:
89 name: release-windows-x64-${{ matrix.shared_lib }}-${{ matrix.with_tts }} 93 name: release-windows-x64-${{ matrix.shared_lib }}-${{ matrix.with_tts }}
90 path: build/install/* 94 path: build/install/*
91 95
  96 + - name: Test C++ API
  97 + shell: bash
  98 + run: |
  99 + export PATH=$PWD/build/bin/Release:$PATH
  100 + export CXX_STREAMING_ZIPFORMER_EXE=streaming-zipformer-cxx-api.exe
  101 +
  102 + .github/scripts/test-cxx-api.sh
  103 +
92 - name: Test offline speaker diarization 104 - name: Test offline speaker diarization
93 shell: bash 105 shell: bash
94 run: | 106 run: |
95 - du -h -d1 .  
96 export PATH=$PWD/build/bin/Release:$PATH 107 export PATH=$PWD/build/bin/Release:$PATH
97 export EXE=sherpa-onnx-offline-speaker-diarization.exe 108 export EXE=sherpa-onnx-offline-speaker-diarization.exe
98 109
@@ -18,6 +18,8 @@ on: @@ -18,6 +18,8 @@ on:
18 - '.github/scripts/test-offline-punctuation.sh' 18 - '.github/scripts/test-offline-punctuation.sh'
19 - '.github/scripts/test-online-punctuation.sh' 19 - '.github/scripts/test-online-punctuation.sh'
20 - '.github/scripts/test-speaker-diarization.sh' 20 - '.github/scripts/test-speaker-diarization.sh'
  21 + - '.github/scripts/test-c-api.sh'
  22 + - '.github/scripts/test-cxx-api.sh'
21 - 'CMakeLists.txt' 23 - 'CMakeLists.txt'
22 - 'cmake/**' 24 - 'cmake/**'
23 - 'sherpa-onnx/csrc/*' 25 - 'sherpa-onnx/csrc/*'
@@ -36,6 +38,8 @@ on: @@ -36,6 +38,8 @@ on:
36 - '.github/scripts/test-offline-punctuation.sh' 38 - '.github/scripts/test-offline-punctuation.sh'
37 - '.github/scripts/test-online-punctuation.sh' 39 - '.github/scripts/test-online-punctuation.sh'
38 - '.github/scripts/test-speaker-diarization.sh' 40 - '.github/scripts/test-speaker-diarization.sh'
  41 + - '.github/scripts/test-c-api.sh'
  42 + - '.github/scripts/test-cxx-api.sh'
39 - 'CMakeLists.txt' 43 - 'CMakeLists.txt'
40 - 'cmake/**' 44 - 'cmake/**'
41 - 'sherpa-onnx/csrc/*' 45 - 'sherpa-onnx/csrc/*'
@@ -89,10 +93,17 @@ jobs: @@ -89,10 +93,17 @@ jobs:
89 name: release-windows-x86-${{ matrix.shared_lib }}-${{ matrix.with_tts }} 93 name: release-windows-x86-${{ matrix.shared_lib }}-${{ matrix.with_tts }}
90 path: build/install/* 94 path: build/install/*
91 95
  96 + - name: Test C++ API
  97 + shell: bash
  98 + run: |
  99 + export PATH=$PWD/build/bin/Release:$PATH
  100 + export CXX_STREAMING_ZIPFORMER_EXE=streaming-zipformer-cxx-api.exe
  101 +
  102 + .github/scripts/test-cxx-api.sh
  103 +
92 - name: Test offline speaker diarization 104 - name: Test offline speaker diarization
93 shell: bash 105 shell: bash
94 run: | 106 run: |
95 - du -h -d1 .  
96 export PATH=$PWD/build/bin/Release:$PATH 107 export PATH=$PWD/build/bin/Release:$PATH
97 export EXE=sherpa-onnx-offline-speaker-diarization.exe 108 export EXE=sherpa-onnx-offline-speaker-diarization.exe
98 109
@@ -51,9 +51,11 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") @@ -51,9 +51,11 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
51 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 51 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
52 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 52 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
53 53
54 -set(CMAKE_SKIP_BUILD_RPATH FALSE)  
55 -set(BUILD_RPATH_USE_ORIGIN TRUE)  
56 -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 54 +if(NOT WIN32)
  55 + set(CMAKE_SKIP_BUILD_RPATH FALSE)
  56 + set(BUILD_RPATH_USE_ORIGIN TRUE)
  57 + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  58 +endif()
57 59
58 if(NOT APPLE) 60 if(NOT APPLE)
59 set(SHERPA_ONNX_RPATH_ORIGIN "$ORIGIN") 61 set(SHERPA_ONNX_RPATH_ORIGIN "$ORIGIN")
@@ -399,6 +401,7 @@ add_subdirectory(sherpa-onnx) @@ -399,6 +401,7 @@ add_subdirectory(sherpa-onnx)
399 if(SHERPA_ONNX_ENABLE_C_API AND SHERPA_ONNX_ENABLE_BINARY AND SHERPA_ONNX_BUILD_C_API_EXAMPLES) 401 if(SHERPA_ONNX_ENABLE_C_API AND SHERPA_ONNX_ENABLE_BINARY AND SHERPA_ONNX_BUILD_C_API_EXAMPLES)
400 set(SHERPA_ONNX_PKG_WITH_CARGS "-lcargs") 402 set(SHERPA_ONNX_PKG_WITH_CARGS "-lcargs")
401 add_subdirectory(c-api-examples) 403 add_subdirectory(c-api-examples)
  404 + add_subdirectory(cxx-api-examples)
402 endif() 405 endif()
403 406
404 if(SHERPA_ONNX_ENABLE_WASM) 407 if(SHERPA_ONNX_ENABLE_WASM)
@@ -95,7 +95,7 @@ int32_t main() { @@ -95,7 +95,7 @@ int32_t main() {
95 recognizer_config.decoding_method = "greedy_search"; 95 recognizer_config.decoding_method = "greedy_search";
96 recognizer_config.model_config = online_model_config; 96 recognizer_config.model_config = online_model_config;
97 97
98 - SherpaOnnxOnlineRecognizer *recognizer = 98 + const SherpaOnnxOnlineRecognizer *recognizer =
99 SherpaOnnxCreateOnlineRecognizer(&recognizer_config); 99 SherpaOnnxCreateOnlineRecognizer(&recognizer_config);
100 100
101 free((void *)tokens_buf); 101 free((void *)tokens_buf);
@@ -96,7 +96,7 @@ int32_t main() { @@ -96,7 +96,7 @@ int32_t main() {
96 recognizer_config.decoding_method = "greedy_search"; 96 recognizer_config.decoding_method = "greedy_search";
97 recognizer_config.model_config = online_model_config; 97 recognizer_config.model_config = online_model_config;
98 98
99 - SherpaOnnxOnlineRecognizer *recognizer = 99 + const SherpaOnnxOnlineRecognizer *recognizer =
100 SherpaOnnxCreateOnlineRecognizer(&recognizer_config); 100 SherpaOnnxCreateOnlineRecognizer(&recognizer_config);
101 101
102 free((void *)tokens_buf); 102 free((void *)tokens_buf);
@@ -57,7 +57,7 @@ int32_t main() { @@ -57,7 +57,7 @@ int32_t main() {
57 recognizer_config.decoding_method = "greedy_search"; 57 recognizer_config.decoding_method = "greedy_search";
58 recognizer_config.model_config = online_model_config; 58 recognizer_config.model_config = online_model_config;
59 59
60 - SherpaOnnxOnlineRecognizer *recognizer = 60 + const SherpaOnnxOnlineRecognizer *recognizer =
61 SherpaOnnxCreateOnlineRecognizer(&recognizer_config); 61 SherpaOnnxCreateOnlineRecognizer(&recognizer_config);
62 62
63 if (recognizer == NULL) { 63 if (recognizer == NULL) {
@@ -116,7 +116,7 @@ int32_t main() { @@ -116,7 +116,7 @@ int32_t main() {
116 recognizer_config.hotwords_buf = hotwords_buf; 116 recognizer_config.hotwords_buf = hotwords_buf;
117 recognizer_config.hotwords_buf_size = hotwords_buf_size; 117 recognizer_config.hotwords_buf_size = hotwords_buf_size;
118 118
119 - SherpaOnnxOnlineRecognizer *recognizer = 119 + const SherpaOnnxOnlineRecognizer *recognizer =
120 SherpaOnnxCreateOnlineRecognizer(&recognizer_config); 120 SherpaOnnxCreateOnlineRecognizer(&recognizer_config);
121 121
122 free((void *)tokens_buf); 122 free((void *)tokens_buf);
@@ -63,7 +63,7 @@ int32_t main() { @@ -63,7 +63,7 @@ int32_t main() {
63 recognizer_config.decoding_method = "greedy_search"; 63 recognizer_config.decoding_method = "greedy_search";
64 recognizer_config.model_config = online_model_config; 64 recognizer_config.model_config = online_model_config;
65 65
66 - SherpaOnnxOnlineRecognizer *recognizer = 66 + const SherpaOnnxOnlineRecognizer *recognizer =
67 SherpaOnnxCreateOnlineRecognizer(&recognizer_config); 67 SherpaOnnxCreateOnlineRecognizer(&recognizer_config);
68 68
69 if (recognizer == NULL) { 69 if (recognizer == NULL) {
@@ -80,6 +80,7 @@ def get_binaries(): @@ -80,6 +80,7 @@ def get_binaries():
80 binaries += [ 80 binaries += [
81 "onnxruntime.dll", 81 "onnxruntime.dll",
82 "sherpa-onnx-c-api.dll", 82 "sherpa-onnx-c-api.dll",
  83 + "sherpa-onnx-cxx-api.dll",
83 ] 84 ]
84 85
85 return binaries 86 return binaries
  1 +include_directories(${CMAKE_SOURCE_DIR})
  2 +
  3 +add_executable(streaming-zipformer-cxx-api ./streaming-zipformer-cxx-api.cc)
  4 +target_link_libraries(streaming-zipformer-cxx-api sherpa-onnx-cxx-api)
  1 +// cxx-api-examples/streaming-zipformer-cxx-api.cc
  2 +// Copyright (c) 2024 Xiaomi Corporation
  3 +
  4 +//
  5 +// This file demonstrates how to use streaming Zipformer
  6 +// with sherpa-onnx's C++ API.
  7 +//
  8 +// clang-format off
  9 +//
  10 +// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  11 +// tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  12 +// rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
  13 +//
  14 +// clang-format on
  15 +
  16 +#include <chrono> // NOLINT
  17 +#include <iostream>
  18 +#include <string>
  19 +
  20 +#include "sherpa-onnx/c-api/cxx-api.h"
  21 +
  22 +int32_t main() {
  23 + using namespace sherpa_onnx::cxx;
  24 + OnlineRecognizerConfig config;
  25 +
  26 + // please see
  27 + // https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#csukuangfj-sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20-bilingual-chinese-english
  28 + config.model_config.transducer.encoder =
  29 + "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
  30 + "encoder-epoch-99-avg-1.int8.onnx";
  31 +
  32 + // Note: We recommend not using int8.onnx for the decoder.
  33 + config.model_config.transducer.decoder =
  34 + "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
  35 + "decoder-epoch-99-avg-1.onnx";
  36 +
  37 + config.model_config.transducer.joiner =
  38 + "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/"
  39 + "joiner-epoch-99-avg-1.int8.onnx";
  40 +
  41 + config.model_config.tokens =
  42 + "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/tokens.txt";
  43 +
  44 + config.model_config.num_threads = 1;
  45 +
  46 + std::cout << "Loading model\n";
  47 + OnlineRecognizer recongizer = OnlineRecognizer::Create(config);
  48 + if (!recongizer.Get()) {
  49 + std::cerr << "Please check your config\n";
  50 + return -1;
  51 + }
  52 + std::cout << "Loading model done\n";
  53 +
  54 + std::string wave_filename =
  55 + "./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/test_wavs/"
  56 + "0.wav";
  57 + Wave wave = ReadWave(wave_filename);
  58 + if (wave.samples.empty()) {
  59 + std::cerr << "Failed to read: '" << wave_filename << "'\n";
  60 + return -1;
  61 + }
  62 +
  63 + std::cout << "Start recognition\n";
  64 + const auto begin = std::chrono::steady_clock::now();
  65 +
  66 + OnlineStream stream = recongizer.CreateStream();
  67 + stream.AcceptWaveform(wave.sample_rate, wave.samples.data(),
  68 + wave.samples.size());
  69 + while (recongizer.IsReady(&stream)) {
  70 + recongizer.Decode(&stream);
  71 + }
  72 +
  73 + OnlineRecognizerResult result = recongizer.GetResult(&stream);
  74 +
  75 + const auto end = std::chrono::steady_clock::now();
  76 + const float elapsed_seconds =
  77 + std::chrono::duration_cast<std::chrono::milliseconds>(end - begin)
  78 + .count() /
  79 + 1000.;
  80 + float duration = wave.samples.size() / static_cast<float>(wave.sample_rate);
  81 + float rtf = elapsed_seconds / duration;
  82 +
  83 + std::cout << "text: " << result.text << "\n";
  84 + printf("Number of threads: %d\n", config.model_config.num_threads);
  85 + printf("Duration: %.3fs\n", duration);
  86 + printf("Elapsed seconds: %.3fs\n", elapsed_seconds);
  87 + printf("(Real time factor) RTF = %.3f / %.3f = %.3f\n", elapsed_seconds,
  88 + duration, rtf);
  89 +
  90 + return 0;
  91 +}
@@ -290,7 +290,7 @@ int main(int argc, char **argv) { @@ -290,7 +290,7 @@ int main(int argc, char **argv) {
290 } 290 }
291 291
292 SherpaOnnxOnlineRecognizerConfig config; 292 SherpaOnnxOnlineRecognizerConfig config;
293 - memset(&config, 0, sizeof(config)); 293 + memset(&config, 0, sizeof(config));
294 config.model_config.tokens = argv[1]; 294 config.model_config.tokens = argv[1];
295 config.model_config.transducer.encoder = argv[2]; 295 config.model_config.transducer.encoder = argv[2];
296 config.model_config.transducer.decoder = argv[3]; 296 config.model_config.transducer.decoder = argv[3];
@@ -318,7 +318,7 @@ int main(int argc, char **argv) { @@ -318,7 +318,7 @@ int main(int argc, char **argv) {
318 config.rule2_min_trailing_silence = 1.2; 318 config.rule2_min_trailing_silence = 1.2;
319 config.rule3_min_utterance_length = 300; 319 config.rule3_min_utterance_length = 300;
320 320
321 - SherpaOnnxOnlineRecognizer *recognizer = 321 + const SherpaOnnxOnlineRecognizer *recognizer =
322 SherpaOnnxCreateOnlineRecognizer(&config); 322 SherpaOnnxCreateOnlineRecognizer(&config);
323 SherpaOnnxOnlineStream *stream = SherpaOnnxCreateOnlineStream(recognizer); 323 SherpaOnnxOnlineStream *stream = SherpaOnnxCreateOnlineStream(recognizer);
324 const SherpaOnnxDisplay *display = SherpaOnnxCreateDisplay(50); 324 const SherpaOnnxDisplay *display = SherpaOnnxCreateDisplay(50);
@@ -45,7 +45,7 @@ class CStreamingSpeechRecognitionDlg : public CDialogEx { @@ -45,7 +45,7 @@ class CStreamingSpeechRecognitionDlg : public CDialogEx {
45 private: 45 private:
46 Microphone mic_; 46 Microphone mic_;
47 47
48 - SherpaOnnxOnlineRecognizer *recognizer_ = nullptr; 48 + const SherpaOnnxOnlineRecognizer *recognizer_ = nullptr;
49 49
50 PaStream *pa_stream_ = nullptr; 50 PaStream *pa_stream_ = nullptr;
51 RecognizerThread *thread_ = nullptr; 51 RecognizerThread *thread_ = nullptr;
@@ -54,7 +54,7 @@ class CStreamingSpeechRecognitionDlg : public CDialogEx { @@ -54,7 +54,7 @@ class CStreamingSpeechRecognitionDlg : public CDialogEx {
54 54
55 public: 55 public:
56 bool started_ = false; 56 bool started_ = false;
57 - SherpaOnnxOnlineStream *stream_ = nullptr; 57 + const SherpaOnnxOnlineStream *stream_ = nullptr;
58 58
59 public: 59 public:
60 int RunThread(); 60 int RunThread();
@@ -79,4 +79,4 @@ class RecognizerThread : public CWinThread { @@ -79,4 +79,4 @@ class RecognizerThread : public CWinThread {
79 79
80 private: 80 private:
81 CStreamingSpeechRecognitionDlg *dlg_; 81 CStreamingSpeechRecognitionDlg *dlg_;
82 -};  
  82 +};
@@ -199,7 +199,8 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper( @@ -199,7 +199,8 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper(
199 199
200 c.ctc_fst_decoder_config = GetCtcFstDecoderConfig(o); 200 c.ctc_fst_decoder_config = GetCtcFstDecoderConfig(o);
201 201
202 - SherpaOnnxOnlineRecognizer *recognizer = SherpaOnnxCreateOnlineRecognizer(&c); 202 + const SherpaOnnxOnlineRecognizer *recognizer =
  203 + SherpaOnnxCreateOnlineRecognizer(&c);
203 204
204 if (c.model_config.transducer.encoder) { 205 if (c.model_config.transducer.encoder) {
205 delete[] c.model_config.transducer.encoder; 206 delete[] c.model_config.transducer.encoder;
@@ -281,7 +282,7 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper( @@ -281,7 +282,7 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper(
281 } 282 }
282 283
283 return Napi::External<SherpaOnnxOnlineRecognizer>::New( 284 return Napi::External<SherpaOnnxOnlineRecognizer>::New(
284 - env, recognizer, 285 + env, const_cast<SherpaOnnxOnlineRecognizer *>(recognizer),
285 [](Napi::Env env, SherpaOnnxOnlineRecognizer *recognizer) { 286 [](Napi::Env env, SherpaOnnxOnlineRecognizer *recognizer) {
286 SherpaOnnxDestroyOnlineRecognizer(recognizer); 287 SherpaOnnxDestroyOnlineRecognizer(recognizer);
287 }); 288 });
@@ -3,12 +3,25 @@ add_library(sherpa-onnx-c-api c-api.cc) @@ -3,12 +3,25 @@ add_library(sherpa-onnx-c-api c-api.cc)
3 target_link_libraries(sherpa-onnx-c-api sherpa-onnx-core) 3 target_link_libraries(sherpa-onnx-c-api sherpa-onnx-core)
4 4
5 if(BUILD_SHARED_LIBS) 5 if(BUILD_SHARED_LIBS)
6 - target_compile_definitions(sherpa-onnx-c-api PRIVATE SHERPA_ONNX_BUILD_SHARED_LIBS=1)  
7 - target_compile_definitions(sherpa-onnx-c-api PRIVATE SHERPA_ONNX_BUILD_MAIN_LIB=1) 6 + target_compile_definitions(sherpa-onnx-c-api PUBLIC SHERPA_ONNX_BUILD_SHARED_LIBS=1)
  7 + target_compile_definitions(sherpa-onnx-c-api PUBLIC SHERPA_ONNX_BUILD_MAIN_LIB=1)
8 endif() 8 endif()
9 9
10 -install(TARGETS sherpa-onnx-c-api DESTINATION lib) 10 +add_library(sherpa-onnx-cxx-api cxx-api.cc)
  11 +target_link_libraries(sherpa-onnx-cxx-api sherpa-onnx-c-api)
11 12
12 -install(FILES c-api.h  
13 - DESTINATION include/sherpa-onnx/c-api 13 +install(
  14 + TARGETS
  15 + sherpa-onnx-c-api
  16 + sherpa-onnx-cxx-api
  17 + DESTINATION
  18 + lib
  19 +)
  20 +
  21 +install(
  22 + FILES
  23 + c-api.h
  24 + cxx-api.h
  25 + DESTINATION
  26 + include/sherpa-onnx/c-api
14 ) 27 )
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 #include "sherpa-onnx/c-api/c-api.h" 5 #include "sherpa-onnx/c-api/c-api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
  8 +#include <cstring>
8 #include <memory> 9 #include <memory>
9 #include <string> 10 #include <string>
10 #include <utility> 11 #include <utility>
@@ -51,7 +52,7 @@ struct SherpaOnnxDisplay { @@ -51,7 +52,7 @@ struct SherpaOnnxDisplay {
51 52
52 #define SHERPA_ONNX_OR(x, y) (x ? x : y) 53 #define SHERPA_ONNX_OR(x, y) (x ? x : y)
53 54
54 -SherpaOnnxOnlineRecognizer *SherpaOnnxCreateOnlineRecognizer( 55 +const SherpaOnnxOnlineRecognizer *SherpaOnnxCreateOnlineRecognizer(
55 const SherpaOnnxOnlineRecognizerConfig *config) { 56 const SherpaOnnxOnlineRecognizerConfig *config) {
56 sherpa_onnx::OnlineRecognizerConfig recognizer_config; 57 sherpa_onnx::OnlineRecognizerConfig recognizer_config;
57 58
@@ -205,7 +205,8 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOnlineStream SherpaOnnxOnlineStream; @@ -205,7 +205,8 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOnlineStream SherpaOnnxOnlineStream;
205 /// @param config Config for the recognizer. 205 /// @param config Config for the recognizer.
206 /// @return Return a pointer to the recognizer. The user has to invoke 206 /// @return Return a pointer to the recognizer. The user has to invoke
207 // SherpaOnnxDestroyOnlineRecognizer() to free it to avoid memory leak. 207 // SherpaOnnxDestroyOnlineRecognizer() to free it to avoid memory leak.
208 -SHERPA_ONNX_API SherpaOnnxOnlineRecognizer *SherpaOnnxCreateOnlineRecognizer( 208 +SHERPA_ONNX_API const SherpaOnnxOnlineRecognizer *
  209 +SherpaOnnxCreateOnlineRecognizer(
209 const SherpaOnnxOnlineRecognizerConfig *config); 210 const SherpaOnnxOnlineRecognizerConfig *config);
210 211
211 /// Free a pointer returned by SherpaOnnxCreateOnlineRecognizer() 212 /// Free a pointer returned by SherpaOnnxCreateOnlineRecognizer()
  1 +// sherpa-onnx/c-api/cxx-api.cc
  2 +//
  3 +// Copyright (c) 2024 Xiaomi Corporation
  4 +#include "sherpa-onnx/c-api/cxx-api.h"
  5 +
  6 +#include <algorithm>
  7 +#include <cstring>
  8 +
  9 +namespace sherpa_onnx::cxx {
  10 +
  11 +Wave ReadWave(const std::string &filename) {
  12 + auto p = SherpaOnnxReadWave(filename.c_str());
  13 +
  14 + Wave ans;
  15 + if (p) {
  16 + ans.samples.resize(p->num_samples);
  17 +
  18 + std::copy(p->samples, p->samples + p->num_samples, ans.samples.data());
  19 +
  20 + ans.sample_rate = p->sample_rate;
  21 + SherpaOnnxFreeWave(p);
  22 + }
  23 +
  24 + return ans;
  25 +}
  26 +
  27 +OnlineStream::OnlineStream(const SherpaOnnxOnlineStream *p)
  28 + : MoveOnly<OnlineStream, SherpaOnnxOnlineStream>(p) {}
  29 +
  30 +void OnlineStream::Destroy(const SherpaOnnxOnlineStream *p) const {
  31 + SherpaOnnxDestroyOnlineStream(p);
  32 +}
  33 +
  34 +void OnlineStream::AcceptWaveform(int32_t sample_rate, const float *samples,
  35 + int32_t n) const {
  36 + SherpaOnnxOnlineStreamAcceptWaveform(p_, sample_rate, samples, n);
  37 +}
  38 +
  39 +OnlineRecognizer OnlineRecognizer::Create(
  40 + const OnlineRecognizerConfig &config) {
  41 + struct SherpaOnnxOnlineRecognizerConfig c;
  42 + memset(&c, 0, sizeof(c));
  43 +
  44 + c.feat_config.sample_rate = config.feat_config.sample_rate;
  45 + c.feat_config.feature_dim = config.feat_config.feature_dim;
  46 +
  47 + c.model_config.transducer.encoder =
  48 + config.model_config.transducer.encoder.c_str();
  49 + c.model_config.transducer.decoder =
  50 + config.model_config.transducer.decoder.c_str();
  51 + c.model_config.transducer.joiner =
  52 + config.model_config.transducer.joiner.c_str();
  53 +
  54 + c.model_config.paraformer.encoder =
  55 + config.model_config.paraformer.encoder.c_str();
  56 + c.model_config.paraformer.decoder =
  57 + config.model_config.paraformer.decoder.c_str();
  58 +
  59 + c.model_config.zipformer2_ctc.model =
  60 + config.model_config.zipformer2_ctc.model.c_str();
  61 +
  62 + c.model_config.tokens = config.model_config.tokens.c_str();
  63 + c.model_config.num_threads = config.model_config.num_threads;
  64 + c.model_config.provider = config.model_config.provider.c_str();
  65 + c.model_config.debug = config.model_config.debug;
  66 + c.model_config.model_type = config.model_config.model_type.c_str();
  67 + c.model_config.modeling_unit = config.model_config.modeling_unit.c_str();
  68 + c.model_config.bpe_vocab = config.model_config.bpe_vocab.c_str();
  69 + c.model_config.tokens_buf = config.model_config.tokens_buf.c_str();
  70 + c.model_config.tokens_buf_size = config.model_config.tokens_buf.size();
  71 +
  72 + c.decoding_method = config.decoding_method.c_str();
  73 + c.max_active_paths = config.max_active_paths;
  74 + c.enable_endpoint = config.enable_endpoint;
  75 + c.rule1_min_trailing_silence = config.rule1_min_trailing_silence;
  76 + c.rule2_min_trailing_silence = config.rule2_min_trailing_silence;
  77 + c.rule3_min_utterance_length = config.rule3_min_utterance_length;
  78 + c.hotwords_file = config.hotwords_file.c_str();
  79 + c.hotwords_score = config.hotwords_score;
  80 +
  81 + c.ctc_fst_decoder_config.graph = config.ctc_fst_decoder_config.graph.c_str();
  82 + c.ctc_fst_decoder_config.max_active =
  83 + config.ctc_fst_decoder_config.max_active;
  84 +
  85 + c.rule_fsts = config.rule_fsts.c_str();
  86 + c.rule_fars = config.rule_fars.c_str();
  87 +
  88 + c.blank_penalty = config.blank_penalty;
  89 +
  90 + c.hotwords_buf = config.hotwords_buf.c_str();
  91 + c.hotwords_buf_size = config.hotwords_buf.size();
  92 +
  93 + auto p = SherpaOnnxCreateOnlineRecognizer(&c);
  94 + return OnlineRecognizer(p);
  95 +}
  96 +
  97 +OnlineRecognizer::OnlineRecognizer(const SherpaOnnxOnlineRecognizer *p)
  98 + : MoveOnly<OnlineRecognizer, SherpaOnnxOnlineRecognizer>(p) {}
  99 +
  100 +void OnlineRecognizer::Destroy(const SherpaOnnxOnlineRecognizer *p) const {
  101 + SherpaOnnxDestroyOnlineRecognizer(p);
  102 +}
  103 +
  104 +OnlineStream OnlineRecognizer::CreateStream() const {
  105 + auto s = SherpaOnnxCreateOnlineStream(p_);
  106 + return OnlineStream{s};
  107 +}
  108 +
  109 +OnlineStream OnlineRecognizer::CreateStream(const std::string &hotwords) const {
  110 + auto s = SherpaOnnxCreateOnlineStreamWithHotwords(p_, hotwords.c_str());
  111 + return OnlineStream{s};
  112 +}
  113 +
  114 +bool OnlineRecognizer::IsReady(const OnlineStream *s) const {
  115 + return SherpaOnnxIsOnlineStreamReady(p_, s->Get());
  116 +}
  117 +
  118 +void OnlineRecognizer::Decode(const OnlineStream *s) const {
  119 + SherpaOnnxDecodeOnlineStream(p_, s->Get());
  120 +}
  121 +
  122 +void OnlineRecognizer::Decode(const OnlineStream *ss, int32_t n) const {
  123 + if (n <= 0) {
  124 + return;
  125 + }
  126 +
  127 + std::vector<const SherpaOnnxOnlineStream *> streams(n);
  128 + for (int32_t i = 0; i != n; ++n) {
  129 + streams[i] = ss[i].Get();
  130 + }
  131 +
  132 + SherpaOnnxDecodeMultipleOnlineStreams(p_, streams.data(), n);
  133 +}
  134 +
  135 +OnlineRecognizerResult OnlineRecognizer::GetResult(
  136 + const OnlineStream *s) const {
  137 + auto r = SherpaOnnxGetOnlineStreamResult(p_, s->Get());
  138 +
  139 + OnlineRecognizerResult ans;
  140 + ans.text = r->text;
  141 +
  142 + ans.tokens.resize(r->count);
  143 + for (int32_t i = 0; i != r->count; ++i) {
  144 + ans.tokens[i] = r->tokens_arr[i];
  145 + }
  146 +
  147 + if (r->timestamps) {
  148 + ans.timestamps.resize(r->count);
  149 + std::copy(r->timestamps, r->timestamps + r->count, ans.timestamps.data());
  150 + }
  151 +
  152 + ans.json = r->json;
  153 +
  154 + SherpaOnnxDestroyOnlineRecognizerResult(r);
  155 +
  156 + return ans;
  157 +}
  158 +
  159 +} // namespace sherpa_onnx::cxx
  1 +// sherpa-onnx/c-api/cxx-api.h
  2 +//
  3 +// Copyright (c) 2024 Xiaomi Corporation
  4 +
  5 +// C++ Wrapper of the C API for sherpa-onnx
  6 +#ifndef SHERPA_ONNX_C_API_CXX_API_H_
  7 +#define SHERPA_ONNX_C_API_CXX_API_H_
  8 +
  9 +#include <string>
  10 +#include <vector>
  11 +
  12 +#include "sherpa-onnx/c-api/c-api.h"
  13 +
  14 +namespace sherpa_onnx::cxx {
  15 +
  16 +struct SHERPA_ONNX_API OnlineTransducerModelConfig {
  17 + std::string encoder;
  18 + std::string decoder;
  19 + std::string joiner;
  20 +};
  21 +
  22 +struct SHERPA_ONNX_API OnlineParaformerModelConfig {
  23 + std::string encoder;
  24 + std::string decoder;
  25 +};
  26 +
  27 +struct SHERPA_ONNX_API OnlineZipformer2CtcModelConfig {
  28 + std::string model;
  29 +};
  30 +
  31 +struct SHERPA_ONNX_API OnlineModelConfig {
  32 + OnlineTransducerModelConfig transducer;
  33 + OnlineParaformerModelConfig paraformer;
  34 + OnlineZipformer2CtcModelConfig zipformer2_ctc;
  35 + std::string tokens;
  36 + int32_t num_threads = 1;
  37 + std::string provider = "cpu";
  38 + bool debug = false;
  39 + std::string model_type;
  40 + std::string modeling_unit = "cjkchar";
  41 + std::string bpe_vocab;
  42 + std::string tokens_buf;
  43 +};
  44 +
  45 +struct SHERPA_ONNX_API FeatureConfig {
  46 + int32_t sample_rate = 16000;
  47 + int32_t feature_dim = 80;
  48 +};
  49 +
  50 +struct SHERPA_ONNX_API OnlineCtcFstDecoderConfig {
  51 + std::string graph;
  52 + int32_t max_active = 3000;
  53 +};
  54 +
  55 +struct SHERPA_ONNX_API OnlineRecognizerConfig {
  56 + FeatureConfig feat_config;
  57 + OnlineModelConfig model_config;
  58 +
  59 + std::string decoding_method = "greedy_search";
  60 +
  61 + int32_t max_active_paths = 4;
  62 +
  63 + bool enable_endpoint = false;
  64 +
  65 + float rule1_min_trailing_silence = 2.4;
  66 +
  67 + float rule2_min_trailing_silence = 1.2;
  68 +
  69 + float rule3_min_utterance_length = 20;
  70 +
  71 + std::string hotwords_file;
  72 +
  73 + float hotwords_score = 1.5;
  74 +
  75 + OnlineCtcFstDecoderConfig ctc_fst_decoder_config;
  76 + std::string rule_fsts;
  77 + std::string rule_fars;
  78 + float blank_penalty = 0;
  79 +
  80 + std::string hotwords_buf;
  81 +};
  82 +
  83 +struct SHERPA_ONNX_API OnlineRecognizerResult {
  84 + std::string text;
  85 + std::vector<std::string> tokens;
  86 + std::vector<float> timestamps;
  87 + std::string json;
  88 +};
  89 +
  90 +struct SHERPA_ONNX_API Wave {
  91 + std::vector<float> samples;
  92 + int32_t sample_rate;
  93 +};
  94 +
  95 +SHERPA_ONNX_API Wave ReadWave(const std::string &filename);
  96 +
  97 +template <typename Derived, typename T>
  98 +class SHERPA_ONNX_API MoveOnly {
  99 + public:
  100 + explicit MoveOnly(const T *p) : p_(p) {}
  101 +
  102 + ~MoveOnly() { Destroy(); }
  103 +
  104 + MoveOnly(const MoveOnly &) = delete;
  105 +
  106 + MoveOnly &operator=(const MoveOnly &) = delete;
  107 +
  108 + MoveOnly(MoveOnly &&other) : p_(other.Release()) {}
  109 +
  110 + MoveOnly &operator=(MoveOnly &&other) {
  111 + if (&other == this) {
  112 + return *this;
  113 + }
  114 +
  115 + Destroy();
  116 +
  117 + p_ = other.Release();
  118 + }
  119 +
  120 + const T *Get() const { return p_; }
  121 +
  122 + const T *Release() {
  123 + const T *p = p_;
  124 + p_ = nullptr;
  125 + return p;
  126 + }
  127 +
  128 + private:
  129 + void Destroy() {
  130 + if (p_ == nullptr) {
  131 + return;
  132 + }
  133 +
  134 + static_cast<Derived *>(this)->Destroy(p_);
  135 +
  136 + p_ = nullptr;
  137 + }
  138 +
  139 + protected:
  140 + const T *p_ = nullptr;
  141 +};
  142 +
  143 +class SHERPA_ONNX_API OnlineStream
  144 + : public MoveOnly<OnlineStream, SherpaOnnxOnlineStream> {
  145 + public:
  146 + explicit OnlineStream(const SherpaOnnxOnlineStream *p);
  147 +
  148 + void AcceptWaveform(int32_t sample_rate, const float *samples,
  149 + int32_t n) const;
  150 +
  151 + void Destroy(const SherpaOnnxOnlineStream *p) const;
  152 +};
  153 +
  154 +class SHERPA_ONNX_API OnlineRecognizer
  155 + : public MoveOnly<OnlineRecognizer, SherpaOnnxOnlineRecognizer> {
  156 + public:
  157 + static OnlineRecognizer Create(const OnlineRecognizerConfig &config);
  158 +
  159 + void Destroy(const SherpaOnnxOnlineRecognizer *p) const;
  160 +
  161 + OnlineStream CreateStream() const;
  162 +
  163 + OnlineStream CreateStream(const std::string &hotwords) const;
  164 +
  165 + bool IsReady(const OnlineStream *s) const;
  166 +
  167 + void Decode(const OnlineStream *s) const;
  168 +
  169 + void Decode(const OnlineStream *ss, int32_t n) const;
  170 +
  171 + OnlineRecognizerResult GetResult(const OnlineStream *s) const;
  172 +
  173 + private:
  174 + explicit OnlineRecognizer(const SherpaOnnxOnlineRecognizer *p);
  175 +};
  176 +
  177 +} // namespace sherpa_onnx::cxx
  178 +
  179 +#endif // SHERPA_ONNX_C_API_CXX_API_H_