-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inverse text normalization API for other programming languages (#1019)
- Loading branch information
1 parent
b0f7ed3
commit 6e09933
Showing
39 changed files
with
669 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,3 +107,4 @@ package-lock.json | |
sherpa-onnx-nemo-* | ||
sherpa-onnx-vits-* | ||
sherpa-onnx-telespeech-ctc-* | ||
*.fst |
63 changes: 63 additions & 0 deletions
63
dart-api-examples/non-streaming-asr/bin/paraformer-itn.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
import 'dart:io'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
|
||
import './init.dart'; | ||
|
||
void main(List<String> arguments) async { | ||
await initSherpaOnnx(); | ||
|
||
final parser = ArgParser() | ||
..addOption('model', help: 'Path to the paraformer model') | ||
..addOption('tokens', help: 'Path to tokens.txt') | ||
..addOption('rule-fsts', | ||
help: 'Path to rule fsts for inverse text normalization') | ||
..addOption('input-wav', help: 'Path to input.wav to transcribe'); | ||
|
||
final res = parser.parse(arguments); | ||
if (res['model'] == null || | ||
res['tokens'] == null || | ||
res['rule-fsts'] == null || | ||
res['input-wav'] == null) { | ||
print(parser.usage); | ||
exit(1); | ||
} | ||
|
||
final model = res['model'] as String; | ||
final tokens = res['tokens'] as String; | ||
final ruleFsts = res['rule-fsts'] as String; | ||
final inputWav = res['input-wav'] as String; | ||
|
||
final paraformer = sherpa_onnx.OfflineParaformerModelConfig( | ||
model: model, | ||
); | ||
|
||
final modelConfig = sherpa_onnx.OfflineModelConfig( | ||
paraformer: paraformer, | ||
tokens: tokens, | ||
debug: true, | ||
numThreads: 1, | ||
modelType: 'paraformer', | ||
); | ||
final config = sherpa_onnx.OfflineRecognizerConfig( | ||
model: modelConfig, | ||
ruleFsts: ruleFsts, | ||
); | ||
final recognizer = sherpa_onnx.OfflineRecognizer(config); | ||
|
||
final waveData = sherpa_onnx.readWave(inputWav); | ||
final stream = recognizer.createStream(); | ||
|
||
stream.acceptWaveform( | ||
samples: waveData.samples, sampleRate: waveData.sampleRate); | ||
recognizer.decode(stream); | ||
|
||
final result = recognizer.getResult(stream); | ||
print(result.text); | ||
|
||
stream.free(); | ||
recognizer.free(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
dart pub get | ||
|
||
if [ ! -f ./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt ]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
|
||
tar xvf sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
rm sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
fi | ||
|
||
if [ ! -f ./itn-zh-number.wav ]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn-zh-number.wav | ||
fi | ||
|
||
if [ ! -f ./itn_zh_number.fst ]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn_zh_number.fst | ||
fi | ||
|
||
dart run \ | ||
./bin/paraformer-itn.dart \ | ||
--model ./sherpa-onnx-paraformer-zh-2023-03-28/model.int8.onnx \ | ||
--tokens ./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt \ | ||
--rule-fsts ./itn_zh_number.fst \ | ||
--input-wav ./itn-zh-number.wav |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
dotnet-examples/offline-decode-files/run-paraformer-itn.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
if [ ! -d ./sherpa-onnx-paraformer-zh-2023-03-28 ]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
tar xvf sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
rm sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
fi | ||
|
||
if [ ! -f ./itn-zh-number.wav ]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn-zh-number.wav | ||
fi | ||
|
||
if [ ! -f ./itn_zh_number.fst ]; then | ||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/itn_zh_number.fst | ||
fi | ||
|
||
dotnet run \ | ||
--tokens=./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt \ | ||
--paraformer=./sherpa-onnx-paraformer-zh-2023-03-28/model.onnx \ | ||
--rule-fsts=./itn_zh_number.fst \ | ||
--num-threads=2 \ | ||
--files ./itn-zh-number.wav |
Oops, something went wrong.