Committed by
GitHub
Add non-streaming ASR examples for Dart API (#1007)
正在显示
35 个修改的文件
包含
984 行增加
和
37 行删除
.github/scripts/test-dart.sh
0 → 100755
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +set -ex | ||
| 4 | + | ||
| 5 | +cd dart-api-examples | ||
| 6 | + | ||
| 7 | +pushd non-streaming-asr | ||
| 8 | + | ||
| 9 | +echo '----------VAD with paraformer----------' | ||
| 10 | +./run-vad-with-paraformer.sh | ||
| 11 | +rm -rf sherpa-onnx-* | ||
| 12 | + | ||
| 13 | +echo '----------NeMo transducer----------' | ||
| 14 | +./run-nemo-transducer.sh | ||
| 15 | +rm -rf sherpa-onnx-* | ||
| 16 | + | ||
| 17 | +echo '----------NeMo CTC----------' | ||
| 18 | +./run-nemo-ctc.sh | ||
| 19 | +rm -rf sherpa-onnx-* | ||
| 20 | + | ||
| 21 | +echo '----------TeleSpeech CTC----------' | ||
| 22 | +./run-telespeech-ctc.sh | ||
| 23 | +rm -rf sherpa-onnx-* | ||
| 24 | + | ||
| 25 | +echo '----------paraformer----------' | ||
| 26 | +./run-paraformer.sh | ||
| 27 | +rm -rf sherpa-onnx-* | ||
| 28 | + | ||
| 29 | +echo '----------whisper----------' | ||
| 30 | +./run-whisper.sh | ||
| 31 | +rm -rf sherpa-onnx-* | ||
| 32 | + | ||
| 33 | +echo '----------zipformer transducer----------' | ||
| 34 | +./run-zipformer-transducer.sh | ||
| 35 | +rm -rf sherpa-onnx-* | ||
| 36 | + | ||
| 37 | +popd | ||
| 38 | + | ||
| 39 | +pushd vad | ||
| 40 | +./run.sh | ||
| 41 | +rm *.onnx | ||
| 42 | +popd | ||
| 43 | + |
.github/workflows/test-dart-package.yaml
0 → 100644
| 1 | +name: test-dart-package | ||
| 2 | + | ||
| 3 | +on: | ||
| 4 | + schedule: | ||
| 5 | + # minute (0-59) | ||
| 6 | + # hour (0-23) | ||
| 7 | + # day of the month (1-31) | ||
| 8 | + # month (1-12) | ||
| 9 | + # day of the week (0-6) | ||
| 10 | + # nightly build at 15:50 UTC time every day | ||
| 11 | + - cron: "50 15 * * *" | ||
| 12 | + | ||
| 13 | + workflow_dispatch: | ||
| 14 | + | ||
| 15 | +concurrency: | ||
| 16 | + group: test-dart-package-${{ github.ref }} | ||
| 17 | + cancel-in-progress: true | ||
| 18 | + | ||
| 19 | +jobs: | ||
| 20 | + test_dart_package: | ||
| 21 | + name: ${{ matrix.os }} | ||
| 22 | + runs-on: ${{ matrix.os }} | ||
| 23 | + strategy: | ||
| 24 | + fail-fast: false | ||
| 25 | + matrix: | ||
| 26 | + os: [macos-latest, ubuntu-latest] #, windows-latest] | ||
| 27 | + | ||
| 28 | + steps: | ||
| 29 | + - uses: actions/checkout@v4 | ||
| 30 | + with: | ||
| 31 | + fetch-depth: 0 | ||
| 32 | + | ||
| 33 | + - name: Setup Flutter SDK | ||
| 34 | + uses: flutter-actions/setup-flutter@v3 | ||
| 35 | + with: | ||
| 36 | + channel: stable | ||
| 37 | + version: latest | ||
| 38 | + | ||
| 39 | + - name: Display flutter info | ||
| 40 | + shell: bash | ||
| 41 | + run: | | ||
| 42 | + which flutter | ||
| 43 | + which dart | ||
| 44 | + | ||
| 45 | + flutter --version | ||
| 46 | + dart --version | ||
| 47 | + flutter doctor | ||
| 48 | + | ||
| 49 | + - name: Run tests | ||
| 50 | + shell: bash | ||
| 51 | + run: | | ||
| 52 | + .github/scripts/test-dart.sh |
| @@ -21,19 +21,24 @@ concurrency: | @@ -21,19 +21,24 @@ concurrency: | ||
| 21 | cancel-in-progress: true | 21 | cancel-in-progress: true |
| 22 | 22 | ||
| 23 | jobs: | 23 | jobs: |
| 24 | - dart: | 24 | + test_dart: |
| 25 | name: ${{ matrix.os }} | 25 | name: ${{ matrix.os }} |
| 26 | runs-on: ${{ matrix.os }} | 26 | runs-on: ${{ matrix.os }} |
| 27 | strategy: | 27 | strategy: |
| 28 | fail-fast: false | 28 | fail-fast: false |
| 29 | matrix: | 29 | matrix: |
| 30 | - os: [macos-latest, ubuntu-latest] #, windows-latest] | 30 | + os: [ubuntu-latest] |
| 31 | 31 | ||
| 32 | steps: | 32 | steps: |
| 33 | - uses: actions/checkout@v4 | 33 | - uses: actions/checkout@v4 |
| 34 | with: | 34 | with: |
| 35 | fetch-depth: 0 | 35 | fetch-depth: 0 |
| 36 | 36 | ||
| 37 | + - name: ccache | ||
| 38 | + uses: hendrikmuhs/ccache-action@v1.2 | ||
| 39 | + with: | ||
| 40 | + key: ${{ matrix.os }}-dart | ||
| 41 | + | ||
| 37 | - name: Setup Flutter SDK | 42 | - name: Setup Flutter SDK |
| 38 | uses: flutter-actions/setup-flutter@v3 | 43 | uses: flutter-actions/setup-flutter@v3 |
| 39 | with: | 44 | with: |
| @@ -50,11 +55,39 @@ jobs: | @@ -50,11 +55,39 @@ jobs: | ||
| 50 | dart --version | 55 | dart --version |
| 51 | flutter doctor | 56 | flutter doctor |
| 52 | 57 | ||
| 58 | + - name: Build sherpa-onnx | ||
| 59 | + shell: bash | ||
| 60 | + run: | | ||
| 61 | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
| 62 | + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | ||
| 63 | + cmake --version | ||
| 64 | + mkdir build | ||
| 65 | + | ||
| 66 | + cd build | ||
| 67 | + | ||
| 68 | + cmake \ | ||
| 69 | + -D BUILD_SHARED_LIBS=ON \ | ||
| 70 | + -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ | ||
| 71 | + -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ | ||
| 72 | + -DBUILD_ESPEAK_NG_EXE=OFF \ | ||
| 73 | + -DSHERPA_ONNX_ENABLE_BINARY=OFF \ | ||
| 74 | + -DCMAKE_INSTALL_PREFIX=./install \ | ||
| 75 | + .. | ||
| 76 | + make -j install | ||
| 77 | + | ||
| 78 | + - name: Copy libs | ||
| 79 | + shell: bash | ||
| 80 | + run: | | ||
| 81 | + cp -v build/install/lib/lib* ./sherpa-onnx/flutter/linux/ | ||
| 82 | + | ||
| 83 | + echo "--------------------" | ||
| 84 | + | ||
| 85 | + ls -lh ./sherpa-onnx/flutter/linux/ | ||
| 86 | + | ||
| 53 | - name: Run tests | 87 | - name: Run tests |
| 54 | shell: bash | 88 | shell: bash |
| 55 | run: | | 89 | run: | |
| 56 | - cd dart-api-examples | 90 | + cp scripts/dart/vad-pubspec.yaml dart-api-examples/vad/pubspec.yaml |
| 91 | + cp scripts/dart/non-streaming-asr-pubspec.yaml dart-api-examples/non-streaming-asr/pubspec.yaml | ||
| 57 | 92 | ||
| 58 | - pushd vad | ||
| 59 | - ./run.sh | ||
| 60 | - popd | 93 | + .github/scripts/test-dart.sh |
dart-api-examples/.gitignore
0 → 100644
| 1 | +!run*.sh |
| 1 | +# Introduction | ||
| 2 | + | ||
| 3 | +This folder contains examples for non-streaming ASR with Dart API. | ||
| 4 | + | ||
| 5 | +| File | Description| | ||
| 6 | +|------|------------| | ||
| 7 | +|[./bin/nemo-ctc.dart](./bin/nemo-ctc.dart)| Use a NeMo Ctc model for speech recognition. See [./run-nemo-ctc.sh](./run-nemo-ctc.sh)| | ||
| 8 | +|[./bin/nemo-transducer.dart](./bin/nemo-transducer.dart)| Use a NeMo transducer model for speech recognition. See [./run-nemo-transducer.sh](./run-nemo-transducer.sh)| | ||
| 9 | +|[./bin/paraformer.dart](./bin/paraformer.dart)|Use a paraformer model for speech recognition. See [./run-paraformer.sh](./run-paraformer.sh)| | ||
| 10 | +|[./bin/telespeech-ctc.dart](./bin/telespeech-ctc.dart)| Use models from [Tele-AI/TeleSpeech-ASR](https://github.com/Tele-AI/TeleSpeech-ASR) for speech recognition. See [./run-telespeech-ctc.sh](./run-telespeech-ctc.sh)| | ||
| 11 | +|[./bin/whisper.dart](./bin/whisper.dart)| Use whisper for speech recognition. See [./run-whisper.sh](./run-whisper.sh)| | ||
| 12 | +|[./bin/zipformer-transducer.dart](./bin/zipformer-transducer.dart)| Use a zipformer transducer for speech recognition. See [./run-zipformer-transducer.sh](./run-zipformer-transducer.sh)| | ||
| 13 | +|[./bin/vad-with-paraformer.dart](./bin/vad-with-paraformer.dart)| Use a [silero-vad](https://github.com/snakers4/silero-vad) with paraformer for speech recognition. See [./run-vad-with-paraformer.sh](./run-vad-with-paraformer.sh)| | ||
| 14 | + |
| 1 | +# This file configures the static analysis results for your project (errors, | ||
| 2 | +# warnings, and lints). | ||
| 3 | +# | ||
| 4 | +# This enables the 'recommended' set of lints from `package:lints`. | ||
| 5 | +# This set helps identify many issues that may lead to problems when running | ||
| 6 | +# or consuming Dart code, and enforces writing Dart using a single, idiomatic | ||
| 7 | +# style and format. | ||
| 8 | +# | ||
| 9 | +# If you want a smaller set of lints you can change this to specify | ||
| 10 | +# 'package:lints/core.yaml'. These are just the most critical lints | ||
| 11 | +# (the recommended set includes the core lints). | ||
| 12 | +# The core lints are also what is used by pub.dev for scoring packages. | ||
| 13 | + | ||
| 14 | +include: package:lints/recommended.yaml | ||
| 15 | + | ||
| 16 | +# Uncomment the following section to specify additional rules. | ||
| 17 | + | ||
| 18 | +# linter: | ||
| 19 | +# rules: | ||
| 20 | +# - camel_case_types | ||
| 21 | + | ||
| 22 | +# analyzer: | ||
| 23 | +# exclude: | ||
| 24 | +# - path/to/excluded/files/** | ||
| 25 | + | ||
| 26 | +# For more information about the core and recommended set of lints, see | ||
| 27 | +# https://dart.dev/go/core-lints | ||
| 28 | + | ||
| 29 | +# For additional information about configuring this file, see | ||
| 30 | +# https://dart.dev/guides/language/analysis-options |
| 1 | +../../vad/bin/init.dart |
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:typed_data'; | ||
| 3 | + | ||
| 4 | +import 'package:args/args.dart'; | ||
| 5 | +import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
| 6 | + | ||
| 7 | +import './init.dart'; | ||
| 8 | + | ||
| 9 | +void main(List<String> arguments) async { | ||
| 10 | + await initSherpaOnnx(); | ||
| 11 | + | ||
| 12 | + final parser = ArgParser() | ||
| 13 | + ..addOption('model', help: 'Path to the NeMo CTC model') | ||
| 14 | + ..addOption('tokens', help: 'Path to tokens.txt') | ||
| 15 | + ..addOption('input-wav', help: 'Path to input.wav to transcribe'); | ||
| 16 | + | ||
| 17 | + final res = parser.parse(arguments); | ||
| 18 | + if (res['model'] == null || | ||
| 19 | + res['tokens'] == null || | ||
| 20 | + res['input-wav'] == null) { | ||
| 21 | + print(parser.usage); | ||
| 22 | + exit(1); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + final model = res['model'] as String; | ||
| 26 | + final tokens = res['tokens'] as String; | ||
| 27 | + final inputWav = res['input-wav'] as String; | ||
| 28 | + | ||
| 29 | + final nemo = sherpa_onnx.OfflineNemoEncDecCtcModelConfig(model: model); | ||
| 30 | + | ||
| 31 | + final modelConfig = sherpa_onnx.OfflineModelConfig( | ||
| 32 | + nemoCtc: nemo, | ||
| 33 | + tokens: tokens, | ||
| 34 | + debug: true, | ||
| 35 | + numThreads: 1, | ||
| 36 | + ); | ||
| 37 | + final config = sherpa_onnx.OfflineRecognizerConfig(model: modelConfig); | ||
| 38 | + final recognizer = sherpa_onnx.OfflineRecognizer(config); | ||
| 39 | + | ||
| 40 | + final waveData = sherpa_onnx.readWave(inputWav); | ||
| 41 | + final stream = recognizer.createStream(); | ||
| 42 | + | ||
| 43 | + stream.acceptWaveform( | ||
| 44 | + samples: waveData.samples, sampleRate: waveData.sampleRate); | ||
| 45 | + recognizer.decode(stream); | ||
| 46 | + | ||
| 47 | + final result = recognizer.getResult(stream); | ||
| 48 | + print(result.text); | ||
| 49 | + | ||
| 50 | + stream.free(); | ||
| 51 | + recognizer.free(); | ||
| 52 | +} |
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:typed_data'; | ||
| 3 | + | ||
| 4 | +import 'package:args/args.dart'; | ||
| 5 | +import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
| 6 | + | ||
| 7 | +import './init.dart'; | ||
| 8 | + | ||
| 9 | +void main(List<String> arguments) async { | ||
| 10 | + await initSherpaOnnx(); | ||
| 11 | + | ||
| 12 | + final parser = ArgParser() | ||
| 13 | + ..addOption('encoder', help: 'Path to the encoder model') | ||
| 14 | + ..addOption('decoder', help: 'Path to decoder model') | ||
| 15 | + ..addOption('joiner', help: 'Path to joiner model') | ||
| 16 | + ..addOption('tokens', help: 'Path to tokens.txt') | ||
| 17 | + ..addOption('input-wav', help: 'Path to input.wav to transcribe'); | ||
| 18 | + | ||
| 19 | + final res = parser.parse(arguments); | ||
| 20 | + if (res['encoder'] == null || | ||
| 21 | + res['decoder'] == null || | ||
| 22 | + res['joiner'] == null || | ||
| 23 | + res['tokens'] == null || | ||
| 24 | + res['input-wav'] == null) { | ||
| 25 | + print(parser.usage); | ||
| 26 | + exit(1); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + final encoder = res['encoder'] as String; | ||
| 30 | + final decoder = res['decoder'] as String; | ||
| 31 | + final joiner = res['joiner'] as String; | ||
| 32 | + final tokens = res['tokens'] as String; | ||
| 33 | + final inputWav = res['input-wav'] as String; | ||
| 34 | + | ||
| 35 | + final transducer = sherpa_onnx.OfflineTransducerModelConfig( | ||
| 36 | + encoder: encoder, | ||
| 37 | + decoder: decoder, | ||
| 38 | + joiner: joiner, | ||
| 39 | + ); | ||
| 40 | + | ||
| 41 | + final modelConfig = sherpa_onnx.OfflineModelConfig( | ||
| 42 | + transducer: transducer, | ||
| 43 | + tokens: tokens, | ||
| 44 | + debug: true, | ||
| 45 | + numThreads: 1, | ||
| 46 | + ); | ||
| 47 | + final config = sherpa_onnx.OfflineRecognizerConfig(model: modelConfig); | ||
| 48 | + final recognizer = sherpa_onnx.OfflineRecognizer(config); | ||
| 49 | + | ||
| 50 | + final waveData = sherpa_onnx.readWave(inputWav); | ||
| 51 | + final stream = recognizer.createStream(); | ||
| 52 | + | ||
| 53 | + stream.acceptWaveform( | ||
| 54 | + samples: waveData.samples, sampleRate: waveData.sampleRate); | ||
| 55 | + recognizer.decode(stream); | ||
| 56 | + | ||
| 57 | + final result = recognizer.getResult(stream); | ||
| 58 | + print(result.text); | ||
| 59 | + | ||
| 60 | + stream.free(); | ||
| 61 | + recognizer.free(); | ||
| 62 | +} |
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:typed_data'; | ||
| 3 | + | ||
| 4 | +import 'package:args/args.dart'; | ||
| 5 | +import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
| 6 | + | ||
| 7 | +import './init.dart'; | ||
| 8 | + | ||
| 9 | +void main(List<String> arguments) async { | ||
| 10 | + await initSherpaOnnx(); | ||
| 11 | + | ||
| 12 | + final parser = ArgParser() | ||
| 13 | + ..addOption('model', help: 'Path to the paraformer model') | ||
| 14 | + ..addOption('tokens', help: 'Path to tokens.txt') | ||
| 15 | + ..addOption('input-wav', help: 'Path to input.wav to transcribe'); | ||
| 16 | + | ||
| 17 | + final res = parser.parse(arguments); | ||
| 18 | + if (res['model'] == null || | ||
| 19 | + res['tokens'] == null || | ||
| 20 | + res['input-wav'] == null) { | ||
| 21 | + print(parser.usage); | ||
| 22 | + exit(1); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + final model = res['model'] as String; | ||
| 26 | + final tokens = res['tokens'] as String; | ||
| 27 | + final inputWav = res['input-wav'] as String; | ||
| 28 | + | ||
| 29 | + final paraformer = sherpa_onnx.OfflineParaformerModelConfig( | ||
| 30 | + model: model, | ||
| 31 | + ); | ||
| 32 | + | ||
| 33 | + final modelConfig = sherpa_onnx.OfflineModelConfig( | ||
| 34 | + paraformer: paraformer, | ||
| 35 | + tokens: tokens, | ||
| 36 | + debug: true, | ||
| 37 | + numThreads: 1, | ||
| 38 | + modelType: 'paraformer', | ||
| 39 | + ); | ||
| 40 | + final config = sherpa_onnx.OfflineRecognizerConfig(model: modelConfig); | ||
| 41 | + final recognizer = sherpa_onnx.OfflineRecognizer(config); | ||
| 42 | + | ||
| 43 | + final waveData = sherpa_onnx.readWave(inputWav); | ||
| 44 | + final stream = recognizer.createStream(); | ||
| 45 | + | ||
| 46 | + stream.acceptWaveform( | ||
| 47 | + samples: waveData.samples, sampleRate: waveData.sampleRate); | ||
| 48 | + recognizer.decode(stream); | ||
| 49 | + | ||
| 50 | + final result = recognizer.getResult(stream); | ||
| 51 | + print(result.text); | ||
| 52 | + | ||
| 53 | + stream.free(); | ||
| 54 | + recognizer.free(); | ||
| 55 | +} |
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:typed_data'; | ||
| 3 | + | ||
| 4 | +import 'package:args/args.dart'; | ||
| 5 | +import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
| 6 | + | ||
| 7 | +import './init.dart'; | ||
| 8 | + | ||
| 9 | +void main(List<String> arguments) async { | ||
| 10 | + await initSherpaOnnx(); | ||
| 11 | + | ||
| 12 | + final parser = ArgParser() | ||
| 13 | + ..addOption('model', help: 'Path to the telespeech CTC model') | ||
| 14 | + ..addOption('tokens', help: 'Path to tokens.txt') | ||
| 15 | + ..addOption('input-wav', help: 'Path to input.wav to transcribe'); | ||
| 16 | + | ||
| 17 | + final res = parser.parse(arguments); | ||
| 18 | + if (res['model'] == null || | ||
| 19 | + res['tokens'] == null || | ||
| 20 | + res['input-wav'] == null) { | ||
| 21 | + print(parser.usage); | ||
| 22 | + exit(1); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + final model = res['model'] as String; | ||
| 26 | + final tokens = res['tokens'] as String; | ||
| 27 | + final inputWav = res['input-wav'] as String; | ||
| 28 | + | ||
| 29 | + final modelConfig = sherpa_onnx.OfflineModelConfig( | ||
| 30 | + telespeechCtc: model, | ||
| 31 | + tokens: tokens, | ||
| 32 | + debug: true, | ||
| 33 | + numThreads: 1, | ||
| 34 | + modelType: 'telespeech_ctc', | ||
| 35 | + ); | ||
| 36 | + final config = sherpa_onnx.OfflineRecognizerConfig(model: modelConfig); | ||
| 37 | + final recognizer = sherpa_onnx.OfflineRecognizer(config); | ||
| 38 | + | ||
| 39 | + final waveData = sherpa_onnx.readWave(inputWav); | ||
| 40 | + final stream = recognizer.createStream(); | ||
| 41 | + | ||
| 42 | + stream.acceptWaveform( | ||
| 43 | + samples: waveData.samples, sampleRate: waveData.sampleRate); | ||
| 44 | + recognizer.decode(stream); | ||
| 45 | + | ||
| 46 | + final result = recognizer.getResult(stream); | ||
| 47 | + print(result.text); | ||
| 48 | + | ||
| 49 | + stream.free(); | ||
| 50 | + recognizer.free(); | ||
| 51 | +} |
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:typed_data'; | ||
| 3 | + | ||
| 4 | +import 'package:args/args.dart'; | ||
| 5 | +import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
| 6 | + | ||
| 7 | +import './init.dart'; | ||
| 8 | + | ||
| 9 | +void main(List<String> arguments) async { | ||
| 10 | + await initSherpaOnnx(); | ||
| 11 | + | ||
| 12 | + final parser = ArgParser() | ||
| 13 | + ..addOption('silero-vad', help: 'Path to silero_vad.onnx') | ||
| 14 | + ..addOption('model', help: 'Path to the paraformer model') | ||
| 15 | + ..addOption('tokens', help: 'Path to tokens.txt') | ||
| 16 | + ..addOption('input-wav', help: 'Path to input.wav to transcribe'); | ||
| 17 | + | ||
| 18 | + final res = parser.parse(arguments); | ||
| 19 | + if (res['silero-vad'] == null || | ||
| 20 | + res['model'] == null || | ||
| 21 | + res['tokens'] == null || | ||
| 22 | + res['input-wav'] == null) { | ||
| 23 | + print(parser.usage); | ||
| 24 | + exit(1); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + final sileroVad = res['silero-vad'] as String; | ||
| 28 | + final model = res['model'] as String; | ||
| 29 | + final tokens = res['tokens'] as String; | ||
| 30 | + final inputWav = res['input-wav'] as String; | ||
| 31 | + | ||
| 32 | + final paraformer = sherpa_onnx.OfflineParaformerModelConfig( | ||
| 33 | + model: model, | ||
| 34 | + ); | ||
| 35 | + | ||
| 36 | + final modelConfig = sherpa_onnx.OfflineModelConfig( | ||
| 37 | + paraformer: paraformer, | ||
| 38 | + tokens: tokens, | ||
| 39 | + debug: true, | ||
| 40 | + numThreads: 1, | ||
| 41 | + modelType: 'paraformer', | ||
| 42 | + ); | ||
| 43 | + final config = sherpa_onnx.OfflineRecognizerConfig(model: modelConfig); | ||
| 44 | + final recognizer = sherpa_onnx.OfflineRecognizer(config); | ||
| 45 | + | ||
| 46 | + final sileroVadConfig = sherpa_onnx.SileroVadModelConfig( | ||
| 47 | + model: sileroVad, | ||
| 48 | + minSilenceDuration: 0.25, | ||
| 49 | + minSpeechDuration: 0.5, | ||
| 50 | + ); | ||
| 51 | + | ||
| 52 | + final vadConfig = sherpa_onnx.VadModelConfig( | ||
| 53 | + sileroVad: sileroVadConfig, | ||
| 54 | + numThreads: 1, | ||
| 55 | + debug: true, | ||
| 56 | + ); | ||
| 57 | + | ||
| 58 | + final vad = sherpa_onnx.VoiceActivityDetector( | ||
| 59 | + config: vadConfig, bufferSizeInSeconds: 10); | ||
| 60 | + | ||
| 61 | + final waveData = sherpa_onnx.readWave(inputWav); | ||
| 62 | + | ||
| 63 | + int numSamples = waveData.samples.length; | ||
| 64 | + int numIter = numSamples ~/ vadConfig.sileroVad.windowSize; | ||
| 65 | + | ||
| 66 | + for (int i = 0; i != numIter; ++i) { | ||
| 67 | + int start = i * vadConfig.sileroVad.windowSize; | ||
| 68 | + vad.acceptWaveform(Float32List.sublistView( | ||
| 69 | + waveData.samples, start, start + vadConfig.sileroVad.windowSize)); | ||
| 70 | + | ||
| 71 | + if (vad.isDetected()) { | ||
| 72 | + while (!vad.isEmpty()) { | ||
| 73 | + final stream = recognizer.createStream(); | ||
| 74 | + final segment = vad.front(); | ||
| 75 | + stream.acceptWaveform( | ||
| 76 | + samples: segment.samples, sampleRate: waveData.sampleRate); | ||
| 77 | + recognizer.decode(stream); | ||
| 78 | + | ||
| 79 | + final result = recognizer.getResult(stream); | ||
| 80 | + | ||
| 81 | + final startTime = segment.start * 1.0 / waveData.sampleRate; | ||
| 82 | + final duration = segment.samples.length * 1.0 / waveData.sampleRate; | ||
| 83 | + final stopTime = startTime + duration; | ||
| 84 | + if (result.text != '') { | ||
| 85 | + print( | ||
| 86 | + '${startTime.toStringAsPrecision(4)} -- ${stopTime.toStringAsPrecision(4)}: ${result.text}'); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + stream.free(); | ||
| 90 | + vad.pop(); | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + vad.free(); | ||
| 96 | + recognizer.free(); | ||
| 97 | +} |
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:typed_data'; | ||
| 3 | + | ||
| 4 | +import 'package:args/args.dart'; | ||
| 5 | +import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
| 6 | + | ||
| 7 | +import './init.dart'; | ||
| 8 | + | ||
| 9 | +void main(List<String> arguments) async { | ||
| 10 | + await initSherpaOnnx(); | ||
| 11 | + | ||
| 12 | + final parser = ArgParser() | ||
| 13 | + ..addOption('encoder', help: 'Path to the whisper encoder model') | ||
| 14 | + ..addOption('decoder', help: 'Path to whisper decoder model') | ||
| 15 | + ..addOption('tokens', help: 'Path to tokens.txt') | ||
| 16 | + ..addOption('input-wav', help: 'Path to input.wav to transcribe'); | ||
| 17 | + | ||
| 18 | + final res = parser.parse(arguments); | ||
| 19 | + if (res['encoder'] == null || | ||
| 20 | + res['decoder'] == null || | ||
| 21 | + res['tokens'] == null || | ||
| 22 | + res['input-wav'] == null) { | ||
| 23 | + print(parser.usage); | ||
| 24 | + exit(1); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + final encoder = res['encoder'] as String; | ||
| 28 | + final decoder = res['decoder'] as String; | ||
| 29 | + final tokens = res['tokens'] as String; | ||
| 30 | + final inputWav = res['input-wav'] as String; | ||
| 31 | + | ||
| 32 | + final whisper = sherpa_onnx.OfflineWhisperModelConfig( | ||
| 33 | + encoder: encoder, | ||
| 34 | + decoder: decoder, | ||
| 35 | + ); | ||
| 36 | + | ||
| 37 | + final modelConfig = sherpa_onnx.OfflineModelConfig( | ||
| 38 | + whisper: whisper, | ||
| 39 | + tokens: tokens, | ||
| 40 | + modelType: 'whisper', | ||
| 41 | + debug: false, | ||
| 42 | + numThreads: 1, | ||
| 43 | + ); | ||
| 44 | + final config = sherpa_onnx.OfflineRecognizerConfig(model: modelConfig); | ||
| 45 | + final recognizer = sherpa_onnx.OfflineRecognizer(config); | ||
| 46 | + | ||
| 47 | + final waveData = sherpa_onnx.readWave(inputWav); | ||
| 48 | + final stream = recognizer.createStream(); | ||
| 49 | + | ||
| 50 | + stream.acceptWaveform( | ||
| 51 | + samples: waveData.samples, sampleRate: waveData.sampleRate); | ||
| 52 | + recognizer.decode(stream); | ||
| 53 | + | ||
| 54 | + final result = recognizer.getResult(stream); | ||
| 55 | + print(result.text); | ||
| 56 | + | ||
| 57 | + stream.free(); | ||
| 58 | + recognizer.free(); | ||
| 59 | +} |
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:typed_data'; | ||
| 3 | + | ||
| 4 | +import 'package:args/args.dart'; | ||
| 5 | +import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
| 6 | + | ||
| 7 | +import './init.dart'; | ||
| 8 | + | ||
| 9 | +void main(List<String> arguments) async { | ||
| 10 | + await initSherpaOnnx(); | ||
| 11 | + | ||
| 12 | + final parser = ArgParser() | ||
| 13 | + ..addOption('encoder', help: 'Path to the encoder model') | ||
| 14 | + ..addOption('decoder', help: 'Path to decoder model') | ||
| 15 | + ..addOption('joiner', help: 'Path to joiner model') | ||
| 16 | + ..addOption('tokens', help: 'Path to tokens.txt') | ||
| 17 | + ..addOption('input-wav', help: 'Path to input.wav to transcribe'); | ||
| 18 | + | ||
| 19 | + final res = parser.parse(arguments); | ||
| 20 | + if (res['encoder'] == null || | ||
| 21 | + res['decoder'] == null || | ||
| 22 | + res['joiner'] == null || | ||
| 23 | + res['tokens'] == null || | ||
| 24 | + res['input-wav'] == null) { | ||
| 25 | + print(parser.usage); | ||
| 26 | + exit(1); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + final encoder = res['encoder'] as String; | ||
| 30 | + final decoder = res['decoder'] as String; | ||
| 31 | + final joiner = res['joiner'] as String; | ||
| 32 | + final tokens = res['tokens'] as String; | ||
| 33 | + final inputWav = res['input-wav'] as String; | ||
| 34 | + | ||
| 35 | + final transducer = sherpa_onnx.OfflineTransducerModelConfig( | ||
| 36 | + encoder: encoder, | ||
| 37 | + decoder: decoder, | ||
| 38 | + joiner: joiner, | ||
| 39 | + ); | ||
| 40 | + | ||
| 41 | + final modelConfig = sherpa_onnx.OfflineModelConfig( | ||
| 42 | + transducer: transducer, | ||
| 43 | + tokens: tokens, | ||
| 44 | + debug: true, | ||
| 45 | + numThreads: 1, | ||
| 46 | + ); | ||
| 47 | + final config = sherpa_onnx.OfflineRecognizerConfig(model: modelConfig); | ||
| 48 | + final recognizer = sherpa_onnx.OfflineRecognizer(config); | ||
| 49 | + | ||
| 50 | + final waveData = sherpa_onnx.readWave(inputWav); | ||
| 51 | + final stream = recognizer.createStream(); | ||
| 52 | + | ||
| 53 | + stream.acceptWaveform( | ||
| 54 | + samples: waveData.samples, sampleRate: waveData.sampleRate); | ||
| 55 | + recognizer.decode(stream); | ||
| 56 | + | ||
| 57 | + final result = recognizer.getResult(stream); | ||
| 58 | + print(result.text); | ||
| 59 | + | ||
| 60 | + stream.free(); | ||
| 61 | + recognizer.free(); | ||
| 62 | +} |
| 1 | +# Generated by pub | ||
| 2 | +# See https://dart.dev/tools/pub/glossary#lockfile | ||
| 3 | +packages: | ||
| 4 | + args: | ||
| 5 | + dependency: "direct main" | ||
| 6 | + description: | ||
| 7 | + name: args | ||
| 8 | + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" | ||
| 9 | + url: "https://pub.dev" | ||
| 10 | + source: hosted | ||
| 11 | + version: "2.5.0" | ||
| 12 | + characters: | ||
| 13 | + dependency: transitive | ||
| 14 | + description: | ||
| 15 | + name: characters | ||
| 16 | + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" | ||
| 17 | + url: "https://pub.dev" | ||
| 18 | + source: hosted | ||
| 19 | + version: "1.3.0" | ||
| 20 | + collection: | ||
| 21 | + dependency: transitive | ||
| 22 | + description: | ||
| 23 | + name: collection | ||
| 24 | + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a | ||
| 25 | + url: "https://pub.dev" | ||
| 26 | + source: hosted | ||
| 27 | + version: "1.18.0" | ||
| 28 | + ffi: | ||
| 29 | + dependency: transitive | ||
| 30 | + description: | ||
| 31 | + name: ffi | ||
| 32 | + sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" | ||
| 33 | + url: "https://pub.dev" | ||
| 34 | + source: hosted | ||
| 35 | + version: "2.1.2" | ||
| 36 | + flutter: | ||
| 37 | + dependency: transitive | ||
| 38 | + description: flutter | ||
| 39 | + source: sdk | ||
| 40 | + version: "0.0.0" | ||
| 41 | + lints: | ||
| 42 | + dependency: "direct dev" | ||
| 43 | + description: | ||
| 44 | + name: lints | ||
| 45 | + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 | ||
| 46 | + url: "https://pub.dev" | ||
| 47 | + source: hosted | ||
| 48 | + version: "3.0.0" | ||
| 49 | + material_color_utilities: | ||
| 50 | + dependency: transitive | ||
| 51 | + description: | ||
| 52 | + name: material_color_utilities | ||
| 53 | + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" | ||
| 54 | + url: "https://pub.dev" | ||
| 55 | + source: hosted | ||
| 56 | + version: "0.8.0" | ||
| 57 | + meta: | ||
| 58 | + dependency: transitive | ||
| 59 | + description: | ||
| 60 | + name: meta | ||
| 61 | + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" | ||
| 62 | + url: "https://pub.dev" | ||
| 63 | + source: hosted | ||
| 64 | + version: "1.12.0" | ||
| 65 | + path: | ||
| 66 | + dependency: "direct main" | ||
| 67 | + description: | ||
| 68 | + name: path | ||
| 69 | + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" | ||
| 70 | + url: "https://pub.dev" | ||
| 71 | + source: hosted | ||
| 72 | + version: "1.9.0" | ||
| 73 | + sherpa_onnx: | ||
| 74 | + dependency: "direct main" | ||
| 75 | + description: | ||
| 76 | + name: sherpa_onnx | ||
| 77 | + sha256: e45894f81e7c854ca96d678bcab5303036e884a7c90e9a6c4ec04c7b1ee215a8 | ||
| 78 | + url: "https://pub.dev" | ||
| 79 | + source: hosted | ||
| 80 | + version: "1.9.29" | ||
| 81 | + sky_engine: | ||
| 82 | + dependency: transitive | ||
| 83 | + description: flutter | ||
| 84 | + source: sdk | ||
| 85 | + version: "0.0.99" | ||
| 86 | + vector_math: | ||
| 87 | + dependency: transitive | ||
| 88 | + description: | ||
| 89 | + name: vector_math | ||
| 90 | + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" | ||
| 91 | + url: "https://pub.dev" | ||
| 92 | + source: hosted | ||
| 93 | + version: "2.1.4" | ||
| 94 | +sdks: | ||
| 95 | + dart: ">=3.4.0 <4.0.0" | ||
| 96 | + flutter: ">=3.3.0" |
| 1 | +name: non_streaming_asr | ||
| 2 | +description: > | ||
| 3 | + This example demonstrates how to use the Dart API for Non-streaming speech recognition. Specifically, we use the following models as examples, whisper, zipformer, and paraformer. | ||
| 4 | + | ||
| 5 | +version: 1.0.0 | ||
| 6 | +# repository: https://github.com/my_org/my_repo | ||
| 7 | + | ||
| 8 | +environment: | ||
| 9 | + sdk: ^3.4.0 | ||
| 10 | + | ||
| 11 | +# Add regular dependencies here. | ||
| 12 | +dependencies: | ||
| 13 | + sherpa_onnx: ^1.9.29 | ||
| 14 | + path: ^1.9.0 | ||
| 15 | + args: ^2.5.0 | ||
| 16 | + | ||
| 17 | +dev_dependencies: | ||
| 18 | + lints: ^3.0.0 |
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +set -ex | ||
| 4 | + | ||
| 5 | +dart pub get | ||
| 6 | + | ||
| 7 | +if [ ! -f ./sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k/tokens.txt ]; then | ||
| 8 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2 | ||
| 9 | + tar xvf sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2 | ||
| 10 | + rm sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2 | ||
| 11 | +fi | ||
| 12 | + | ||
| 13 | +dart run \ | ||
| 14 | + ./bin/nemo-ctc.dart \ | ||
| 15 | + --model ./sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k/model.onnx \ | ||
| 16 | + --tokens ./sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k/tokens.txt \ | ||
| 17 | + --input-wav ./sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k/test_wavs/de-german.wav |
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +set -ex | ||
| 4 | + | ||
| 5 | +dart pub get | ||
| 6 | + | ||
| 7 | +if [ ! -f ./sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/tokens.txt ]; then | ||
| 8 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2 | ||
| 9 | + | ||
| 10 | + tar xvf sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2 | ||
| 11 | + rm sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2 | ||
| 12 | +fi | ||
| 13 | + | ||
| 14 | +dart run \ | ||
| 15 | + ./bin/nemo-transducer.dart \ | ||
| 16 | + --encoder ./sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/encoder.onnx \ | ||
| 17 | + --decoder ./sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/decoder.onnx \ | ||
| 18 | + --joiner ./sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/joiner.onnx \ | ||
| 19 | + --tokens ./sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/tokens.txt \ | ||
| 20 | + --input-wav ./sherpa-onnx-nemo-fast-conformer-transducer-be-de-en-es-fr-hr-it-pl-ru-uk-20k/test_wavs/de-german.wav |
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +set -ex | ||
| 4 | + | ||
| 5 | +dart pub get | ||
| 6 | + | ||
| 7 | +if [ ! -f ./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt ]; then | ||
| 8 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
| 9 | + | ||
| 10 | + tar xvf sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
| 11 | + rm sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
| 12 | +fi | ||
| 13 | + | ||
| 14 | +dart run \ | ||
| 15 | + ./bin/paraformer.dart \ | ||
| 16 | + --model ./sherpa-onnx-paraformer-zh-2023-03-28/model.int8.onnx \ | ||
| 17 | + --tokens ./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt \ | ||
| 18 | + --input-wav ./sherpa-onnx-paraformer-zh-2023-03-28/test_wavs/3-sichuan.wav |
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +set -ex | ||
| 4 | + | ||
| 5 | +dart pub get | ||
| 6 | + | ||
| 7 | +if [ ! -f ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/tokens.txt ]; then | ||
| 8 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04.tar.bz2 | ||
| 9 | + | ||
| 10 | + tar xvf sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04.tar.bz2 | ||
| 11 | + rm sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04.tar.bz2 | ||
| 12 | +fi | ||
| 13 | + | ||
| 14 | +dart run \ | ||
| 15 | + ./bin/telespeech-ctc.dart \ | ||
| 16 | + --model ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/model.int8.onnx \ | ||
| 17 | + --tokens ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/tokens.txt \ | ||
| 18 | + --input-wav ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/test_wavs/3-sichuan.wav |
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +set -ex | ||
| 4 | + | ||
| 5 | +dart pub get | ||
| 6 | + | ||
| 7 | +if [[ ! -f ./silero_vad.onnx ]]; then | ||
| 8 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx | ||
| 9 | +fi | ||
| 10 | + | ||
| 11 | +if [[ ! -f ./lei-jun-test.wav ]]; then | ||
| 12 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/lei-jun-test.wav | ||
| 13 | +fi | ||
| 14 | + | ||
| 15 | +if [ ! -f ./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt ]; then | ||
| 16 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
| 17 | + | ||
| 18 | + tar xvf sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
| 19 | + rm sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2 | ||
| 20 | +fi | ||
| 21 | + | ||
| 22 | +dart run \ | ||
| 23 | + ./bin/vad-with-paraformer.dart \ | ||
| 24 | + --silero-vad ./silero_vad.onnx \ | ||
| 25 | + --model ./sherpa-onnx-paraformer-zh-2023-03-28/model.int8.onnx \ | ||
| 26 | + --tokens ./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt \ | ||
| 27 | + --input-wav ./lei-jun-test.wav |
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +set -ex | ||
| 4 | + | ||
| 5 | +dart pub get | ||
| 6 | + | ||
| 7 | +if [ ! -f ./sherpa-onnx-whisper-tiny.en/tiny.en-tokens.txt ]; then | ||
| 8 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-whisper-tiny.en.tar.bz2 | ||
| 9 | + | ||
| 10 | + tar xvf sherpa-onnx-whisper-tiny.en.tar.bz2 | ||
| 11 | + rm sherpa-onnx-whisper-tiny.en.tar.bz2 | ||
| 12 | +fi | ||
| 13 | + | ||
| 14 | +dart run \ | ||
| 15 | + ./bin/whisper.dart \ | ||
| 16 | + --encoder ./sherpa-onnx-whisper-tiny.en/tiny.en-encoder.int8.onnx \ | ||
| 17 | + --decoder ./sherpa-onnx-whisper-tiny.en/tiny.en-decoder.int8.onnx \ | ||
| 18 | + --tokens ./sherpa-onnx-whisper-tiny.en/tiny.en-tokens.txt \ | ||
| 19 | + --input-wav ./sherpa-onnx-whisper-tiny.en/test_wavs/0.wav |
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +set -ex | ||
| 4 | + | ||
| 5 | +dart pub get | ||
| 6 | + | ||
| 7 | +if [ ! -f ./sherpa-onnx-zipformer-gigaspeech-2023-12-12/tokens.txt ]; then | ||
| 8 | + curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-zipformer-gigaspeech-2023-12-12.tar.bz2 | ||
| 9 | + | ||
| 10 | + tar xvf sherpa-onnx-zipformer-gigaspeech-2023-12-12.tar.bz2 | ||
| 11 | + rm sherpa-onnx-zipformer-gigaspeech-2023-12-12.tar.bz2 | ||
| 12 | +fi | ||
| 13 | + | ||
| 14 | +dart run \ | ||
| 15 | + ./bin/zipformer-transducer.dart \ | ||
| 16 | + --encoder ./sherpa-onnx-zipformer-gigaspeech-2023-12-12/encoder-epoch-30-avg-1.int8.onnx \ | ||
| 17 | + --decoder ./sherpa-onnx-zipformer-gigaspeech-2023-12-12/decoder-epoch-30-avg-1.onnx \ | ||
| 18 | + --joiner ./sherpa-onnx-zipformer-gigaspeech-2023-12-12/joiner-epoch-30-avg-1.int8.onnx \ | ||
| 19 | + --tokens ./sherpa-onnx-zipformer-gigaspeech-2023-12-12/tokens.txt \ | ||
| 20 | + --input-wav ./sherpa-onnx-zipformer-gigaspeech-2023-12-12/test_wavs/1221-135766-0001.wav |
dart-api-examples/vad/bin/init.dart
0 → 100644
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:isolate'; | ||
| 3 | +import 'package:path/path.dart' as p; | ||
| 4 | +import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | ||
| 5 | + | ||
| 6 | +Future<void> initSherpaOnnx() async { | ||
| 7 | + var uri = await Isolate.resolvePackageUri( | ||
| 8 | + Uri.parse('package:sherpa_onnx/sherpa_onnx.dart')); | ||
| 9 | + | ||
| 10 | + if (uri == null) { | ||
| 11 | + print('File not found'); | ||
| 12 | + exit(1); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + String platform = ''; | ||
| 16 | + | ||
| 17 | + if (Platform.isMacOS) { | ||
| 18 | + platform = 'macos'; | ||
| 19 | + } else if (Platform.isLinux) { | ||
| 20 | + platform = 'linux'; | ||
| 21 | + } else if (Platform.isWindows) { | ||
| 22 | + platform = 'windows'; | ||
| 23 | + } else { | ||
| 24 | + throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + final libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform); | ||
| 28 | + sherpa_onnx.initBindings(libPath); | ||
| 29 | +} |
| 1 | import 'dart:io'; | 1 | import 'dart:io'; |
| 2 | -import 'dart:isolate'; | ||
| 3 | import 'dart:typed_data'; | 2 | import 'dart:typed_data'; |
| 4 | 3 | ||
| 5 | import 'package:args/args.dart'; | 4 | import 'package:args/args.dart'; |
| 6 | -import 'package:path/path.dart' as p; | ||
| 7 | import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; | 5 | import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; |
| 8 | - | ||
| 9 | -Future<void> initSherpaOnnx() async { | ||
| 10 | - var uri = await Isolate.resolvePackageUri( | ||
| 11 | - Uri.parse('package:sherpa_onnx/sherpa_onnx.dart')); | ||
| 12 | - | ||
| 13 | - if (uri == null) { | ||
| 14 | - print('File not found'); | ||
| 15 | - exit(1); | ||
| 16 | - } | ||
| 17 | - String platform = ''; | ||
| 18 | - if (Platform.isMacOS) { | ||
| 19 | - platform = 'macos'; | ||
| 20 | - } else if (Platform.isLinux) { | ||
| 21 | - platform = 'linux'; | ||
| 22 | - } else if (Platform.isWindows) { | ||
| 23 | - platform = 'windows'; | ||
| 24 | - } else { | ||
| 25 | - throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | - final libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform); | ||
| 29 | - sherpa_onnx.initBindings(libPath); | ||
| 30 | -} | 6 | +import './init.dart'; |
| 31 | 7 | ||
| 32 | void main(List<String> arguments) async { | 8 | void main(List<String> arguments) async { |
| 33 | await initSherpaOnnx(); | 9 | await initSherpaOnnx(); |
| @@ -36,6 +12,7 @@ void main(List<String> arguments) async { | @@ -36,6 +12,7 @@ void main(List<String> arguments) async { | ||
| 36 | ..addOption('silero-vad', help: 'Path to silero_vad.onnx') | 12 | ..addOption('silero-vad', help: 'Path to silero_vad.onnx') |
| 37 | ..addOption('input-wav', help: 'Path to input.wav') | 13 | ..addOption('input-wav', help: 'Path to input.wav') |
| 38 | ..addOption('output-wav', help: 'Path to output.wav'); | 14 | ..addOption('output-wav', help: 'Path to output.wav'); |
| 15 | + | ||
| 39 | final res = parser.parse(arguments); | 16 | final res = parser.parse(arguments); |
| 40 | if (res['silero-vad'] == null || | 17 | if (res['silero-vad'] == null || |
| 41 | res['input-wav'] == null || | 18 | res['input-wav'] == null || |
| @@ -53,6 +30,7 @@ void main(List<String> arguments) async { | @@ -53,6 +30,7 @@ void main(List<String> arguments) async { | ||
| 53 | minSilenceDuration: 0.25, | 30 | minSilenceDuration: 0.25, |
| 54 | minSpeechDuration: 0.5, | 31 | minSpeechDuration: 0.5, |
| 55 | ); | 32 | ); |
| 33 | + | ||
| 56 | final config = sherpa_onnx.VadModelConfig( | 34 | final config = sherpa_onnx.VadModelConfig( |
| 57 | sileroVad: sileroVadConfig, | 35 | sileroVad: sileroVadConfig, |
| 58 | numThreads: 1, | 36 | numThreads: 1, |
| @@ -86,8 +64,11 @@ void main(List<String> arguments) async { | @@ -86,8 +64,11 @@ void main(List<String> arguments) async { | ||
| 86 | } | 64 | } |
| 87 | } | 65 | } |
| 88 | 66 | ||
| 67 | + vad.free(); | ||
| 68 | + | ||
| 89 | final s = Float32List.fromList(allSamples.expand((x) => x).toList()); | 69 | final s = Float32List.fromList(allSamples.expand((x) => x).toList()); |
| 90 | sherpa_onnx.writeWave( | 70 | sherpa_onnx.writeWave( |
| 91 | filename: outputWav, samples: s, sampleRate: waveData.sampleRate); | 71 | filename: outputWav, samples: s, sampleRate: waveData.sampleRate); |
| 72 | + | ||
| 92 | print('Saved to ${outputWav}'); | 73 | print('Saved to ${outputWav}'); |
| 93 | } | 74 | } |
| @@ -74,10 +74,10 @@ packages: | @@ -74,10 +74,10 @@ packages: | ||
| 74 | dependency: "direct main" | 74 | dependency: "direct main" |
| 75 | description: | 75 | description: |
| 76 | name: sherpa_onnx | 76 | name: sherpa_onnx |
| 77 | - sha256: "6cfadf7bc35001bb1284f9fac1e03e33787cafa918e0c45da96d1e91afa58751" | 77 | + sha256: e45894f81e7c854ca96d678bcab5303036e884a7c90e9a6c4ec04c7b1ee215a8 |
| 78 | url: "https://pub.dev" | 78 | url: "https://pub.dev" |
| 79 | source: hosted | 79 | source: hosted |
| 80 | - version: "0.0.3" | 80 | + version: "1.9.29" |
| 81 | sky_engine: | 81 | sky_engine: |
| 82 | dependency: transitive | 82 | dependency: transitive |
| 83 | description: flutter | 83 | description: flutter |
scripts/dart/non-streaming-asr-pubspec.yaml
0 → 100644
| 1 | +name: non_streaming_asr | ||
| 2 | +description: > | ||
| 3 | + This example demonstrates how to use the Dart API for Non-streaming speech recognition. Specifically, we use the following models as examples, whisper, zipformer, and paraformer. | ||
| 4 | + | ||
| 5 | +version: 1.0.0 | ||
| 6 | + | ||
| 7 | +environment: | ||
| 8 | + sdk: ^3.4.0 | ||
| 9 | + | ||
| 10 | +# Add regular dependencies here. | ||
| 11 | +dependencies: | ||
| 12 | + sherpa_onnx: | ||
| 13 | + path: ../../sherpa-onnx/flutter | ||
| 14 | + | ||
| 15 | + path: ^1.9.0 | ||
| 16 | + args: ^2.5.0 | ||
| 17 | + | ||
| 18 | +dev_dependencies: | ||
| 19 | + lints: ^3.0.0 |
scripts/dart/vad-pubspec.yaml
0 → 100644
| 1 | +name: vad | ||
| 2 | + | ||
| 3 | +description: > | ||
| 4 | + This example demonstrates how to use the Dart API for VAD (voice activity detection). | ||
| 5 | + | ||
| 6 | +version: 1.0.0 | ||
| 7 | + | ||
| 8 | +environment: | ||
| 9 | + sdk: ^3.4.0 | ||
| 10 | + | ||
| 11 | +dependencies: | ||
| 12 | + sherpa_onnx: | ||
| 13 | + path: ../../sherpa-onnx/flutter | ||
| 14 | + path: ^1.9.0 | ||
| 15 | + args: ^2.5.0 | ||
| 16 | + | ||
| 17 | +dev_dependencies: | ||
| 18 | + lints: ^3.0.0 |
| @@ -102,11 +102,14 @@ class OfflineModelConfig { | @@ -102,11 +102,14 @@ class OfflineModelConfig { | ||
| 102 | this.debug = true, | 102 | this.debug = true, |
| 103 | this.provider = 'cpu', | 103 | this.provider = 'cpu', |
| 104 | this.modelType = '', | 104 | this.modelType = '', |
| 105 | + this.modelingUnit = '', | ||
| 106 | + this.bpeVocab = '', | ||
| 107 | + this.telespeechCtc = '', | ||
| 105 | }); | 108 | }); |
| 106 | 109 | ||
| 107 | @override | 110 | @override |
| 108 | String toString() { | 111 | String toString() { |
| 109 | - return 'OfflineModelConfig(transducer: $transducer, paraformer: $paraformer, nemoCtc: $nemoCtc, whisper: $whisper, tdnn: $tdnn, tokens: $tokens, numThreads: $numThreads, debug: $debug, provider: $provider, modelType: $modelType)'; | 112 | + return 'OfflineModelConfig(transducer: $transducer, paraformer: $paraformer, nemoCtc: $nemoCtc, whisper: $whisper, tdnn: $tdnn, tokens: $tokens, numThreads: $numThreads, debug: $debug, provider: $provider, modelType: $modelType, modelingUnit: $modelingUnit, bpeVocab: $bpeVocab, telespeechCtc: $telespeechCtc)'; |
| 110 | } | 113 | } |
| 111 | 114 | ||
| 112 | final OfflineTransducerModelConfig transducer; | 115 | final OfflineTransducerModelConfig transducer; |
| @@ -120,6 +123,9 @@ class OfflineModelConfig { | @@ -120,6 +123,9 @@ class OfflineModelConfig { | ||
| 120 | final bool debug; | 123 | final bool debug; |
| 121 | final String provider; | 124 | final String provider; |
| 122 | final String modelType; | 125 | final String modelType; |
| 126 | + final String modelingUnit; | ||
| 127 | + final String bpeVocab; | ||
| 128 | + final String telespeechCtc; | ||
| 123 | } | 129 | } |
| 124 | 130 | ||
| 125 | class OfflineRecognizerConfig { | 131 | class OfflineRecognizerConfig { |
| @@ -213,6 +219,9 @@ class OfflineRecognizer { | @@ -213,6 +219,9 @@ class OfflineRecognizer { | ||
| 213 | c.ref.model.debug = config.model.debug ? 1 : 0; | 219 | c.ref.model.debug = config.model.debug ? 1 : 0; |
| 214 | c.ref.model.provider = config.model.provider.toNativeUtf8(); | 220 | c.ref.model.provider = config.model.provider.toNativeUtf8(); |
| 215 | c.ref.model.modelType = config.model.modelType.toNativeUtf8(); | 221 | c.ref.model.modelType = config.model.modelType.toNativeUtf8(); |
| 222 | + c.ref.model.modelingUnit = config.model.modelingUnit.toNativeUtf8(); | ||
| 223 | + c.ref.model.bpeVocab = config.model.bpeVocab.toNativeUtf8(); | ||
| 224 | + c.ref.model.telespeechCtc = config.model.telespeechCtc.toNativeUtf8(); | ||
| 216 | 225 | ||
| 217 | c.ref.lm.model = config.lm.model.toNativeUtf8(); | 226 | c.ref.lm.model = config.lm.model.toNativeUtf8(); |
| 218 | c.ref.lm.scale = config.lm.scale; | 227 | c.ref.lm.scale = config.lm.scale; |
| @@ -228,6 +237,9 @@ class OfflineRecognizer { | @@ -228,6 +237,9 @@ class OfflineRecognizer { | ||
| 228 | calloc.free(c.ref.hotwordsFile); | 237 | calloc.free(c.ref.hotwordsFile); |
| 229 | calloc.free(c.ref.decodingMethod); | 238 | calloc.free(c.ref.decodingMethod); |
| 230 | calloc.free(c.ref.lm.model); | 239 | calloc.free(c.ref.lm.model); |
| 240 | + calloc.free(c.ref.model.telespeechCtc); | ||
| 241 | + calloc.free(c.ref.model.bpeVocab); | ||
| 242 | + calloc.free(c.ref.model.modelingUnit); | ||
| 231 | calloc.free(c.ref.model.modelType); | 243 | calloc.free(c.ref.model.modelType); |
| 232 | calloc.free(c.ref.model.provider); | 244 | calloc.free(c.ref.model.provider); |
| 233 | calloc.free(c.ref.model.tokens); | 245 | calloc.free(c.ref.model.tokens); |
| @@ -58,11 +58,13 @@ class OnlineModelConfig { | @@ -58,11 +58,13 @@ class OnlineModelConfig { | ||
| 58 | this.provider = 'cpu', | 58 | this.provider = 'cpu', |
| 59 | this.debug = true, | 59 | this.debug = true, |
| 60 | this.modelType = '', | 60 | this.modelType = '', |
| 61 | + this.modelingUnit = '', | ||
| 62 | + this.bpeVocab = '', | ||
| 61 | }); | 63 | }); |
| 62 | 64 | ||
| 63 | @override | 65 | @override |
| 64 | String toString() { | 66 | String toString() { |
| 65 | - return 'OnlineModelConfig(transducer: $transducer, paraformer: $paraformer, zipformer2Ctc: $zipformer2Ctc, tokens: $tokens, numThreads: $numThreads, provider: $provider, debug: $debug, modelType: $modelType)'; | 67 | + return 'OnlineModelConfig(transducer: $transducer, paraformer: $paraformer, zipformer2Ctc: $zipformer2Ctc, tokens: $tokens, numThreads: $numThreads, provider: $provider, debug: $debug, modelType: $modelType, modelingUnit: $modelingUnit, bpeVocab: $bpeVocab)'; |
| 66 | } | 68 | } |
| 67 | 69 | ||
| 68 | final OnlineTransducerModelConfig transducer; | 70 | final OnlineTransducerModelConfig transducer; |
| @@ -78,6 +80,10 @@ class OnlineModelConfig { | @@ -78,6 +80,10 @@ class OnlineModelConfig { | ||
| 78 | final bool debug; | 80 | final bool debug; |
| 79 | 81 | ||
| 80 | final String modelType; | 82 | final String modelType; |
| 83 | + | ||
| 84 | + final String modelingUnit; | ||
| 85 | + | ||
| 86 | + final String bpeVocab; | ||
| 81 | } | 87 | } |
| 82 | 88 | ||
| 83 | class OnlineCtcFstDecoderConfig { | 89 | class OnlineCtcFstDecoderConfig { |
| @@ -180,6 +186,8 @@ class OnlineRecognizer { | @@ -180,6 +186,8 @@ class OnlineRecognizer { | ||
| 180 | c.ref.model.provider = config.model.provider.toNativeUtf8(); | 186 | c.ref.model.provider = config.model.provider.toNativeUtf8(); |
| 181 | c.ref.model.debug = config.model.debug ? 1 : 0; | 187 | c.ref.model.debug = config.model.debug ? 1 : 0; |
| 182 | c.ref.model.modelType = config.model.modelType.toNativeUtf8(); | 188 | c.ref.model.modelType = config.model.modelType.toNativeUtf8(); |
| 189 | + c.ref.model.modelingUnit = config.model.modelingUnit.toNativeUtf8(); | ||
| 190 | + c.ref.model.bpeVocab = config.model.bpeVocab.toNativeUtf8(); | ||
| 183 | 191 | ||
| 184 | c.ref.decodingMethod = config.decodingMethod.toNativeUtf8(); | 192 | c.ref.decodingMethod = config.decodingMethod.toNativeUtf8(); |
| 185 | c.ref.maxActivePaths = config.maxActivePaths; | 193 | c.ref.maxActivePaths = config.maxActivePaths; |
| @@ -199,6 +207,8 @@ class OnlineRecognizer { | @@ -199,6 +207,8 @@ class OnlineRecognizer { | ||
| 199 | calloc.free(c.ref.ctcFstDecoderConfig.graph); | 207 | calloc.free(c.ref.ctcFstDecoderConfig.graph); |
| 200 | calloc.free(c.ref.hotwordsFile); | 208 | calloc.free(c.ref.hotwordsFile); |
| 201 | calloc.free(c.ref.decodingMethod); | 209 | calloc.free(c.ref.decodingMethod); |
| 210 | + calloc.free(c.ref.model.bpeVocab); | ||
| 211 | + calloc.free(c.ref.model.modelingUnit); | ||
| 202 | calloc.free(c.ref.model.modelType); | 212 | calloc.free(c.ref.model.modelType); |
| 203 | calloc.free(c.ref.model.provider); | 213 | calloc.free(c.ref.model.provider); |
| 204 | calloc.free(c.ref.model.tokens); | 214 | calloc.free(c.ref.model.tokens); |
| @@ -63,6 +63,9 @@ final class SherpaOnnxOfflineModelConfig extends Struct { | @@ -63,6 +63,9 @@ final class SherpaOnnxOfflineModelConfig extends Struct { | ||
| 63 | external Pointer<Utf8> provider; | 63 | external Pointer<Utf8> provider; |
| 64 | 64 | ||
| 65 | external Pointer<Utf8> modelType; | 65 | external Pointer<Utf8> modelType; |
| 66 | + external Pointer<Utf8> modelingUnit; | ||
| 67 | + external Pointer<Utf8> bpeVocab; | ||
| 68 | + external Pointer<Utf8> telespeechCtc; | ||
| 66 | } | 69 | } |
| 67 | 70 | ||
| 68 | final class SherpaOnnxOfflineRecognizerConfig extends Struct { | 71 | final class SherpaOnnxOfflineRecognizerConfig extends Struct { |
| @@ -111,6 +114,10 @@ final class SherpaOnnxOnlineModelConfig extends Struct { | @@ -111,6 +114,10 @@ final class SherpaOnnxOnlineModelConfig extends Struct { | ||
| 111 | external int debug; | 114 | external int debug; |
| 112 | 115 | ||
| 113 | external Pointer<Utf8> modelType; | 116 | external Pointer<Utf8> modelType; |
| 117 | + | ||
| 118 | + external Pointer<Utf8> modelingUnit; | ||
| 119 | + | ||
| 120 | + external Pointer<Utf8> bpeVocab; | ||
| 114 | } | 121 | } |
| 115 | 122 | ||
| 116 | final class SherpaOnnxOnlineCtcFstDecoderConfig extends Struct { | 123 | final class SherpaOnnxOnlineCtcFstDecoderConfig extends Struct { |
| @@ -17,7 +17,7 @@ topics: | @@ -17,7 +17,7 @@ topics: | ||
| 17 | - voice-activity-detection | 17 | - voice-activity-detection |
| 18 | 18 | ||
| 19 | # remember to change the version in macos/sherpa_onnx.podspec | 19 | # remember to change the version in macos/sherpa_onnx.podspec |
| 20 | -version: 0.0.2 | 20 | +version: 1.9.29 |
| 21 | 21 | ||
| 22 | homepage: https://github.com/k2-fsa/sherpa-onnx | 22 | homepage: https://github.com/k2-fsa/sherpa-onnx |
| 23 | 23 |
-
请 注册 或 登录 后发表评论