Skip to content

Commit 6789c90

Browse files
authored
Inverse text normalization API of streaming ASR for various programming languages (#1022)
1 parent 349d957 commit 6789c90

File tree

64 files changed

+849
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+849
-55
lines changed

.github/scripts/test-dart.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ echo '----------streaming zipformer ctc----------'
6666
rm -rf sherpa-onnx-*
6767

6868
echo '----------streaming zipformer transducer----------'
69+
./run-zipformer-transducer-itn.sh
6970
./run-zipformer-transducer.sh
71+
rm -f itn*
7072
rm -rf sherpa-onnx-*
7173

7274
echo '----------streaming NeMo transducer----------'

.github/scripts/test-dot-net.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
cd dotnet-examples/
44

5-
cd ./offline-decode-files
5+
cd ./online-decode-files
6+
./run-transducer-itn.sh
7+
./run-zipformer2-ctc.sh
8+
./run-transducer.sh
9+
./run-paraformer.sh
10+
11+
cd ../offline-decode-files
612
./run-paraformer-itn.sh
713
./run-telespeech-ctc.sh
814
./run-nemo-ctc.sh
@@ -27,11 +33,6 @@ cd ../streaming-hlg-decoding/
2733
cd ../spoken-language-identification
2834
./run.sh
2935

30-
cd ../online-decode-files
31-
./run-zipformer2-ctc.sh
32-
./run-transducer.sh
33-
./run-paraformer.sh
34-
3536
cd ../offline-tts
3637
./run-aishell3.sh
3738
./run-piper.sh

.github/scripts/test-nodejs-addon-npm.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/s
7070
tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
7171
rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
7272

73+
rm -f itn*
74+
75+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn_zh_number.fst
76+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn-zh-number.wav
77+
78+
node test_asr_streaming_transducer_itn.js
79+
7380
node test_asr_streaming_transducer.js
7481

7582
rm -rf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
@@ -120,6 +127,8 @@ rm sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2
120127

121128
node ./test_asr_non_streaming_paraformer.js
122129

130+
rm -f itn*
131+
123132
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn_zh_number.fst
124133
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn-zh-number.wav
125134

.github/scripts/test-nodejs-npm.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ curl -LS -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/s
1515
ls -lh
1616
tar xvf sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2
1717
rm sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2
18+
19+
rm -f itn*
1820
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn-zh-number.wav
1921
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn_zh_number.fst
2022
node ./test-offline-paraformer-itn.js
@@ -57,7 +59,15 @@ rm -rf sherpa-onnx-streaming-paraformer-bilingual-zh-en
5759
curl -LS -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
5860
tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
5961
rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
62+
63+
rm -f itn*
64+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn-zh-number.wav
65+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn_zh_number.fst
66+
67+
node ./test-online-transducer-itn.js
68+
6069
node ./test-online-transducer.js
70+
6171
rm -rf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
6272

6373
curl -LS -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

.github/workflows/build-wheels-aarch64.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: build-wheels-aarch64
22

33
on:
44
push:
5+
branches:
6+
- wheel
57
tags:
68
- 'v[0-9]+.[0-9]+.[0-9]+*'
79
workflow_dispatch:

.github/workflows/build-wheels-armv7l.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: build-wheels-armv7l
22

33
on:
44
push:
5+
branches:
6+
- wheel
57
tags:
68
- 'v[0-9]+.[0-9]+.[0-9]+*'
79
workflow_dispatch:

.github/workflows/build-wheels-linux.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: build-wheels-linux
22

33
on:
44
push:
5+
branches:
6+
- wheel
57
tags:
68
- 'v[0-9]+.[0-9]+.[0-9]+*'
79
workflow_dispatch:

.github/workflows/build-wheels-macos-arm64.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: build-wheels-macos-arm64
22

33
on:
44
push:
5+
branches:
6+
- wheel
57
tags:
68
- 'v[0-9]+.[0-9]+.[0-9]+*'
79
workflow_dispatch:
@@ -84,7 +86,7 @@ jobs:
8486
run: |
8587
opts='--break-system-packages'
8688
v=${{ matrix.python-version }}
87-
if [[ $v == cp38 || $v == cp39 ]]; then
89+
if [[ $v == cp37 || $v == cp38 || $v == cp39 ]]; then
8890
opts=''
8991
fi
9092

.github/workflows/build-wheels-macos-x64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
run: |
102102
opts='--break-system-packages'
103103
v=${{ matrix.python-version }}
104-
if [[ $v == cp38 || $v == cp39 ]]; then
104+
if [[ $v == cp37 || $v == cp38 || $v == cp39 ]]; then
105105
opts=''
106106
fi
107107

.github/workflows/build-wheels-win32.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: build-wheels-win32
22

33
on:
44
push:
5+
branches:
6+
- wheel
57
tags:
68
- 'v[0-9]+.[0-9]+.[0-9]+*'
79
workflow_dispatch:

.github/workflows/run-java-test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ jobs:
173173
shell: bash
174174
run: |
175175
cd ./java-api-examples
176+
./run-inverse-text-normalization-transducer.sh
177+
rm -rf sherpa-onnx-streaming-*
178+
176179
./run-streaming-decode-file-ctc.sh
177180
# Delete model files to save space
178181
rm -rf sherpa-onnx-streaming-*

.github/workflows/test-go.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ jobs:
187187
./run-transducer.sh
188188
rm -rf sherpa-onnx-streaming-zipformer-en-2023-06-26
189189
190+
./run-transducer-itn.sh
191+
rm -rf sherpa-onnx-streaming-*
192+
190193
echo "Test paraformer"
191194
./run-paraformer.sh
192195
rm -rf sherpa-onnx-streaming-paraformer-bilingual-zh-en

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ project(sherpa-onnx)
77
# Remember to update
88
# ./nodejs-addon-examples
99
# ./dart-api-examples/
10-
set(SHERPA_ONNX_VERSION "1.9.30")
10+
# ./sherpa-onnx/flutter/CHANGELOG.md
11+
set(SHERPA_ONNX_VERSION "1.10.0")
1112

1213
# Disable warning about
1314
#

android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ class MainActivity : AppCompatActivity() {
196196
// See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
197197
// for a list of available models
198198
val type = 0
199+
var ruleFsts : String?
200+
ruleFsts = null
201+
199202
Log.i(TAG, "Select model type $type")
200203
val config = OnlineRecognizerConfig(
201204
featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80),
@@ -205,6 +208,10 @@ class MainActivity : AppCompatActivity() {
205208
enableEndpoint = true,
206209
)
207210

211+
if (ruleFsts != null) {
212+
config.ruleFsts = ruleFsts
213+
}
214+
208215
recognizer = OnlineRecognizer(
209216
assetManager = application.assets,
210217
config = config,

android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,18 @@ class MainActivity : AppCompatActivity() {
194194
// See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
195195
// for a list of available models
196196
val firstType = 9
197+
val firstRuleFsts: String?
198+
firstRuleFsts = null
197199
Log.i(TAG, "Select model type $firstType for the first pass")
198200
val config = OnlineRecognizerConfig(
199201
featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80),
200202
modelConfig = getModelConfig(type = firstType)!!,
201203
endpointConfig = getEndpointConfig(),
202204
enableEndpoint = true,
203205
)
206+
if (firstRuleFsts != null) {
207+
config.ruleFsts = firstRuleFsts;
208+
}
204209

205210
onlineRecognizer = OnlineRecognizer(
206211
assetManager = application.assets,
@@ -213,13 +218,19 @@ class MainActivity : AppCompatActivity() {
213218
// See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
214219
// for a list of available models
215220
val secondType = 0
221+
var secondRuleFsts: String?
222+
secondRuleFsts = null
216223
Log.i(TAG, "Select model type $secondType for the second pass")
217224

218225
val config = OfflineRecognizerConfig(
219226
featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80),
220227
modelConfig = getOfflineModelConfig(type = secondType)!!,
221228
)
222229

230+
if (secondRuleFsts != null) {
231+
config.ruleFsts = secondRuleFsts
232+
}
233+
223234
offlineRecognizer = OfflineRecognizer(
224235
assetManager = application.assets,
225236
config = config,

android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,17 @@ class MainActivity : AppCompatActivity() {
200200
// See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
201201
// for a list of available models
202202
val asrModelType = 0
203+
val asrRuleFsts: String?
204+
asrRuleFsts = null
203205
Log.i(TAG, "Select model type ${asrModelType} for ASR")
204206

205207
val config = OfflineRecognizerConfig(
206208
featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80),
207209
modelConfig = getOfflineModelConfig(type = asrModelType)!!,
208210
)
211+
if (asrRuleFsts != null) {
212+
config.ruleFsts = asrRuleFsts;
213+
}
209214

210215
offlineRecognizer = OfflineRecognizer(
211216
assetManager = application.assets,

cmake/kaldi-decoder.cmake

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,36 +63,24 @@ function(download_kaldi_decoder)
6363
kaldi-decoder-core
6464
kaldifst_core
6565
fst
66+
fstfar
6667
DESTINATION ..)
67-
if(SHERPA_ONNX_ENABLE_TTS)
68-
install(TARGETS
69-
fstfar
70-
DESTINATION ..)
71-
endif()
7268
else()
7369
install(TARGETS
7470
kaldi-decoder-core
7571
kaldifst_core
7672
fst
73+
fstfar
7774
DESTINATION lib)
78-
if(SHERPA_ONNX_ENABLE_TTS)
79-
install(TARGETS
80-
fstfar
81-
DESTINATION lib)
82-
endif()
8375
endif()
8476

8577
if(WIN32 AND BUILD_SHARED_LIBS)
8678
install(TARGETS
8779
kaldi-decoder-core
8880
kaldifst_core
8981
fst
82+
fstfar
9083
DESTINATION bin)
91-
if(SHERPA_ONNX_ENABLE_TTS)
92-
install(TARGETS
93-
fstfar
94-
DESTINATION bin)
95-
endif()
9684
endif()
9785
endfunction()
9886

dart-api-examples/non-streaming-asr/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ environment:
1010

1111
# Add regular dependencies here.
1212
dependencies:
13-
sherpa_onnx: ^1.9.30
13+
sherpa_onnx: ^1.10.0
1414
path: ^1.9.0
1515
args: ^2.5.0
1616

dart-api-examples/streaming-asr/bin/zipformer-transducer.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void main(List<String> arguments) async {
1515
..addOption('decoder', help: 'Path to decoder model')
1616
..addOption('joiner', help: 'Path to joiner model')
1717
..addOption('tokens', help: 'Path to tokens.txt')
18+
..addOption('rule-fsts', help: 'Path to rule fsts', defaultsTo: '')
1819
..addOption('input-wav', help: 'Path to input.wav to transcribe');
1920

2021
final res = parser.parse(arguments);
@@ -31,6 +32,7 @@ void main(List<String> arguments) async {
3132
final decoder = res['decoder'] as String;
3233
final joiner = res['joiner'] as String;
3334
final tokens = res['tokens'] as String;
35+
final ruleFsts = res['rule-fsts'] as String;
3436
final inputWav = res['input-wav'] as String;
3537

3638
final transducer = sherpa_onnx.OnlineTransducerModelConfig(
@@ -45,7 +47,10 @@ void main(List<String> arguments) async {
4547
debug: true,
4648
numThreads: 1,
4749
);
48-
final config = sherpa_onnx.OnlineRecognizerConfig(model: modelConfig);
50+
final config = sherpa_onnx.OnlineRecognizerConfig(
51+
model: modelConfig,
52+
ruleFsts: ruleFsts,
53+
);
4954
final recognizer = sherpa_onnx.OnlineRecognizer(config);
5055

5156
final waveData = sherpa_onnx.readWave(inputWav);

dart-api-examples/streaming-asr/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ environment:
1111

1212
# Add regular dependencies here.
1313
dependencies:
14-
sherpa_onnx: ^1.9.30
14+
sherpa_onnx: ^1.10.0
1515
path: ^1.9.0
1616
args: ^2.5.0
1717

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
dart pub get
6+
7+
if [ ! -f ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/tokens.txt ]; then
8+
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
9+
tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
10+
rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
11+
fi
12+
13+
if [ ! -f ./itn-zh-number.wav ]; then
14+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn-zh-number.wav
15+
fi
16+
17+
if [ ! -f ./itn_zh_number.fst ]; then
18+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn_zh_number.fst
19+
fi
20+
21+
dart run \
22+
./bin/zipformer-transducer.dart \
23+
--encoder ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/encoder-epoch-99-avg-1.int8.onnx \
24+
--decoder ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/decoder-epoch-99-avg-1.onnx \
25+
--joiner ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/joiner-epoch-99-avg-1.int8.onnx \
26+
--tokens ./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/tokens.txt \
27+
--rule-fsts ./itn_zh_number.fst \
28+
--input-wav ./itn-zh-number.wav

dart-api-examples/tts/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ environment:
88

99
# Add regular dependencies here.
1010
dependencies:
11-
sherpa_onnx: ^1.9.30
11+
sherpa_onnx: ^1.10.0
1212
path: ^1.9.0
1313
args: ^2.5.0
1414

dart-api-examples/vad/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ environment:
99
sdk: ^3.4.0
1010

1111
dependencies:
12-
sherpa_onnx: ^1.9.30
12+
sherpa_onnx: ^1.10.0
1313
path: ^1.9.0
1414
args: ^2.5.0
1515

0 commit comments

Comments
 (0)