Skip to content

Commit db85b2c

Browse files
authored
Add Android APKs for NeMo CTC models. (#866)
1 parent 7322f4e commit db85b2c

File tree

9 files changed

+210
-3
lines changed

9 files changed

+210
-3
lines changed

.github/workflows/apk-vad-asr.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
os: [ubuntu-latest]
26-
total: ["3"]
27-
index: ["0", "1", "2"]
26+
total: ["5"]
27+
index: ["0", "1", "2", "3", "4"]
2828

2929
steps:
3030
- uses: actions/checkout@v4

kotlin-api-examples/run.sh

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ function testOnlineAsr() {
6363
git clone https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-02-21
6464
fi
6565

66+
if [ ! -f ./sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms/tokens.txt ]; then
67+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms.tar.bz2
68+
tar xvf sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms.tar.bz2
69+
rm sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms.tar.bz2
70+
fi
71+
6672
if [ ! -d ./sherpa-onnx-streaming-zipformer-ctc-multi-zh-hans-2023-12-13 ]; then
6773
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-ctc-multi-zh-hans-2023-12-13.tar.bz2
6874
tar xvf sherpa-onnx-streaming-zipformer-ctc-multi-zh-hans-2023-12-13.tar.bz2

kotlin-api-examples/test_online_asr.kt

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fun main() {
44
testOnlineAsr("transducer")
55
testOnlineAsr("zipformer2-ctc")
66
testOnlineAsr("ctc-hlg")
7+
testOnlineAsr("nemo-ctc")
78
}
89

910
fun testOnlineAsr(type: String) {
@@ -42,6 +43,17 @@ fun testOnlineAsr(type: String) {
4243
debug = false,
4344
)
4445
}
46+
"nemo-ctc" -> {
47+
waveFilename = "./sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms/test_wavs/0.wav"
48+
OnlineModelConfig(
49+
neMoCtc = OnlineNeMoCtcModelConfig(
50+
model = "./sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms/model.onnx",
51+
),
52+
tokens = "./sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms/tokens.txt",
53+
numThreads = 1,
54+
debug = false,
55+
)
56+
}
4557
"ctc-hlg" -> {
4658
waveFilename = "./sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18/test_wavs/1.wav"
4759
ctcFstDecoderConfig.graph = "./sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18/HLG.fst"

scripts/apk/generate-asr-apk-script.py

+42
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,48 @@ def get_models():
167167
168168
ls -lh
169169
170+
popd
171+
""",
172+
),
173+
Model(
174+
model_name="sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms",
175+
idx=11,
176+
lang="en",
177+
short_name="nemo_ctc_80ms",
178+
cmd="""
179+
pushd $model_name
180+
rm -rf test_wavs
181+
182+
ls -lh
183+
184+
popd
185+
""",
186+
),
187+
Model(
188+
model_name="sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-480ms",
189+
idx=12,
190+
lang="en",
191+
short_name="nemo_ctc_480ms",
192+
cmd="""
193+
pushd $model_name
194+
rm -rf test_wavs
195+
196+
ls -lh
197+
198+
popd
199+
""",
200+
),
201+
Model(
202+
model_name="sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-1040ms",
203+
idx=13,
204+
lang="en",
205+
short_name="nemo_ctc_1040ms",
206+
cmd="""
207+
pushd $model_name
208+
rm -rf test_wavs
209+
210+
ls -lh
211+
170212
popd
171213
""",
172214
),

scripts/apk/generate-vad-asr-apk-script.py

+60
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,66 @@ def get_models():
103103
104104
ls -lh
105105
106+
popd
107+
""",
108+
),
109+
Model(
110+
model_name="sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k",
111+
idx=7,
112+
lang="be_de_en_es_fr_hr_it_pl_ru_uk",
113+
short_name="fast_conformer_ctc_20k",
114+
cmd="""
115+
pushd $model_name
116+
117+
rm -rfv test_wavs
118+
119+
ls -lh
120+
121+
popd
122+
""",
123+
),
124+
Model(
125+
model_name="sherpa-onnx-nemo-fast-conformer-ctc-en-24500",
126+
idx=8,
127+
lang="en",
128+
short_name="fast_conformer_ctc_24500",
129+
cmd="""
130+
pushd $model_name
131+
132+
rm -rfv test_wavs
133+
134+
ls -lh
135+
136+
popd
137+
""",
138+
),
139+
Model(
140+
model_name="sherpa-onnx-nemo-fast-conformer-ctc-en-de-es-fr-14288",
141+
idx=9,
142+
lang="en_des_es_fr",
143+
short_name="fast_conformer_ctc_14288",
144+
cmd="""
145+
pushd $model_name
146+
147+
rm -rfv test_wavs
148+
149+
ls -lh
150+
151+
popd
152+
""",
153+
),
154+
Model(
155+
model_name="sherpa-onnx-nemo-fast-conformer-ctc-es-1424",
156+
idx=10,
157+
lang="es",
158+
short_name="fast_conformer_ctc_1424",
159+
cmd="""
160+
pushd $model_name
161+
162+
rm -rfv test_wavs
163+
164+
ls -lh
165+
106166
popd
107167
""",
108168
),

sherpa-onnx/csrc/offline-ctc-model.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ std::unique_ptr<OfflineCtcModel> OfflineCtcModel::Create(
163163
return std::make_unique<OfflineNemoEncDecCtcModel>(mgr, config);
164164
break;
165165
case ModelType::kEncDecHybridRNNTCTCBPEModel:
166-
return std::make_unique<OfflineNemoEncDecHybridRNNTCTCBPEModel>(config);
166+
return std::make_unique<OfflineNemoEncDecHybridRNNTCTCBPEModel>(mgr,
167+
config);
167168
break;
168169
case ModelType::kTdnn:
169170
return std::make_unique<OfflineTdnnCtcModel>(mgr, config);

sherpa-onnx/jni/online-recognizer.cc

+12
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ static OnlineRecognizerConfig GetConfig(JNIEnv *env, jobject config) {
159159
ans.model_config.zipformer2_ctc.model = p;
160160
env->ReleaseStringUTFChars(s, p);
161161

162+
// streaming NeMo CTC
163+
fid = env->GetFieldID(model_config_cls, "neMoCtc",
164+
"Lcom/k2fsa/sherpa/onnx/OnlineNeMoCtcModelConfig;");
165+
jobject nemo_ctc_config = env->GetObjectField(model_config, fid);
166+
jclass nemo_ctc_config_cls = env->GetObjectClass(nemo_ctc_config);
167+
168+
fid = env->GetFieldID(nemo_ctc_config_cls, "model", "Ljava/lang/String;");
169+
s = (jstring)env->GetObjectField(nemo_ctc_config, fid);
170+
p = env->GetStringUTFChars(s, nullptr);
171+
ans.model_config.nemo_ctc.model = p;
172+
env->ReleaseStringUTFChars(s, p);
173+
162174
fid = env->GetFieldID(model_config_cls, "tokens", "Ljava/lang/String;");
163175
s = (jstring)env->GetObjectField(model_config, fid);
164176
p = env->GetStringUTFChars(s, nullptr);

sherpa-onnx/kotlin-api/OfflineRecognizer.kt

+39
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,45 @@ fun getOfflineModelConfig(type: Int): OfflineModelConfig? {
231231
)
232232
}
233233

234+
7 -> {
235+
val modelDir = "sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k"
236+
return OfflineModelConfig(
237+
nemo = OfflineNemoEncDecCtcModelConfig(
238+
model = "$modelDir/model.onnx",
239+
),
240+
tokens = "$modelDir/tokens.txt",
241+
)
242+
}
243+
244+
8 -> {
245+
val modelDir = "sherpa-onnx-nemo-fast-conformer-ctc-en-24500"
246+
return OfflineModelConfig(
247+
nemo = OfflineNemoEncDecCtcModelConfig(
248+
model = "$modelDir/model.onnx",
249+
),
250+
tokens = "$modelDir/tokens.txt",
251+
)
252+
}
253+
254+
9 -> {
255+
val modelDir = "sherpa-onnx-nemo-fast-conformer-ctc-en-de-es-fr-14288"
256+
return OfflineModelConfig(
257+
nemo = OfflineNemoEncDecCtcModelConfig(
258+
model = "$modelDir/model.onnx",
259+
),
260+
tokens = "$modelDir/tokens.txt",
261+
)
262+
}
263+
264+
10 -> {
265+
val modelDir = "sherpa-onnx-nemo-fast-conformer-ctc-es-1424"
266+
return OfflineModelConfig(
267+
nemo = OfflineNemoEncDecCtcModelConfig(
268+
model = "$modelDir/model.onnx",
269+
),
270+
tokens = "$modelDir/tokens.txt",
271+
)
272+
}
234273
}
235274
return null
236275
}

sherpa-onnx/kotlin-api/OnlineRecognizer.kt

+35
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ data class OnlineZipformer2CtcModelConfig(
2929
var model: String = "",
3030
)
3131

32+
data class OnlineNeMoCtcModelConfig(
33+
var model: String = "",
34+
)
35+
3236
data class OnlineModelConfig(
3337
var transducer: OnlineTransducerModelConfig = OnlineTransducerModelConfig(),
3438
var paraformer: OnlineParaformerModelConfig = OnlineParaformerModelConfig(),
3539
var zipformer2Ctc: OnlineZipformer2CtcModelConfig = OnlineZipformer2CtcModelConfig(),
40+
var neMoCtc: OnlineNeMoCtcModelConfig = OnlineNeMoCtcModelConfig(),
3641
var tokens: String,
3742
var numThreads: Int = 1,
3843
var debug: Boolean = false,
@@ -318,6 +323,36 @@ fun getModelConfig(type: Int): OnlineModelConfig? {
318323
modelType = "zipformer",
319324
)
320325
}
326+
327+
11 -> {
328+
val modelDir = "sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-80ms"
329+
return OnlineModelConfig(
330+
neMoCtc = OnlineNeMoCtcModelConfig(
331+
model = "$modelDir/model.onnx",
332+
),
333+
tokens = "$modelDir/tokens.txt",
334+
)
335+
}
336+
337+
12 -> {
338+
val modelDir = "sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-480ms"
339+
return OnlineModelConfig(
340+
neMoCtc = OnlineNeMoCtcModelConfig(
341+
model = "$modelDir/model.onnx",
342+
),
343+
tokens = "$modelDir/tokens.txt",
344+
)
345+
}
346+
347+
13 -> {
348+
val modelDir = "sherpa-onnx-nemo-streaming-fast-conformer-ctc-en-1040ms"
349+
return OnlineModelConfig(
350+
neMoCtc = OnlineNeMoCtcModelConfig(
351+
model = "$modelDir/model.onnx",
352+
),
353+
tokens = "$modelDir/tokens.txt",
354+
)
355+
}
321356
}
322357
return null
323358
}

0 commit comments

Comments
 (0)