-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pascal API for non-streaming ASR (#1247)
- Loading branch information
1 parent
5791b69
commit a7dc6c2
Showing
26 changed files
with
1,616 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
!run-*.sh | ||
zipformer_transducer | ||
whisper | ||
nemo_transducer | ||
nemo_ctc | ||
paraformer | ||
paraformer_itn | ||
sense_voice | ||
telespeech_ctc |
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,15 @@ | ||
# Introduction | ||
|
||
This folder contains examples about using sherpa-onnx's object pascal | ||
APIs with non-streaming models for speech recognition. | ||
|
||
|File|Description| | ||
|----|-----------| | ||
|[run-nemo-ctc.sh](./run-nemo-ctc.sh)|Use a non-streaming NeMo CTC model for speech recognition| | ||
|[run-nemo-transducer.sh](./run-nemo-transducer.sh)|Use a non-streaming NeMo transducer model for speech recognition| | ||
|[run-paraformer-itn.sh](./run-paraformer-itn.sh)|Use a non-streaming Paraformer model for speech recognition with inverse text normalization for numbers| | ||
|[run-paraformer.sh](./run-paraformer.sh)|Use a non-streaming Paraformer model for speech recognition| | ||
|[run-sense-voice.sh](./run-sense-voice.sh)|Use a non-streaming SenseVoice model for speech recognition| | ||
|[run-telespeech-ctc.sh](./run-telespeech-ctc.sh)|Use a non-streaming TeleSpeech CTC model for speech recognition| | ||
|[run-whisper.sh](./run-whisper.sh)|Use a Whisper model for speech recognition| | ||
|[run-zipformer-transducer.sh](./run-zipformer-transducer.sh)|Use a non-streaming Zipformer transducer model for speech recognition| |
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,74 @@ | ||
{ Copyright (c) 2024 Xiaomi Corporation } | ||
|
||
{ | ||
This file shows how to use a non-streaming NeMo CTC model | ||
to decode files. | ||
You can download the model files from | ||
https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models | ||
} | ||
|
||
program nemo_ctc; | ||
|
||
{$mode objfpc} | ||
|
||
uses | ||
sherpa_onnx, | ||
DateUtils, | ||
SysUtils; | ||
|
||
var | ||
Wave: TSherpaOnnxWave; | ||
WaveFilename: AnsiString; | ||
|
||
Config: TSherpaOnnxOfflineRecognizerConfig; | ||
Recognizer: TSherpaOnnxOfflineRecognizer; | ||
Stream: TSherpaOnnxOfflineStream; | ||
RecognitionResult: TSherpaOnnxOfflineRecognizerResult; | ||
|
||
Start: TDateTime; | ||
Stop: TDateTime; | ||
|
||
Elapsed: Single; | ||
Duration: Single; | ||
RealTimeFactor: Single; | ||
begin | ||
Config.ModelConfig.NeMoCtC.Model := './sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k/model.onnx'; | ||
Config.ModelConfig.Tokens := './sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k/tokens.txt'; | ||
Config.ModelConfig.Provider := 'cpu'; | ||
Config.ModelConfig.NumThreads := 1; | ||
Config.ModelConfig.Debug := False; | ||
|
||
WaveFilename := './sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k/test_wavs/es-spanish.wav'; | ||
|
||
Wave := SherpaOnnxReadWave(WaveFilename); | ||
|
||
Recognizer := TSherpaOnnxOfflineRecognizer.Create(Config); | ||
Stream := Recognizer.CreateStream(); | ||
Start := Now; | ||
|
||
Stream.AcceptWaveform(Wave.Samples, Wave.SampleRate); | ||
Recognizer.Decode(Stream); | ||
|
||
RecognitionResult := Recognizer.GetResult(Stream); | ||
|
||
Stop := Now; | ||
|
||
Elapsed := MilliSecondsBetween(Stop, Start) / 1000; | ||
Duration := Length(Wave.Samples) / Wave.SampleRate; | ||
RealTimeFactor := Elapsed / Duration; | ||
|
||
WriteLn(RecognitionResult.ToString); | ||
WriteLn(Format('NumThreads %d', [Config.ModelConfig.NumThreads])); | ||
WriteLn(Format('Elapsed %.3f s', [Elapsed])); | ||
WriteLn(Format('Wave duration %.3f s', [Duration])); | ||
WriteLn(Format('RTF = %.3f/%.3f = %.3f', [Elapsed, Duration, RealTimeFactor])); | ||
|
||
{Free resources to avoid memory leak. | ||
Note: You don't need to invoke them for this simple script. | ||
However, you have to invoke them in your own large/complex project. | ||
} | ||
FreeAndNil(Stream); | ||
FreeAndNil(Recognizer); | ||
end. |
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,77 @@ | ||
{ Copyright (c) 2024 Xiaomi Corporation } | ||
|
||
{ | ||
This file shows how to use a non-streaming NeMo transducer | ||
to decode files. | ||
You can download the model files from | ||
https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models | ||
} | ||
|
||
program nemo_transducer; | ||
|
||
{$mode objfpc} | ||
|
||
uses | ||
sherpa_onnx, | ||
DateUtils, | ||
SysUtils; | ||
|
||
var | ||
Wave: TSherpaOnnxWave; | ||
WaveFilename: AnsiString; | ||
|
||
Config: TSherpaOnnxOfflineRecognizerConfig; | ||
Recognizer: TSherpaOnnxOfflineRecognizer; | ||
Stream: TSherpaOnnxOfflineStream; | ||
RecognitionResult: TSherpaOnnxOfflineRecognizerResult; | ||
|
||
Start: TDateTime; | ||
Stop: TDateTime; | ||
|
||
Elapsed: Single; | ||
Duration: Single; | ||
RealTimeFactor: Single; | ||
begin | ||
Config.ModelConfig.Transducer.Encoder := './sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/encoder.onnx'; | ||
Config.ModelConfig.Transducer.Decoder := './sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/decoder.onnx'; | ||
Config.ModelConfig.Transducer.Joiner := './sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/joiner.onnx'; | ||
Config.ModelConfig.ModelType := 'nemo_transducer'; | ||
Config.ModelConfig.Tokens := './sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/tokens.txt'; | ||
Config.ModelConfig.Provider := 'cpu'; | ||
Config.ModelConfig.NumThreads := 1; | ||
Config.ModelConfig.Debug := False; | ||
|
||
WaveFilename := './sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/test_wavs/de-german.wav'; | ||
|
||
Wave := SherpaOnnxReadWave(WaveFilename); | ||
|
||
Recognizer := TSherpaOnnxOfflineRecognizer.Create(Config); | ||
Stream := Recognizer.CreateStream(); | ||
Start := Now; | ||
|
||
Stream.AcceptWaveform(Wave.Samples, Wave.SampleRate); | ||
Recognizer.Decode(Stream); | ||
|
||
RecognitionResult := Recognizer.GetResult(Stream); | ||
|
||
Stop := Now; | ||
|
||
Elapsed := MilliSecondsBetween(Stop, Start) / 1000; | ||
Duration := Length(Wave.Samples) / Wave.SampleRate; | ||
RealTimeFactor := Elapsed / Duration; | ||
|
||
WriteLn(RecognitionResult.ToString); | ||
WriteLn(Format('NumThreads %d', [Config.ModelConfig.NumThreads])); | ||
WriteLn(Format('Elapsed %.3f s', [Elapsed])); | ||
WriteLn(Format('Wave duration %.3f s', [Duration])); | ||
WriteLn(Format('RTF = %.3f/%.3f = %.3f', [Elapsed, Duration, RealTimeFactor])); | ||
|
||
{Free resources to avoid memory leak. | ||
Note: You don't need to invoke them for this simple script. | ||
However, you have to invoke them in your own large/complex project. | ||
} | ||
FreeAndNil(Stream); | ||
FreeAndNil(Recognizer); | ||
end. |
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,74 @@ | ||
{ Copyright (c) 2024 Xiaomi Corporation } | ||
|
||
{ | ||
This file shows how to use a non-streaming Paraformer model | ||
to decode files. | ||
You can download the model files from | ||
https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models | ||
} | ||
|
||
program paraformer; | ||
|
||
{$mode objfpc} | ||
|
||
uses | ||
sherpa_onnx, | ||
DateUtils, | ||
SysUtils; | ||
|
||
var | ||
Wave: TSherpaOnnxWave; | ||
WaveFilename: AnsiString; | ||
|
||
Config: TSherpaOnnxOfflineRecognizerConfig; | ||
Recognizer: TSherpaOnnxOfflineRecognizer; | ||
Stream: TSherpaOnnxOfflineStream; | ||
RecognitionResult: TSherpaOnnxOfflineRecognizerResult; | ||
|
||
Start: TDateTime; | ||
Stop: TDateTime; | ||
|
||
Elapsed: Single; | ||
Duration: Single; | ||
RealTimeFactor: Single; | ||
begin | ||
Config.ModelConfig.Paraformer.Model := './sherpa-onnx-paraformer-zh-2023-09-14/model.int8.onnx'; | ||
Config.ModelConfig.Tokens := './sherpa-onnx-paraformer-zh-2023-09-14/tokens.txt'; | ||
Config.ModelConfig.Provider := 'cpu'; | ||
Config.ModelConfig.NumThreads := 1; | ||
Config.ModelConfig.Debug := False; | ||
|
||
WaveFilename := './sherpa-onnx-paraformer-zh-2023-09-14/test_wavs/3-sichuan.wav'; | ||
|
||
Wave := SherpaOnnxReadWave(WaveFilename); | ||
|
||
Recognizer := TSherpaOnnxOfflineRecognizer.Create(Config); | ||
Stream := Recognizer.CreateStream(); | ||
Start := Now; | ||
|
||
Stream.AcceptWaveform(Wave.Samples, Wave.SampleRate); | ||
Recognizer.Decode(Stream); | ||
|
||
RecognitionResult := Recognizer.GetResult(Stream); | ||
|
||
Stop := Now; | ||
|
||
Elapsed := MilliSecondsBetween(Stop, Start) / 1000; | ||
Duration := Length(Wave.Samples) / Wave.SampleRate; | ||
RealTimeFactor := Elapsed / Duration; | ||
|
||
WriteLn(RecognitionResult.ToString); | ||
WriteLn(Format('NumThreads %d', [Config.ModelConfig.NumThreads])); | ||
WriteLn(Format('Elapsed %.3f s', [Elapsed])); | ||
WriteLn(Format('Wave duration %.3f s', [Duration])); | ||
WriteLn(Format('RTF = %.3f/%.3f = %.3f', [Elapsed, Duration, RealTimeFactor])); | ||
|
||
{Free resources to avoid memory leak. | ||
Note: You don't need to invoke them for this simple script. | ||
However, you have to invoke them in your own large/complex project. | ||
} | ||
FreeAndNil(Stream); | ||
FreeAndNil(Recognizer); | ||
end. |
Oops, something went wrong.