Fangjun Kuang
Committed by GitHub

Refactor flutter to support Android (#1072)

正在显示 100 个修改的文件 包含 4414 行增加28 行删除

要显示太多修改。

为保证性能只显示 100 of 100+ 个文件。

@@ -8,6 +8,7 @@ on: @@ -8,6 +8,7 @@ on:
8 - '.github/workflows/test-dart.yaml' 8 - '.github/workflows/test-dart.yaml'
9 - '.github/scripts/test-dart.sh' 9 - '.github/scripts/test-dart.sh'
10 - 'dart-api-examples/**' 10 - 'dart-api-examples/**'
  11 + - 'flutter/**'
11 pull_request: 12 pull_request:
12 branches: 13 branches:
13 - master 14 - master
@@ -15,6 +16,7 @@ on: @@ -15,6 +16,7 @@ on:
15 - '.github/workflows/test-dart.yaml' 16 - '.github/workflows/test-dart.yaml'
16 - '.github/scripts/test-dart.sh' 17 - '.github/scripts/test-dart.sh'
17 - 'dart-api-examples/**' 18 - 'dart-api-examples/**'
  19 + - 'flutter/**'
18 20
19 workflow_dispatch: 21 workflow_dispatch:
20 22
@@ -29,7 +31,7 @@ jobs: @@ -29,7 +31,7 @@ jobs:
29 strategy: 31 strategy:
30 fail-fast: false 32 fail-fast: false
31 matrix: 33 matrix:
32 - os: [ubuntu-latest] 34 + os: [ubuntu-latest, macos-latest] #, windows-latest]
33 35
34 steps: 36 steps:
35 - uses: actions/checkout@v4 37 - uses: actions/checkout@v4
@@ -75,16 +77,29 @@ jobs: @@ -75,16 +77,29 @@ jobs:
75 -DSHERPA_ONNX_ENABLE_BINARY=OFF \ 77 -DSHERPA_ONNX_ENABLE_BINARY=OFF \
76 -DCMAKE_INSTALL_PREFIX=./install \ 78 -DCMAKE_INSTALL_PREFIX=./install \
77 .. 79 ..
78 - make -j install 80 +
  81 + cmake --build . --target install --config Release
79 82
80 - name: Copy libs 83 - name: Copy libs
81 shell: bash 84 shell: bash
82 run: | 85 run: |
83 - cp -v build/install/lib/lib* ./sherpa-onnx/flutter/linux/ 86 + if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
  87 + os=linux
  88 + elif [[ ${{ matrix.os }} == macos-latest ]]; then
  89 + os=macos
  90 + elif [[ ${{ matrix.os }} == windows-latest ]]; then
  91 + os=windows
  92 + fi
  93 +
  94 + if [[ $os == windows ]]; then
  95 + cp -fv build/install/lib/*.dll ./flutter/sherpa_onnx_$os/$os
  96 + else
  97 + cp -fv build/install/lib/lib* ./flutter/sherpa_onnx_$os/$os
  98 + fi
84 99
85 echo "--------------------" 100 echo "--------------------"
86 101
87 - ls -lh ./sherpa-onnx/flutter/linux/ 102 + ls -lh ./flutter/sherpa_onnx_$os/$os
88 103
89 - name: Run tests 104 - name: Run tests
90 shell: bash 105 shell: bash
@@ -93,5 +108,6 @@ jobs: @@ -93,5 +108,6 @@ jobs:
93 cp scripts/dart/non-streaming-asr-pubspec.yaml dart-api-examples/non-streaming-asr/pubspec.yaml 108 cp scripts/dart/non-streaming-asr-pubspec.yaml dart-api-examples/non-streaming-asr/pubspec.yaml
94 cp scripts/dart/streaming-asr-pubspec.yaml dart-api-examples/streaming-asr/pubspec.yaml 109 cp scripts/dart/streaming-asr-pubspec.yaml dart-api-examples/streaming-asr/pubspec.yaml
95 cp scripts/dart/tts-pubspec.yaml dart-api-examples/tts/pubspec.yaml 110 cp scripts/dart/tts-pubspec.yaml dart-api-examples/tts/pubspec.yaml
  111 + cp scripts/dart/sherpa-onnx-pubspec.yaml flutter/sherpa_onnx/pubspec.yaml
96 112
97 .github/scripts/test-dart.sh 113 .github/scripts/test-dart.sh
@@ -67,6 +67,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then @@ -67,6 +67,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
67 SHERPA_ONNX_ENABLE_BINARY=OFF 67 SHERPA_ONNX_ENABLE_BINARY=OFF
68 fi 68 fi
69 69
  70 +if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
  71 + SHERPA_ONNX_ENABLE_C_API=OFF
  72 +fi
  73 +
  74 +if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
  75 + SHERPA_ONNX_ENABLE_JNI=ON
  76 +fi
  77 +
70 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 78 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
71 -DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \ 79 -DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
72 -DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \ 80 -DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
@@ -80,8 +88,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" @@ -80,8 +88,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
80 -DSHERPA_ONNX_ENABLE_TESTS=OFF \ 88 -DSHERPA_ONNX_ENABLE_TESTS=OFF \
81 -DSHERPA_ONNX_ENABLE_CHECK=OFF \ 89 -DSHERPA_ONNX_ENABLE_CHECK=OFF \
82 -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ 90 -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
83 - -DSHERPA_ONNX_ENABLE_JNI=ON \  
84 - -DSHERPA_ONNX_ENABLE_C_API=OFF \ 91 + -DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
  92 + -DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
85 -DCMAKE_INSTALL_PREFIX=./install \ 93 -DCMAKE_INSTALL_PREFIX=./install \
86 -DANDROID_ABI="arm64-v8a" \ 94 -DANDROID_ABI="arm64-v8a" \
87 -DANDROID_PLATFORM=android-21 .. 95 -DANDROID_PLATFORM=android-21 ..
@@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then @@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
68 SHERPA_ONNX_ENABLE_BINARY=OFF 68 SHERPA_ONNX_ENABLE_BINARY=OFF
69 fi 69 fi
70 70
  71 +if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
  72 + SHERPA_ONNX_ENABLE_C_API=OFF
  73 +fi
  74 +
  75 +if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
  76 + SHERPA_ONNX_ENABLE_JNI=ON
  77 +fi
  78 +
71 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 79 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
72 -DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \ 80 -DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
73 -DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \ 81 -DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
@@ -81,8 +89,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" @@ -81,8 +89,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
81 -DSHERPA_ONNX_ENABLE_TESTS=OFF \ 89 -DSHERPA_ONNX_ENABLE_TESTS=OFF \
82 -DSHERPA_ONNX_ENABLE_CHECK=OFF \ 90 -DSHERPA_ONNX_ENABLE_CHECK=OFF \
83 -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ 91 -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
84 - -DSHERPA_ONNX_ENABLE_JNI=ON \  
85 - -DSHERPA_ONNX_ENABLE_C_API=OFF \ 92 + -DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
  93 + -DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
86 -DCMAKE_INSTALL_PREFIX=./install \ 94 -DCMAKE_INSTALL_PREFIX=./install \
87 -DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON \ 95 -DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON \
88 -DANDROID_PLATFORM=android-21 .. 96 -DANDROID_PLATFORM=android-21 ..
@@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then @@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
68 SHERPA_ONNX_ENABLE_BINARY=OFF 68 SHERPA_ONNX_ENABLE_BINARY=OFF
69 fi 69 fi
70 70
  71 +if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
  72 + SHERPA_ONNX_ENABLE_C_API=OFF
  73 +fi
  74 +
  75 +if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
  76 + SHERPA_ONNX_ENABLE_JNI=ON
  77 +fi
  78 +
71 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 79 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
72 -DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \ 80 -DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
73 -DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \ 81 -DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
@@ -81,10 +89,10 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" @@ -81,10 +89,10 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
81 -DSHERPA_ONNX_ENABLE_TESTS=OFF \ 89 -DSHERPA_ONNX_ENABLE_TESTS=OFF \
82 -DSHERPA_ONNX_ENABLE_CHECK=OFF \ 90 -DSHERPA_ONNX_ENABLE_CHECK=OFF \
83 -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ 91 -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
84 - -DSHERPA_ONNX_ENABLE_JNI=ON \ 92 + -DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
85 -DCMAKE_INSTALL_PREFIX=./install \ 93 -DCMAKE_INSTALL_PREFIX=./install \
86 -DANDROID_ABI="x86_64" \ 94 -DANDROID_ABI="x86_64" \
87 - -DSHERPA_ONNX_ENABLE_C_API=OFF \ 95 + -DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
88 -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ 96 -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
89 -DANDROID_PLATFORM=android-21 .. 97 -DANDROID_PLATFORM=android-21 ..
90 98
@@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then @@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
68 SHERPA_ONNX_ENABLE_BINARY=OFF 68 SHERPA_ONNX_ENABLE_BINARY=OFF
69 fi 69 fi
70 70
  71 +if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
  72 + SHERPA_ONNX_ENABLE_C_API=OFF
  73 +fi
  74 +
  75 +if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
  76 + SHERPA_ONNX_ENABLE_JNI=ON
  77 +fi
  78 +
71 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \ 79 cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
72 -DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \ 80 -DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
73 -DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \ 81 -DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
@@ -81,10 +89,10 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" @@ -81,10 +89,10 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
81 -DSHERPA_ONNX_ENABLE_TESTS=OFF \ 89 -DSHERPA_ONNX_ENABLE_TESTS=OFF \
82 -DSHERPA_ONNX_ENABLE_CHECK=OFF \ 90 -DSHERPA_ONNX_ENABLE_CHECK=OFF \
83 -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ 91 -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
84 - -DSHERPA_ONNX_ENABLE_JNI=ON \ 92 + -DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
85 -DCMAKE_INSTALL_PREFIX=./install \ 93 -DCMAKE_INSTALL_PREFIX=./install \
86 -DANDROID_ABI="x86" \ 94 -DANDROID_ABI="x86" \
87 - -DSHERPA_ONNX_ENABLE_C_API=OFF \ 95 + -DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
88 -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ 96 -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
89 -DANDROID_PLATFORM=android-21 .. 97 -DANDROID_PLATFORM=android-21 ..
90 98
@@ -5,14 +5,6 @@ import 'package:path/path.dart' as p; @@ -5,14 +5,6 @@ import 'package:path/path.dart' as p;
5 import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx; 5 import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx;
6 6
7 Future<void> initSherpaOnnx() async { 7 Future<void> initSherpaOnnx() async {
8 - var uri = await Isolate.resolvePackageUri(  
9 - Uri.parse('package:sherpa_onnx/sherpa_onnx.dart'));  
10 -  
11 - if (uri == null) {  
12 - print('File not found');  
13 - exit(1);  
14 - }  
15 -  
16 String platform = ''; 8 String platform = '';
17 9
18 if (Platform.isMacOS) { 10 if (Platform.isMacOS) {
@@ -25,6 +17,14 @@ Future<void> initSherpaOnnx() async { @@ -25,6 +17,14 @@ Future<void> initSherpaOnnx() async {
25 throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); 17 throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
26 } 18 }
27 19
  20 + var uri = await Isolate.resolvePackageUri(
  21 + Uri.parse('package:sherpa_onnx_$platform/any_path_is_ok_here.dart'));
  22 +
  23 + if (uri == null) {
  24 + print('File not found');
  25 + exit(1);
  26 + }
  27 +
28 final libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform); 28 final libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform);
29 sherpa_onnx.initBindings(libPath); 29 sherpa_onnx.initBindings(libPath);
30 } 30 }
  1 +# Do not remove or rename entries in this file, only add new ones
  2 +# See https://github.com/flutter/flutter/issues/128635 for more context.
  3 +
  4 +# Miscellaneous
  5 +*.class
  6 +*.lock
  7 +*.log
  8 +*.pyc
  9 +*.swp
  10 +.DS_Store
  11 +.atom/
  12 +.buildlog/
  13 +.history
  14 +.svn/
  15 +
  16 +# IntelliJ related
  17 +*.iml
  18 +*.ipr
  19 +*.iws
  20 +.idea/
  21 +
  22 +# Visual Studio Code related
  23 +.classpath
  24 +.project
  25 +.settings/
  26 +.vscode/*
  27 +
  28 +# Flutter repo-specific
  29 +/bin/cache/
  30 +/bin/internal/bootstrap.bat
  31 +/bin/internal/bootstrap.sh
  32 +/bin/mingit/
  33 +/dev/benchmarks/mega_gallery/
  34 +/dev/bots/.recipe_deps
  35 +/dev/bots/android_tools/
  36 +/dev/devicelab/ABresults*.json
  37 +/dev/docs/doc/
  38 +/dev/docs/api_docs.zip
  39 +/dev/docs/flutter.docs.zip
  40 +/dev/docs/lib/
  41 +/dev/docs/pubspec.yaml
  42 +/dev/integration_tests/**/xcuserdata
  43 +/dev/integration_tests/**/Pods
  44 +/packages/flutter/coverage/
  45 +version
  46 +analysis_benchmark.json
  47 +
  48 +# packages file containing multi-root paths
  49 +.packages.generated
  50 +
  51 +# Flutter/Dart/Pub related
  52 +**/doc/api/
  53 +.dart_tool/
  54 +.flutter-plugins
  55 +.flutter-plugins-dependencies
  56 +**/generated_plugin_registrant.dart
  57 +.packages
  58 +.pub-preload-cache/
  59 +.pub-cache/
  60 +.pub/
  61 +build/
  62 +flutter_*.png
  63 +linked_*.ds
  64 +unlinked.ds
  65 +unlinked_spec.ds
  66 +
  67 +# Android related
  68 +**/android/**/gradle-wrapper.jar
  69 +.gradle/
  70 +**/android/captures/
  71 +**/android/gradlew
  72 +**/android/gradlew.bat
  73 +**/android/local.properties
  74 +**/android/**/GeneratedPluginRegistrant.java
  75 +**/android/key.properties
  76 +*.jks
  77 +
  78 +# iOS/XCode related
  79 +**/ios/**/*.mode1v3
  80 +**/ios/**/*.mode2v3
  81 +**/ios/**/*.moved-aside
  82 +**/ios/**/*.pbxuser
  83 +**/ios/**/*.perspectivev3
  84 +**/ios/**/*sync/
  85 +**/ios/**/.sconsign.dblite
  86 +**/ios/**/.tags*
  87 +**/ios/**/.vagrant/
  88 +**/ios/**/DerivedData/
  89 +**/ios/**/Icon?
  90 +**/ios/**/Pods/
  91 +**/ios/**/.symlinks/
  92 +**/ios/**/profile
  93 +**/ios/**/xcuserdata
  94 +**/ios/.generated/
  95 +**/ios/Flutter/.last_build_id
  96 +**/ios/Flutter/App.framework
  97 +**/ios/Flutter/Flutter.framework
  98 +**/ios/Flutter/Flutter.podspec
  99 +**/ios/Flutter/Generated.xcconfig
  100 +**/ios/Flutter/ephemeral
  101 +**/ios/Flutter/app.flx
  102 +**/ios/Flutter/app.zip
  103 +**/ios/Flutter/flutter_assets/
  104 +**/ios/Flutter/flutter_export_environment.sh
  105 +**/ios/ServiceDefinitions.json
  106 +**/ios/Runner/GeneratedPluginRegistrant.*
  107 +
  108 +# macOS
  109 +**/Flutter/ephemeral/
  110 +**/Pods/
  111 +**/macos/Flutter/GeneratedPluginRegistrant.swift
  112 +**/macos/Flutter/ephemeral
  113 +**/xcuserdata/
  114 +
  115 +# Windows
  116 +**/windows/flutter/generated_plugin_registrant.cc
  117 +**/windows/flutter/generated_plugin_registrant.h
  118 +**/windows/flutter/generated_plugins.cmake
  119 +
  120 +# Linux
  121 +**/linux/flutter/generated_plugin_registrant.cc
  122 +**/linux/flutter/generated_plugin_registrant.h
  123 +**/linux/flutter/generated_plugins.cmake
  124 +
  125 +# Coverage
  126 +coverage/
  127 +
  128 +# Symbols
  129 +app.*.symbols
  130 +
  131 +# Exceptions to above rules.
  132 +!**/ios/**/default.mode1v3
  133 +!**/ios/**/default.mode2v3
  134 +!**/ios/**/default.pbxuser
  135 +!**/ios/**/default.perspectivev3
  136 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
  137 +!/dev/ci/**/Gemfile.lock
  138 +!.vscode/settings.json
@@ -7,4 +7,119 @@ This directory contains flutter examples of `sherpa-onnx`. @@ -7,4 +7,119 @@ This directory contains flutter examples of `sherpa-onnx`.
7 flutter create --platforms windows,macos streaming_asr 7 flutter create --platforms windows,macos streaming_asr
8 cd streaming_asr 8 cd streaming_asr
9 flutter pub get 9 flutter pub get
  10 +
  11 +# to support a new platform, e.g., android, use
  12 +
  13 +cd streaming_asr
  14 +flutter create --platforms --org com.k2fsa.sherpa.onnx android ./
  15 +```
  16 +
  17 +To run with android, first use
  18 +```
  19 +(py38) fangjuns-MacBook-Pro:streaming_asr fangjun$ flutter run devices
  20 +No devices found yet. Checking for wireless devices...
  21 +
  22 +No supported devices found with name or id matching 'android-arm64'.
  23 +
  24 +The following devices were found:
  25 +Mi 10 (mobile) • 61106679 • android-arm64 • Android 12 (API 31)
  26 +macOS (desktop) • macos • darwin-x64 • macOS 13.1 22C65 darwin-x64
  27 +Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.127
  28 +```
  29 +to find available devices. I have attached my Android phone (Xiaomi 10) to my computer
  30 +and it shows the device ID of my Android phone is `61106679`, so I use
  31 +
  32 +```bash
  33 +(py38) fangjuns-MacBook-Pro:streaming_asr fangjun$ flutter run -d 61106679
  34 +```
  35 +
  36 +to run it.
  37 +
  38 +If you get the following errors and hint:
  39 +
  40 +```
  41 +BUILD FAILED in 2m 43s
  42 +Running Gradle task 'assembleDebug'... 165.3s
  43 +
  44 +┌─ Flutter Fix ───────────────────────────────────────────────────────────────────────────────────────────────────┐
  45 +│ The plugin record_android requires a higher Android SDK version. │
  46 +│ Fix this issue by adding the following to the file │
  47 +│ /Users/fangjun/open-source/sherpa-onnx/flutter-examples/streaming_asr/android/app/build.gradle: │
  48 +│ android { │
  49 +│ defaultConfig { │
  50 +│ minSdkVersion 23 │
  51 +│ } │
  52 +│ } │
  53 +│ │
  54 +│ │
  55 +│ Following this change, your app will not be available to users running Android SDKs below 23. │
  56 +│ Consider searching for a version of this plugin that supports these lower versions of the Android SDK instead. │
  57 +│ For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration │
  58 +└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  59 +Error: Gradle task assembleDebug failed with exit code 1
  60 +```
  61 +
  62 +Please use the following changes:
  63 +
  64 +```diff
  65 +--- a/flutter-examples/streaming_asr/android/app/build.gradle
  66 ++++ b/flutter-examples/streaming_asr/android/app/build.gradle
  67 +@@ -38,7 +38,7 @@ android {
  68 + applicationId = "com.k2fsa.sherpa.onnx.streaming_asr"
  69 + // You can update the following values to match your application needs.
  70 + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
  71 +- minSdk = flutter.minSdkVersion
  72 ++ minSdk = 23
  73 + targetSdk = flutter.targetSdkVersion
  74 + versionCode = flutterVersionCode.toInteger()
  75 + versionName = flutterVersionName
  76 +```
  77 +
  78 +If you get the following errors:
  79 +
  80 +```
  81 +Launching lib/main.dart on Mi 10 in debug mode...
  82 +ERROR:/Users/fangjun/open-source/sherpa-onnx/flutter-examples/streaming_asr/build/record_android/intermediates/runtime_library_classes_jar/debug/clas
  83 +ses.jar: D8: com.android.tools.r8.internal.Hc: Sealed classes are not supported as program classes
  84 +
  85 +FAILURE: Build failed with an exception.
  86 +
  87 +* What went wrong:
  88 +Execution failed for task ':app:mergeLibDexDebug'.
  89 +> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
  90 + > Failed to transform classes.jar (project :record_android) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, com.andro
  91 +id.build.api.attributes.AgpVersionAttr=7.3.0, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.gradle.internal.attributes.Vari
  92 +antAttr=debug, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=23, org.gradle.ca
  93 +tegory=library, org.gradle.jvm.environment=android, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type
  94 +=androidJvm}.
  95 + > Execution failed for DexingWithClasspathTransform: /Users/fangjun/open-source/sherpa-onnx/flutter-examples/streaming_asr/build/record_android
  96 +/intermediates/runtime_library_classes_jar/debug/classes.jar.
  97 + > Error while dexing.
  98 +
  99 +* Try:
  100 +> Run with --stacktrace option to get the stack trace.
  101 +> Run with --info or --debug option to get more log output.
  102 +> Run with --scan to get full insights.
  103 +
  104 +* Get more help at https://help.gradle.org
  105 +
  106 +BUILD FAILED in 2m 10s
  107 +```
  108 +
  109 +Please refer to <https://github.com/llfbandit/record/blob/master/record_android/README.md>
  110 +to make the following changes
  111 +
  112 +```diff
  113 +diff --git a/flutter-examples/streaming_asr/android/settings.gradle b/flutter-examples/streaming_asr/android/settings.gradle
  114 +index 536165d3..9b1a1012 100644
  115 +--- a/flutter-examples/streaming_asr/android/settings.gradle
  116 ++++ b/flutter-examples/streaming_asr/android/settings.gradle
  117 +@@ -18,7 +18,7 @@ pluginManagement {
  118 +
  119 + plugins {
  120 + id "dev.flutter.flutter-plugin-loader" version "1.0.0"
  121 +- id "com.android.application" version "7.3.0" apply false
  122 ++ id "com.android.application" version "7.4.2" apply false
  123 + id "org.jetbrains.kotlin.android" version "1.7.10" apply false
  124 + }
10 ``` 125 ```
@@ -15,10 +15,7 @@ migration: @@ -15,10 +15,7 @@ migration:
15 - platform: root 15 - platform: root
16 create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1 16 create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
17 base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1 17 base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
18 - - platform: macos  
19 - create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1  
20 - base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1  
21 - - platform: windows 18 + - platform: android
22 create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1 19 create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
23 base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1 20 base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
24 21
  1 +gradle-wrapper.jar
  2 +/.gradle
  3 +/captures/
  4 +/gradlew
  5 +/gradlew.bat
  6 +/local.properties
  7 +GeneratedPluginRegistrant.java
  8 +
  9 +# Remember to never publicly share your keystore.
  10 +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
  11 +key.properties
  12 +**/*.keystore
  13 +**/*.jks
  1 +plugins {
  2 + id "com.android.application"
  3 + id "kotlin-android"
  4 + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
  5 + id "dev.flutter.flutter-gradle-plugin"
  6 +}
  7 +
  8 +def localProperties = new Properties()
  9 +def localPropertiesFile = rootProject.file("local.properties")
  10 +if (localPropertiesFile.exists()) {
  11 + localPropertiesFile.withReader("UTF-8") { reader ->
  12 + localProperties.load(reader)
  13 + }
  14 +}
  15 +
  16 +def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
  17 +if (flutterVersionCode == null) {
  18 + flutterVersionCode = "1"
  19 +}
  20 +
  21 +def flutterVersionName = localProperties.getProperty("flutter.versionName")
  22 +if (flutterVersionName == null) {
  23 + flutterVersionName = "1.0"
  24 +}
  25 +
  26 +android {
  27 + namespace = "com.k2fsa.sherpa.onnx.streaming_asr"
  28 + compileSdk = flutter.compileSdkVersion
  29 + ndkVersion = flutter.ndkVersion
  30 +
  31 + compileOptions {
  32 + sourceCompatibility = JavaVersion.VERSION_1_8
  33 + targetCompatibility = JavaVersion.VERSION_1_8
  34 + }
  35 +
  36 + defaultConfig {
  37 + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
  38 + applicationId = "com.k2fsa.sherpa.onnx.streaming_asr"
  39 + // You can update the following values to match your application needs.
  40 + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
  41 + minSdk = 23
  42 + targetSdk = flutter.targetSdkVersion
  43 + versionCode = flutterVersionCode.toInteger()
  44 + versionName = flutterVersionName
  45 + }
  46 +
  47 + buildTypes {
  48 + release {
  49 + // TODO: Add your own signing config for the release build.
  50 + // Signing with the debug keys for now, so `flutter run --release` works.
  51 + signingConfig = signingConfigs.debug
  52 + }
  53 + }
  54 +}
  55 +
  56 +flutter {
  57 + source = "../.."
  58 +}
  1 +<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  2 + <!-- The INTERNET permission is required for development. Specifically,
  3 + the Flutter tool needs it to communicate with the running application
  4 + to allow setting breakpoints, to provide hot reload, etc.
  5 + -->
  6 + <uses-permission android:name="android.permission.INTERNET"/>
  7 +</manifest>
  1 +<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  2 + <application
  3 + android:label="streaming_asr"
  4 + android:name="${applicationName}"
  5 + android:icon="@mipmap/ic_launcher">
  6 + <activity
  7 + android:name=".MainActivity"
  8 + android:exported="true"
  9 + android:launchMode="singleTop"
  10 + android:taskAffinity=""
  11 + android:theme="@style/LaunchTheme"
  12 + android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
  13 + android:hardwareAccelerated="true"
  14 + android:windowSoftInputMode="adjustResize">
  15 + <!-- Specifies an Android theme to apply to this Activity as soon as
  16 + the Android process has started. This theme is visible to the user
  17 + while the Flutter UI initializes. After that, this theme continues
  18 + to determine the Window background behind the Flutter UI. -->
  19 + <meta-data
  20 + android:name="io.flutter.embedding.android.NormalTheme"
  21 + android:resource="@style/NormalTheme"
  22 + />
  23 + <intent-filter>
  24 + <action android:name="android.intent.action.MAIN"/>
  25 + <category android:name="android.intent.category.LAUNCHER"/>
  26 + </intent-filter>
  27 + </activity>
  28 + <!-- Don't delete the meta-data below.
  29 + This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
  30 + <meta-data
  31 + android:name="flutterEmbedding"
  32 + android:value="2" />
  33 + </application>
  34 + <!-- Required to query activities that can process text, see:
  35 + https://developer.android.com/training/package-visibility and
  36 + https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
  37 +
  38 + In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
  39 + <queries>
  40 + <intent>
  41 + <action android:name="android.intent.action.PROCESS_TEXT"/>
  42 + <data android:mimeType="text/plain"/>
  43 + </intent>
  44 + </queries>
  45 +</manifest>
  1 +package com.k2fsa.sherpa.onnx.streaming_asr
  2 +
  3 +import io.flutter.embedding.android.FlutterActivity
  4 +
  5 +class MainActivity: FlutterActivity()
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<!-- Modify this file to customize your launch splash screen -->
  3 +<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  4 + <item android:drawable="?android:colorBackground" />
  5 +
  6 + <!-- You can insert your own image assets here -->
  7 + <!-- <item>
  8 + <bitmap
  9 + android:gravity="center"
  10 + android:src="@mipmap/launch_image" />
  11 + </item> -->
  12 +</layer-list>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<!-- Modify this file to customize your launch splash screen -->
  3 +<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  4 + <item android:drawable="@android:color/white" />
  5 +
  6 + <!-- You can insert your own image assets here -->
  7 + <!-- <item>
  8 + <bitmap
  9 + android:gravity="center"
  10 + android:src="@mipmap/launch_image" />
  11 + </item> -->
  12 +</layer-list>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
  4 + <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
  5 + <!-- Show a splash screen on the activity. Automatically removed when
  6 + the Flutter engine draws its first frame -->
  7 + <item name="android:windowBackground">@drawable/launch_background</item>
  8 + </style>
  9 + <!-- Theme applied to the Android Window as soon as the process has started.
  10 + This theme determines the color of the Android Window while your
  11 + Flutter UI initializes, as well as behind your Flutter UI while its
  12 + running.
  13 +
  14 + This Theme is only used starting with V2 of Flutter's Android embedding. -->
  15 + <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
  16 + <item name="android:windowBackground">?android:colorBackground</item>
  17 + </style>
  18 +</resources>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
  4 + <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
  5 + <!-- Show a splash screen on the activity. Automatically removed when
  6 + the Flutter engine draws its first frame -->
  7 + <item name="android:windowBackground">@drawable/launch_background</item>
  8 + </style>
  9 + <!-- Theme applied to the Android Window as soon as the process has started.
  10 + This theme determines the color of the Android Window while your
  11 + Flutter UI initializes, as well as behind your Flutter UI while its
  12 + running.
  13 +
  14 + This Theme is only used starting with V2 of Flutter's Android embedding. -->
  15 + <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
  16 + <item name="android:windowBackground">?android:colorBackground</item>
  17 + </style>
  18 +</resources>
  1 +<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  2 + <!-- The INTERNET permission is required for development. Specifically,
  3 + the Flutter tool needs it to communicate with the running application
  4 + to allow setting breakpoints, to provide hot reload, etc.
  5 + -->
  6 + <uses-permission android:name="android.permission.INTERNET"/>
  7 +</manifest>
  1 +allprojects {
  2 + repositories {
  3 + google()
  4 + mavenCentral()
  5 + }
  6 +}
  7 +
  8 +rootProject.buildDir = "../build"
  9 +subprojects {
  10 + project.buildDir = "${rootProject.buildDir}/${project.name}"
  11 +}
  12 +subprojects {
  13 + project.evaluationDependsOn(":app")
  14 +}
  15 +
  16 +tasks.register("clean", Delete) {
  17 + delete rootProject.buildDir
  18 +}
  1 +org.gradle.jvmargs=-Xmx4G -XX:+HeapDumpOnOutOfMemoryError
  2 +android.useAndroidX=true
  3 +android.enableJetifier=true
  1 +distributionBase=GRADLE_USER_HOME
  2 +distributionPath=wrapper/dists
  3 +zipStoreBase=GRADLE_USER_HOME
  4 +zipStorePath=wrapper/dists
  5 +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
  1 +pluginManagement {
  2 + def flutterSdkPath = {
  3 + def properties = new Properties()
  4 + file("local.properties").withInputStream { properties.load(it) }
  5 + def flutterSdkPath = properties.getProperty("flutter.sdk")
  6 + assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
  7 + return flutterSdkPath
  8 + }()
  9 +
  10 + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
  11 +
  12 + repositories {
  13 + google()
  14 + mavenCentral()
  15 + gradlePluginPortal()
  16 + }
  17 +}
  18 +
  19 +plugins {
  20 + id "dev.flutter.flutter-plugin-loader" version "1.0.0"
  21 + id "com.android.application" version "7.4.2" apply false
  22 + id "org.jetbrains.kotlin.android" version "1.7.10" apply false
  23 +}
  24 +
  25 +include ":app"
@@ -291,10 +291,11 @@ packages: @@ -291,10 +291,11 @@ packages:
291 sherpa_onnx: 291 sherpa_onnx:
292 dependency: "direct main" 292 dependency: "direct main"
293 description: 293 description:
294 - path: "../../sherpa-onnx/flutter"  
295 - relative: true  
296 - source: path  
297 - version: "1.9.29" 294 + name: sherpa_onnx
  295 + sha256: b797a1297e1445d62ed73d23a044bd4407e9133f616b64339ba2d249f4b66743
  296 + url: "https://pub.dev"
  297 + source: hosted
  298 + version: "1.10.2"
298 sky_engine: 299 sky_engine:
299 dependency: transitive 300 dependency: transitive
300 description: flutter 301 description: flutter
@@ -31,6 +31,8 @@ dependencies: @@ -31,6 +31,8 @@ dependencies:
31 url_launcher: ^6.2.6 31 url_launcher: ^6.2.6
32 32
33 sherpa_onnx: ^1.10.0 33 sherpa_onnx: ^1.10.0
  34 + # sherpa_onnx:
  35 + # path: ../../flutter/sherpa_onnx
34 36
35 dev_dependencies: 37 dev_dependencies:
36 flutter_test: 38 flutter_test:
  1 +# Do not remove or rename entries in this file, only add new ones
  2 +# See https://github.com/flutter/flutter/issues/128635 for more context.
  3 +
  4 +# Miscellaneous
  5 +*.class
  6 +*.lock
  7 +*.log
  8 +*.pyc
  9 +*.swp
  10 +.DS_Store
  11 +.atom/
  12 +.buildlog/
  13 +.history
  14 +.svn/
  15 +
  16 +# IntelliJ related
  17 +*.iml
  18 +*.ipr
  19 +*.iws
  20 +.idea/
  21 +
  22 +# Visual Studio Code related
  23 +.classpath
  24 +.project
  25 +.settings/
  26 +.vscode/*
  27 +
  28 +# Flutter repo-specific
  29 +/bin/cache/
  30 +/bin/internal/bootstrap.bat
  31 +/bin/internal/bootstrap.sh
  32 +/bin/mingit/
  33 +/dev/benchmarks/mega_gallery/
  34 +/dev/bots/.recipe_deps
  35 +/dev/bots/android_tools/
  36 +/dev/devicelab/ABresults*.json
  37 +/dev/docs/doc/
  38 +/dev/docs/api_docs.zip
  39 +/dev/docs/flutter.docs.zip
  40 +/dev/docs/lib/
  41 +/dev/docs/pubspec.yaml
  42 +/dev/integration_tests/**/xcuserdata
  43 +/dev/integration_tests/**/Pods
  44 +/packages/flutter/coverage/
  45 +version
  46 +analysis_benchmark.json
  47 +
  48 +# packages file containing multi-root paths
  49 +.packages.generated
  50 +
  51 +# Flutter/Dart/Pub related
  52 +**/doc/api/
  53 +.dart_tool/
  54 +.flutter-plugins
  55 +.flutter-plugins-dependencies
  56 +**/generated_plugin_registrant.dart
  57 +.packages
  58 +.pub-preload-cache/
  59 +.pub-cache/
  60 +.pub/
  61 +build/
  62 +flutter_*.png
  63 +linked_*.ds
  64 +unlinked.ds
  65 +unlinked_spec.ds
  66 +
  67 +# Android related
  68 +**/android/**/gradle-wrapper.jar
  69 +.gradle/
  70 +**/android/captures/
  71 +**/android/gradlew
  72 +**/android/gradlew.bat
  73 +**/android/local.properties
  74 +**/android/**/GeneratedPluginRegistrant.java
  75 +**/android/key.properties
  76 +*.jks
  77 +
  78 +# iOS/XCode related
  79 +**/ios/**/*.mode1v3
  80 +**/ios/**/*.mode2v3
  81 +**/ios/**/*.moved-aside
  82 +**/ios/**/*.pbxuser
  83 +**/ios/**/*.perspectivev3
  84 +**/ios/**/*sync/
  85 +**/ios/**/.sconsign.dblite
  86 +**/ios/**/.tags*
  87 +**/ios/**/.vagrant/
  88 +**/ios/**/DerivedData/
  89 +**/ios/**/Icon?
  90 +**/ios/**/Pods/
  91 +**/ios/**/.symlinks/
  92 +**/ios/**/profile
  93 +**/ios/**/xcuserdata
  94 +**/ios/.generated/
  95 +**/ios/Flutter/.last_build_id
  96 +**/ios/Flutter/App.framework
  97 +**/ios/Flutter/Flutter.framework
  98 +**/ios/Flutter/Flutter.podspec
  99 +**/ios/Flutter/Generated.xcconfig
  100 +**/ios/Flutter/ephemeral
  101 +**/ios/Flutter/app.flx
  102 +**/ios/Flutter/app.zip
  103 +**/ios/Flutter/flutter_assets/
  104 +**/ios/Flutter/flutter_export_environment.sh
  105 +**/ios/ServiceDefinitions.json
  106 +**/ios/Runner/GeneratedPluginRegistrant.*
  107 +
  108 +# macOS
  109 +**/Flutter/ephemeral/
  110 +**/Pods/
  111 +**/macos/Flutter/GeneratedPluginRegistrant.swift
  112 +**/macos/Flutter/ephemeral
  113 +**/xcuserdata/
  114 +
  115 +# Windows
  116 +**/windows/flutter/generated_plugin_registrant.cc
  117 +**/windows/flutter/generated_plugin_registrant.h
  118 +**/windows/flutter/generated_plugins.cmake
  119 +
  120 +# Linux
  121 +**/linux/flutter/generated_plugin_registrant.cc
  122 +**/linux/flutter/generated_plugin_registrant.h
  123 +**/linux/flutter/generated_plugins.cmake
  124 +
  125 +# Coverage
  126 +coverage/
  127 +
  128 +# Symbols
  129 +app.*.symbols
  130 +
  131 +# Exceptions to above rules.
  132 +!**/ios/**/default.mode1v3
  133 +!**/ios/**/default.mode2v3
  134 +!**/ios/**/default.pbxuser
  135 +!**/ios/**/default.perspectivev3
  136 +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
  137 +!/dev/ci/**/Gemfile.lock
  138 +!.vscode/settings.json
  1 +# Introduction
  2 +
  3 +This directory contains the source code of the flutter
  4 +package [sherpa-onnx](https://github.com/k2-fsa/sherpa-onnx)
  5 +
  6 +Caution: You are not expected to use this directory directly.
  7 +
  8 +This directory is for developers only.
  9 +
  10 +For common users, please use our package at <https://pub.dev/packages/sherpa_onnx>
  1 +# Introduction
  2 +
  3 +This file keeps some notes about how packages in this directory
  4 +are created.
  5 +
  6 +1. Create `sherpa_onnx`.
  7 +
  8 +```bash
  9 +flutter create --template plugin sherpa_onnx
  10 +```
  11 +
  12 +2. Create `sherpa_onnx_macos`
  13 +
  14 +```bash
  15 +flutter create --template plugin_ffi --platforms macos sherpa_onnx_macos
  16 +```
  17 +
  18 +3. Create `sherpa_onnx_linux
  19 +
  20 +```bash
  21 +flutter create --template plugin_ffi --platforms linux sherpa_onnx_linux
  22 +```
  23 +
  24 +4. Create `sherpa_onnx_windows
  25 +
  26 +```bash
  27 +flutter create --template plugin_ffi --platforms linux sherpa_onnx_windows
  28 +```
  29 +
  30 +5. Create `sherpa_onnx_android
  31 +
  32 +```bash
  33 +flutter create --template plugin_ffi --platforms android --org com.k2fsa.sherpa.onnx sherpa_onnx_android
  34 +```
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
  26 +/pubspec.lock
  27 +**/doc/api/
  28 +.dart_tool/
  29 +build/
  1 +# This file tracks properties of this Flutter project.
  2 +# Used by Flutter tool to assess capabilities and perform upgrades etc.
  3 +#
  4 +# This file should be version controlled and should not be manually edited.
  5 +
  6 +version:
  7 + revision: "5dcb86f68f239346676ceb1ed1ea385bd215fba1"
  8 + channel: "stable"
  9 +
  10 +project_type: plugin
  11 +
  12 +# Tracks metadata for the flutter migrate command
  13 +migration:
  14 + platforms:
  15 + - platform: root
  16 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  17 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  18 +
  19 + # User provided section
  20 +
  21 + # List of Local paths (relative to this file) that should be
  22 + # ignored by the migrate tool.
  23 + #
  24 + # Files that are not part of the templates will be ignored by default.
  25 + unmanaged_files:
  26 + - 'lib/main.dart'
  27 + - 'ios/Runner.xcodeproj/project.pbxproj'
  1 +## 1.10.7
  2 +
  3 +* Support Android
  4 +
  5 +## 1.10.2
  6 +
  7 +* Fix passing C# string to C++
  8 +
  9 +## 1.10.1
  10 +
  11 +* Enable to stop TTS generation
  12 +
  13 +## 1.10.0
  14 +
  15 +* Add inverse text normalization
  16 +
  17 +## 1.9.30
  18 +
  19 +* Add TTS
  20 +
  21 +## 1.9.29
  22 +
  23 +* Publish with CI
  24 +
  25 +## 0.0.3
  26 +
  27 +* Fix path separator on Windows.
  28 +
  29 +## 0.0.2
  30 +
  31 +* Support specifying lib path.
  32 +
  33 +## 0.0.1
  34 +
  35 +* Initial release.
  1 +# sherpa_onnx
  2 +
  3 +Please see <https://github.com/k2-fsa/sherpa-onnx>
  1 +include: package:flutter_lints/flutter.yaml
  2 +
  3 +# Additional information about this file can be found at
  4 +# https://dart.dev/guides/language/analysis-options
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +**/doc/api/
  26 +**/ios/Flutter/.last_build_id
  27 +.dart_tool/
  28 +.flutter-plugins
  29 +.flutter-plugins-dependencies
  30 +.pub-cache/
  31 +.pub/
  32 +/build/
  33 +
  34 +# Symbolication related
  35 +app.*.symbols
  36 +
  37 +# Obfuscation related
  38 +app.*.map.json
  39 +
  40 +# Android Studio will place build artifacts here
  41 +/android/app/debug
  42 +/android/app/profile
  43 +/android/app/release
  1 +# Introduction
  2 +
  3 +Please find examples at
  4 +
  5 +https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples
  6 +
  7 +and
  8 +
  9 +https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples
  1 +# sherpa-onnx app example
  2 +
  3 +See also <https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples>
  4 +
  5 +## Streaming speech recognition
  6 +
  7 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/streaming-asr
  8 +
  9 +## Non-streaming speech recognition
  10 +
  11 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/non-streaming-asr
  12 +
  13 +## Text to speech (TTS)
  14 +
  15 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/tts
  16 +
  17 +## Voice activity detection (VAD)
  18 +
  19 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/vad
  20 +
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:io';
  3 +import 'dart:ffi';
  4 +
  5 +export 'src/feature_config.dart';
  6 +export 'src/offline_recognizer.dart';
  7 +export 'src/offline_stream.dart';
  8 +export 'src/online_recognizer.dart';
  9 +export 'src/online_stream.dart';
  10 +export 'src/speaker_identification.dart';
  11 +export 'src/tts.dart';
  12 +export 'src/vad.dart';
  13 +export 'src/wave_reader.dart';
  14 +export 'src/wave_writer.dart';
  15 +
  16 +import 'src/sherpa_onnx_bindings.dart';
  17 +
  18 +String? _path;
  19 +
  20 +// see also
  21 +// https://github.com/flutter/codelabs/blob/main/ffigen_codelab/step_05/lib/ffigen_app.dart
  22 +final DynamicLibrary _dylib = () {
  23 + if (Platform.isIOS) {
  24 + throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
  25 + }
  26 + if (Platform.isMacOS) {
  27 + if (_path == null) {
  28 + return DynamicLibrary.open('libsherpa-onnx-c-api.dylib');
  29 + } else {
  30 + return DynamicLibrary.open('$_path/libsherpa-onnx-c-api.dylib');
  31 + }
  32 + }
  33 +
  34 + if (Platform.isAndroid || Platform.isLinux) {
  35 + if (_path == null) {
  36 + return DynamicLibrary.open('libsherpa-onnx-c-api.so');
  37 + } else {
  38 + return DynamicLibrary.open('$_path/libsherpa-onnx-c-api.so');
  39 + }
  40 + }
  41 +
  42 + if (Platform.isWindows) {
  43 + if (_path == null) {
  44 + return DynamicLibrary.open('sherpa-onnx-c-api.dll');
  45 + } else {
  46 + return DynamicLibrary.open('$_path\\sherpa-onnx-c-api.dll');
  47 + }
  48 + }
  49 +
  50 + throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
  51 +}();
  52 +
  53 +void initBindings([String? p]) {
  54 + _path ??= p;
  55 + SherpaOnnxBindings.init(_dylib);
  56 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +
  3 +class FeatureConfig {
  4 + const FeatureConfig({this.sampleRate = 16000, this.featureDim = 80});
  5 +
  6 + @override
  7 + String toString() {
  8 + return 'FeatureConfig(sampleRate: $sampleRate, featureDim: $featureDim)';
  9 + }
  10 +
  11 + final int sampleRate;
  12 + final int featureDim;
  13 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:convert';
  3 +import 'dart:ffi';
  4 +
  5 +import 'package:ffi/ffi.dart';
  6 +
  7 +import './feature_config.dart';
  8 +import './offline_stream.dart';
  9 +import './sherpa_onnx_bindings.dart';
  10 +
  11 +class OfflineTransducerModelConfig {
  12 + const OfflineTransducerModelConfig({
  13 + this.encoder = '',
  14 + this.decoder = '',
  15 + this.joiner = '',
  16 + });
  17 +
  18 + @override
  19 + String toString() {
  20 + return 'OfflineTransducerModelConfig(encoder: $encoder, decoder: $decoder, joiner: $joiner)';
  21 + }
  22 +
  23 + final String encoder;
  24 + final String decoder;
  25 + final String joiner;
  26 +}
  27 +
  28 +class OfflineParaformerModelConfig {
  29 + const OfflineParaformerModelConfig({this.model = ''});
  30 +
  31 + @override
  32 + String toString() {
  33 + return 'OfflineParaformerModelConfig(model: $model)';
  34 + }
  35 +
  36 + final String model;
  37 +}
  38 +
  39 +class OfflineNemoEncDecCtcModelConfig {
  40 + const OfflineNemoEncDecCtcModelConfig({this.model = ''});
  41 +
  42 + @override
  43 + String toString() {
  44 + return 'OfflineNemoEncDecCtcModelConfig(model: $model)';
  45 + }
  46 +
  47 + final String model;
  48 +}
  49 +
  50 +class OfflineWhisperModelConfig {
  51 + const OfflineWhisperModelConfig(
  52 + {this.encoder = '',
  53 + this.decoder = '',
  54 + this.language = '',
  55 + this.task = '',
  56 + this.tailPaddings = -1});
  57 +
  58 + @override
  59 + String toString() {
  60 + return 'OfflineWhisperModelConfig(encoder: $encoder, decoder: $decoder, language: $language, task: $task, tailPaddings: $tailPaddings)';
  61 + }
  62 +
  63 + final String encoder;
  64 + final String decoder;
  65 + final String language;
  66 + final String task;
  67 + final int tailPaddings;
  68 +}
  69 +
  70 +class OfflineTdnnModelConfig {
  71 + const OfflineTdnnModelConfig({this.model = ''});
  72 +
  73 + @override
  74 + String toString() {
  75 + return 'OfflineTdnnModelConfig(model: $model)';
  76 + }
  77 +
  78 + final String model;
  79 +}
  80 +
  81 +class OfflineLMConfig {
  82 + const OfflineLMConfig({this.model = '', this.scale = 1.0});
  83 +
  84 + @override
  85 + String toString() {
  86 + return 'OfflineLMConfig(model: $model, scale: $scale)';
  87 + }
  88 +
  89 + final String model;
  90 + final double scale;
  91 +}
  92 +
  93 +class OfflineModelConfig {
  94 + const OfflineModelConfig({
  95 + this.transducer = const OfflineTransducerModelConfig(),
  96 + this.paraformer = const OfflineParaformerModelConfig(),
  97 + this.nemoCtc = const OfflineNemoEncDecCtcModelConfig(),
  98 + this.whisper = const OfflineWhisperModelConfig(),
  99 + this.tdnn = const OfflineTdnnModelConfig(),
  100 + required this.tokens,
  101 + this.numThreads = 1,
  102 + this.debug = true,
  103 + this.provider = 'cpu',
  104 + this.modelType = '',
  105 + this.modelingUnit = '',
  106 + this.bpeVocab = '',
  107 + this.telespeechCtc = '',
  108 + });
  109 +
  110 + @override
  111 + String toString() {
  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)';
  113 + }
  114 +
  115 + final OfflineTransducerModelConfig transducer;
  116 + final OfflineParaformerModelConfig paraformer;
  117 + final OfflineNemoEncDecCtcModelConfig nemoCtc;
  118 + final OfflineWhisperModelConfig whisper;
  119 + final OfflineTdnnModelConfig tdnn;
  120 +
  121 + final String tokens;
  122 + final int numThreads;
  123 + final bool debug;
  124 + final String provider;
  125 + final String modelType;
  126 + final String modelingUnit;
  127 + final String bpeVocab;
  128 + final String telespeechCtc;
  129 +}
  130 +
  131 +class OfflineRecognizerConfig {
  132 + const OfflineRecognizerConfig({
  133 + this.feat = const FeatureConfig(),
  134 + required this.model,
  135 + this.lm = const OfflineLMConfig(),
  136 + this.decodingMethod = 'greedy_search',
  137 + this.maxActivePaths = 4,
  138 + this.hotwordsFile = '',
  139 + this.hotwordsScore = 1.5,
  140 + this.ruleFsts = '',
  141 + this.ruleFars = '',
  142 + });
  143 +
  144 + @override
  145 + String toString() {
  146 + return 'OfflineRecognizerConfig(feat: $feat, model: $model, lm: $lm, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ruleFsts: $ruleFsts, ruleFars: $ruleFars)';
  147 + }
  148 +
  149 + final FeatureConfig feat;
  150 + final OfflineModelConfig model;
  151 + final OfflineLMConfig lm;
  152 + final String decodingMethod;
  153 +
  154 + final int maxActivePaths;
  155 +
  156 + final String hotwordsFile;
  157 +
  158 + final double hotwordsScore;
  159 +
  160 + final String ruleFsts;
  161 + final String ruleFars;
  162 +}
  163 +
  164 +class OfflineRecognizerResult {
  165 + OfflineRecognizerResult(
  166 + {required this.text, required this.tokens, required this.timestamps});
  167 +
  168 + @override
  169 + String toString() {
  170 + return 'OfflineRecognizerResult(text: $text, tokens: $tokens, timestamps: $timestamps)';
  171 + }
  172 +
  173 + final String text;
  174 + final List<String> tokens;
  175 + final List<double> timestamps;
  176 +}
  177 +
  178 +class OfflineRecognizer {
  179 + OfflineRecognizer._({required this.ptr, required this.config});
  180 +
  181 + void free() {
  182 + SherpaOnnxBindings.destroyOfflineRecognizer?.call(ptr);
  183 + ptr = nullptr;
  184 + }
  185 +
  186 + /// The user is responsible to call the OfflineRecognizer.free()
  187 + /// method of the returned instance to avoid memory leak.
  188 + factory OfflineRecognizer(OfflineRecognizerConfig config) {
  189 + final c = calloc<SherpaOnnxOfflineRecognizerConfig>();
  190 +
  191 + c.ref.feat.sampleRate = config.feat.sampleRate;
  192 + c.ref.feat.featureDim = config.feat.featureDim;
  193 +
  194 + // transducer
  195 + c.ref.model.transducer.encoder =
  196 + config.model.transducer.encoder.toNativeUtf8();
  197 + c.ref.model.transducer.decoder =
  198 + config.model.transducer.decoder.toNativeUtf8();
  199 + c.ref.model.transducer.joiner =
  200 + config.model.transducer.joiner.toNativeUtf8();
  201 +
  202 + // paraformer
  203 + c.ref.model.paraformer.model = config.model.paraformer.model.toNativeUtf8();
  204 +
  205 + // nemoCtc
  206 + c.ref.model.nemoCtc.model = config.model.nemoCtc.model.toNativeUtf8();
  207 +
  208 + // whisper
  209 + c.ref.model.whisper.encoder = config.model.whisper.encoder.toNativeUtf8();
  210 +
  211 + c.ref.model.whisper.decoder = config.model.whisper.decoder.toNativeUtf8();
  212 +
  213 + c.ref.model.whisper.language = config.model.whisper.language.toNativeUtf8();
  214 +
  215 + c.ref.model.whisper.task = config.model.whisper.task.toNativeUtf8();
  216 +
  217 + c.ref.model.whisper.tailPaddings = config.model.whisper.tailPaddings;
  218 +
  219 + c.ref.model.tdnn.model = config.model.tdnn.model.toNativeUtf8();
  220 +
  221 + c.ref.model.tokens = config.model.tokens.toNativeUtf8();
  222 +
  223 + c.ref.model.numThreads = config.model.numThreads;
  224 + c.ref.model.debug = config.model.debug ? 1 : 0;
  225 + c.ref.model.provider = config.model.provider.toNativeUtf8();
  226 + c.ref.model.modelType = config.model.modelType.toNativeUtf8();
  227 + c.ref.model.modelingUnit = config.model.modelingUnit.toNativeUtf8();
  228 + c.ref.model.bpeVocab = config.model.bpeVocab.toNativeUtf8();
  229 + c.ref.model.telespeechCtc = config.model.telespeechCtc.toNativeUtf8();
  230 +
  231 + c.ref.lm.model = config.lm.model.toNativeUtf8();
  232 + c.ref.lm.scale = config.lm.scale;
  233 +
  234 + c.ref.decodingMethod = config.decodingMethod.toNativeUtf8();
  235 + c.ref.maxActivePaths = config.maxActivePaths;
  236 +
  237 + c.ref.hotwordsFile = config.hotwordsFile.toNativeUtf8();
  238 + c.ref.hotwordsScore = config.hotwordsScore;
  239 +
  240 + c.ref.ruleFsts = config.ruleFsts.toNativeUtf8();
  241 + c.ref.ruleFars = config.ruleFars.toNativeUtf8();
  242 +
  243 + final ptr = SherpaOnnxBindings.createOfflineRecognizer?.call(c) ?? nullptr;
  244 +
  245 + calloc.free(c.ref.ruleFars);
  246 + calloc.free(c.ref.ruleFsts);
  247 + calloc.free(c.ref.hotwordsFile);
  248 + calloc.free(c.ref.decodingMethod);
  249 + calloc.free(c.ref.lm.model);
  250 + calloc.free(c.ref.model.telespeechCtc);
  251 + calloc.free(c.ref.model.bpeVocab);
  252 + calloc.free(c.ref.model.modelingUnit);
  253 + calloc.free(c.ref.model.modelType);
  254 + calloc.free(c.ref.model.provider);
  255 + calloc.free(c.ref.model.tokens);
  256 + calloc.free(c.ref.model.tdnn.model);
  257 + calloc.free(c.ref.model.whisper.task);
  258 + calloc.free(c.ref.model.whisper.language);
  259 + calloc.free(c.ref.model.whisper.decoder);
  260 + calloc.free(c.ref.model.whisper.encoder);
  261 + calloc.free(c.ref.model.nemoCtc.model);
  262 + calloc.free(c.ref.model.paraformer.model);
  263 + calloc.free(c.ref.model.transducer.encoder);
  264 + calloc.free(c.ref.model.transducer.decoder);
  265 + calloc.free(c.ref.model.transducer.joiner);
  266 + calloc.free(c);
  267 +
  268 + return OfflineRecognizer._(ptr: ptr, config: config);
  269 + }
  270 +
  271 + /// The user has to invoke stream.free() on the returned instance
  272 + /// to avoid memory leak
  273 + OfflineStream createStream() {
  274 + final p = SherpaOnnxBindings.createOfflineStream?.call(ptr) ?? nullptr;
  275 + return OfflineStream(ptr: p);
  276 + }
  277 +
  278 + void decode(OfflineStream stream) {
  279 + SherpaOnnxBindings.decodeOfflineStream?.call(ptr, stream.ptr);
  280 + }
  281 +
  282 + OfflineRecognizerResult getResult(OfflineStream stream) {
  283 + final json =
  284 + SherpaOnnxBindings.getOfflineStreamResultAsJson?.call(stream.ptr) ??
  285 + nullptr;
  286 + if (json == nullptr) {
  287 + return OfflineRecognizerResult(text: '', tokens: [], timestamps: []);
  288 + }
  289 +
  290 + final parsedJson = jsonDecode(json.toDartString());
  291 +
  292 + SherpaOnnxBindings.destroyOfflineStreamResultJson?.call(json);
  293 +
  294 + return OfflineRecognizerResult(
  295 + text: parsedJson['text'],
  296 + tokens: List<String>.from(parsedJson['tokens']),
  297 + timestamps: List<double>.from(parsedJson['timestamps']));
  298 + }
  299 +
  300 + Pointer<SherpaOnnxOfflineRecognizer> ptr;
  301 + OfflineRecognizerConfig config;
  302 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:ffi';
  3 +import 'dart:typed_data';
  4 +import 'package:ffi/ffi.dart';
  5 +
  6 +import './sherpa_onnx_bindings.dart';
  7 +
  8 +class OfflineStream {
  9 + /// The user has to call OfflineStream.free() to avoid memory leak.
  10 + OfflineStream({required this.ptr});
  11 +
  12 + void free() {
  13 + SherpaOnnxBindings.destroyOfflineStream?.call(ptr);
  14 + ptr = nullptr;
  15 + }
  16 +
  17 + /// If you have List<double> data, then you can use
  18 + /// Float32List.fromList(data) to convert data to Float32List
  19 + ///
  20 + /// See
  21 + /// https://api.flutter.dev/flutter/dart-core/List-class.html
  22 + /// and
  23 + /// https://api.flutter.dev/flutter/dart-typed_data/Float32List-class.html
  24 + void acceptWaveform({required Float32List samples, required int sampleRate}) {
  25 + final n = samples.length;
  26 + final Pointer<Float> p = calloc<Float>(n);
  27 +
  28 + final pList = p.asTypedList(n);
  29 + pList.setAll(0, samples);
  30 +
  31 + SherpaOnnxBindings.acceptWaveformOffline?.call(ptr, sampleRate, p, n);
  32 +
  33 + calloc.free(p);
  34 + }
  35 +
  36 + Pointer<SherpaOnnxOfflineStream> ptr;
  37 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:convert';
  3 +import 'dart:ffi';
  4 +
  5 +import 'package:ffi/ffi.dart';
  6 +
  7 +import './feature_config.dart';
  8 +import './online_stream.dart';
  9 +import './sherpa_onnx_bindings.dart';
  10 +
  11 +class OnlineTransducerModelConfig {
  12 + const OnlineTransducerModelConfig({
  13 + this.encoder = '',
  14 + this.decoder = '',
  15 + this.joiner = '',
  16 + });
  17 +
  18 + @override
  19 + String toString() {
  20 + return 'OnlineTransducerModelConfig(encoder: $encoder, decoder: $decoder, joiner: $joiner)';
  21 + }
  22 +
  23 + final String encoder;
  24 + final String decoder;
  25 + final String joiner;
  26 +}
  27 +
  28 +class OnlineParaformerModelConfig {
  29 + const OnlineParaformerModelConfig({this.encoder = '', this.decoder = ''});
  30 +
  31 + @override
  32 + String toString() {
  33 + return 'OnlineParaformerModelConfig(encoder: $encoder, decoder: $decoder)';
  34 + }
  35 +
  36 + final String encoder;
  37 + final String decoder;
  38 +}
  39 +
  40 +class OnlineZipformer2CtcModelConfig {
  41 + const OnlineZipformer2CtcModelConfig({this.model = ''});
  42 +
  43 + @override
  44 + String toString() {
  45 + return 'OnlineZipformer2CtcModelConfig(model: $model)';
  46 + }
  47 +
  48 + final String model;
  49 +}
  50 +
  51 +class OnlineModelConfig {
  52 + const OnlineModelConfig({
  53 + this.transducer = const OnlineTransducerModelConfig(),
  54 + this.paraformer = const OnlineParaformerModelConfig(),
  55 + this.zipformer2Ctc = const OnlineZipformer2CtcModelConfig(),
  56 + required this.tokens,
  57 + this.numThreads = 1,
  58 + this.provider = 'cpu',
  59 + this.debug = true,
  60 + this.modelType = '',
  61 + this.modelingUnit = '',
  62 + this.bpeVocab = '',
  63 + });
  64 +
  65 + @override
  66 + String toString() {
  67 + return 'OnlineModelConfig(transducer: $transducer, paraformer: $paraformer, zipformer2Ctc: $zipformer2Ctc, tokens: $tokens, numThreads: $numThreads, provider: $provider, debug: $debug, modelType: $modelType, modelingUnit: $modelingUnit, bpeVocab: $bpeVocab)';
  68 + }
  69 +
  70 + final OnlineTransducerModelConfig transducer;
  71 + final OnlineParaformerModelConfig paraformer;
  72 + final OnlineZipformer2CtcModelConfig zipformer2Ctc;
  73 +
  74 + final String tokens;
  75 +
  76 + final int numThreads;
  77 +
  78 + final String provider;
  79 +
  80 + final bool debug;
  81 +
  82 + final String modelType;
  83 +
  84 + final String modelingUnit;
  85 +
  86 + final String bpeVocab;
  87 +}
  88 +
  89 +class OnlineCtcFstDecoderConfig {
  90 + const OnlineCtcFstDecoderConfig({this.graph = '', this.maxActive = 3000});
  91 +
  92 + @override
  93 + String toString() {
  94 + return 'OnlineCtcFstDecoderConfig(graph: $graph, maxActive: $maxActive)';
  95 + }
  96 +
  97 + final String graph;
  98 + final int maxActive;
  99 +}
  100 +
  101 +class OnlineRecognizerConfig {
  102 + const OnlineRecognizerConfig({
  103 + this.feat = const FeatureConfig(),
  104 + required this.model,
  105 + this.decodingMethod = 'greedy_search',
  106 + this.maxActivePaths = 4,
  107 + this.enableEndpoint = true,
  108 + this.rule1MinTrailingSilence = 2.4,
  109 + this.rule2MinTrailingSilence = 1.2,
  110 + this.rule3MinUtteranceLength = 20,
  111 + this.hotwordsFile = '',
  112 + this.hotwordsScore = 1.5,
  113 + this.ctcFstDecoderConfig = const OnlineCtcFstDecoderConfig(),
  114 + this.ruleFsts = '',
  115 + this.ruleFars = '',
  116 + });
  117 +
  118 + @override
  119 + String toString() {
  120 + return 'OnlineRecognizerConfig(feat: $feat, model: $model, decodingMethod: $decodingMethod, maxActivePaths: $maxActivePaths, enableEndpoint: $enableEndpoint, rule1MinTrailingSilence: $rule1MinTrailingSilence, rule2MinTrailingSilence: $rule2MinTrailingSilence, rule3MinUtteranceLength: $rule3MinUtteranceLength, hotwordsFile: $hotwordsFile, hotwordsScore: $hotwordsScore, ctcFstDecoderConfig: $ctcFstDecoderConfig, ruleFsts: $ruleFsts, ruleFars: $ruleFars)';
  121 + }
  122 +
  123 + final FeatureConfig feat;
  124 + final OnlineModelConfig model;
  125 + final String decodingMethod;
  126 +
  127 + final int maxActivePaths;
  128 +
  129 + final bool enableEndpoint;
  130 +
  131 + final double rule1MinTrailingSilence;
  132 +
  133 + final double rule2MinTrailingSilence;
  134 +
  135 + final double rule3MinUtteranceLength;
  136 +
  137 + final String hotwordsFile;
  138 +
  139 + final double hotwordsScore;
  140 +
  141 + final OnlineCtcFstDecoderConfig ctcFstDecoderConfig;
  142 + final String ruleFsts;
  143 + final String ruleFars;
  144 +}
  145 +
  146 +class OnlineRecognizerResult {
  147 + OnlineRecognizerResult(
  148 + {required this.text, required this.tokens, required this.timestamps});
  149 +
  150 + @override
  151 + String toString() {
  152 + return 'OnlineRecognizerResult(text: $text, tokens: $tokens, timestamps: $timestamps)';
  153 + }
  154 +
  155 + final String text;
  156 + final List<String> tokens;
  157 + final List<double> timestamps;
  158 +}
  159 +
  160 +class OnlineRecognizer {
  161 + OnlineRecognizer._({required this.ptr, required this.config});
  162 +
  163 + /// The user is responsible to call the OnlineRecognizer.free()
  164 + /// method of the returned instance to avoid memory leak.
  165 + factory OnlineRecognizer(OnlineRecognizerConfig config) {
  166 + final c = calloc<SherpaOnnxOnlineRecognizerConfig>();
  167 + c.ref.feat.sampleRate = config.feat.sampleRate;
  168 + c.ref.feat.featureDim = config.feat.featureDim;
  169 +
  170 + // transducer
  171 + c.ref.model.transducer.encoder =
  172 + config.model.transducer.encoder.toNativeUtf8();
  173 + c.ref.model.transducer.decoder =
  174 + config.model.transducer.decoder.toNativeUtf8();
  175 + c.ref.model.transducer.joiner =
  176 + config.model.transducer.joiner.toNativeUtf8();
  177 +
  178 + // paraformer
  179 + c.ref.model.paraformer.encoder =
  180 + config.model.paraformer.encoder.toNativeUtf8();
  181 + c.ref.model.paraformer.decoder =
  182 + config.model.paraformer.decoder.toNativeUtf8();
  183 +
  184 + // zipformer2Ctc
  185 + c.ref.model.zipformer2Ctc.model =
  186 + config.model.zipformer2Ctc.model.toNativeUtf8();
  187 +
  188 + c.ref.model.tokens = config.model.tokens.toNativeUtf8();
  189 + c.ref.model.numThreads = config.model.numThreads;
  190 + c.ref.model.provider = config.model.provider.toNativeUtf8();
  191 + c.ref.model.debug = config.model.debug ? 1 : 0;
  192 + c.ref.model.modelType = config.model.modelType.toNativeUtf8();
  193 + c.ref.model.modelingUnit = config.model.modelingUnit.toNativeUtf8();
  194 + c.ref.model.bpeVocab = config.model.bpeVocab.toNativeUtf8();
  195 +
  196 + c.ref.decodingMethod = config.decodingMethod.toNativeUtf8();
  197 + c.ref.maxActivePaths = config.maxActivePaths;
  198 + c.ref.enableEndpoint = config.enableEndpoint ? 1 : 0;
  199 + c.ref.rule1MinTrailingSilence = config.rule1MinTrailingSilence;
  200 + c.ref.rule2MinTrailingSilence = config.rule2MinTrailingSilence;
  201 + c.ref.rule3MinUtteranceLength = config.rule3MinUtteranceLength;
  202 + c.ref.hotwordsFile = config.hotwordsFile.toNativeUtf8();
  203 + c.ref.hotwordsScore = config.hotwordsScore;
  204 +
  205 + c.ref.ctcFstDecoderConfig.graph =
  206 + config.ctcFstDecoderConfig.graph.toNativeUtf8();
  207 + c.ref.ctcFstDecoderConfig.maxActive = config.ctcFstDecoderConfig.maxActive;
  208 + c.ref.ruleFsts = config.ruleFsts.toNativeUtf8();
  209 + c.ref.ruleFars = config.ruleFars.toNativeUtf8();
  210 +
  211 + final ptr = SherpaOnnxBindings.createOnlineRecognizer?.call(c) ?? nullptr;
  212 +
  213 + calloc.free(c.ref.ruleFars);
  214 + calloc.free(c.ref.ruleFsts);
  215 + calloc.free(c.ref.ctcFstDecoderConfig.graph);
  216 + calloc.free(c.ref.hotwordsFile);
  217 + calloc.free(c.ref.decodingMethod);
  218 + calloc.free(c.ref.model.bpeVocab);
  219 + calloc.free(c.ref.model.modelingUnit);
  220 + calloc.free(c.ref.model.modelType);
  221 + calloc.free(c.ref.model.provider);
  222 + calloc.free(c.ref.model.tokens);
  223 + calloc.free(c.ref.model.zipformer2Ctc.model);
  224 + calloc.free(c.ref.model.paraformer.encoder);
  225 + calloc.free(c.ref.model.paraformer.decoder);
  226 +
  227 + calloc.free(c.ref.model.transducer.encoder);
  228 + calloc.free(c.ref.model.transducer.decoder);
  229 + calloc.free(c.ref.model.transducer.joiner);
  230 + calloc.free(c);
  231 +
  232 + return OnlineRecognizer._(ptr: ptr, config: config);
  233 + }
  234 +
  235 + void free() {
  236 + SherpaOnnxBindings.destroyOnlineRecognizer?.call(ptr);
  237 + ptr = nullptr;
  238 + }
  239 +
  240 + /// The user has to invoke stream.free() on the returned instance
  241 + /// to avoid memory leak
  242 + OnlineStream createStream({String hotwords = ''}) {
  243 + if (hotwords == '') {
  244 + final p = SherpaOnnxBindings.createOnlineStream?.call(ptr) ?? nullptr;
  245 + return OnlineStream(ptr: p);
  246 + }
  247 +
  248 + final utf8 = hotwords.toNativeUtf8();
  249 + final p =
  250 + SherpaOnnxBindings.createOnlineStreamWithHotwords?.call(ptr, utf8) ??
  251 + nullptr;
  252 + calloc.free(utf8);
  253 + return OnlineStream(ptr: p);
  254 + }
  255 +
  256 + bool isReady(OnlineStream stream) {
  257 + int ready =
  258 + SherpaOnnxBindings.isOnlineStreamReady?.call(ptr, stream.ptr) ?? 0;
  259 +
  260 + return ready == 1;
  261 + }
  262 +
  263 + OnlineRecognizerResult getResult(OnlineStream stream) {
  264 + final json =
  265 + SherpaOnnxBindings.getOnlineStreamResultAsJson?.call(ptr, stream.ptr) ??
  266 + nullptr;
  267 + if (json == nullptr) {
  268 + return OnlineRecognizerResult(text: '', tokens: [], timestamps: []);
  269 + }
  270 +
  271 + final parsedJson = jsonDecode(json.toDartString());
  272 +
  273 + SherpaOnnxBindings.destroyOnlineStreamResultJson?.call(json);
  274 +
  275 + return OnlineRecognizerResult(
  276 + text: parsedJson['text'],
  277 + tokens: List<String>.from(parsedJson['tokens']),
  278 + timestamps: List<double>.from(parsedJson['timestamps']));
  279 + }
  280 +
  281 + void reset(OnlineStream stream) {
  282 + SherpaOnnxBindings.reset?.call(ptr, stream.ptr);
  283 + }
  284 +
  285 + void decode(OnlineStream stream) {
  286 + SherpaOnnxBindings.decodeOnlineStream?.call(ptr, stream.ptr);
  287 + }
  288 +
  289 + bool isEndpoint(OnlineStream stream) {
  290 + int yes = SherpaOnnxBindings.isEndpoint?.call(ptr, stream.ptr) ?? 0;
  291 +
  292 + return yes == 1;
  293 + }
  294 +
  295 + Pointer<SherpaOnnxOnlineRecognizer> ptr;
  296 + OnlineRecognizerConfig config;
  297 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:ffi';
  3 +import 'dart:typed_data';
  4 +import 'package:ffi/ffi.dart';
  5 +
  6 +import './sherpa_onnx_bindings.dart';
  7 +
  8 +class OnlineStream {
  9 + /// The user has to call OnlineStream.free() to avoid memory leak.
  10 + OnlineStream({required this.ptr});
  11 +
  12 + void free() {
  13 + SherpaOnnxBindings.destroyOnlineStream?.call(ptr);
  14 + ptr = nullptr;
  15 + }
  16 +
  17 + /// If you have List<double> data, then you can use
  18 + /// Float32List.fromList(data) to convert data to Float32List
  19 + ///
  20 + /// See
  21 + /// https://api.flutter.dev/flutter/dart-core/List-class.html
  22 + /// and
  23 + /// https://api.flutter.dev/flutter/dart-typed_data/Float32List-class.html
  24 + void acceptWaveform({required Float32List samples, required int sampleRate}) {
  25 + final n = samples.length;
  26 + final Pointer<Float> p = calloc<Float>(n);
  27 +
  28 + final pList = p.asTypedList(n);
  29 + pList.setAll(0, samples);
  30 +
  31 + SherpaOnnxBindings.onlineStreamAcceptWaveform?.call(ptr, sampleRate, p, n);
  32 +
  33 + calloc.free(p);
  34 + }
  35 +
  36 + void inputFinished() {
  37 + SherpaOnnxBindings.onlineStreamInputFinished?.call(ptr);
  38 + }
  39 +
  40 + Pointer<SherpaOnnxOnlineStream> ptr;
  41 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:ffi';
  3 +import 'package:ffi/ffi.dart';
  4 +
  5 +final class SherpaOnnxOfflineTtsVitsModelConfig extends Struct {
  6 + external Pointer<Utf8> model;
  7 + external Pointer<Utf8> lexicon;
  8 + external Pointer<Utf8> tokens;
  9 + external Pointer<Utf8> dataDir;
  10 +
  11 + @Float()
  12 + external double noiseScale;
  13 +
  14 + @Float()
  15 + external double noiseScaleW;
  16 +
  17 + @Float()
  18 + external double lengthScale;
  19 +
  20 + external Pointer<Utf8> dictDir;
  21 +}
  22 +
  23 +final class SherpaOnnxOfflineTtsModelConfig extends Struct {
  24 + external SherpaOnnxOfflineTtsVitsModelConfig vits;
  25 + @Int32()
  26 + external int numThreads;
  27 +
  28 + @Int32()
  29 + external int debug;
  30 +
  31 + external Pointer<Utf8> provider;
  32 +}
  33 +
  34 +final class SherpaOnnxOfflineTtsConfig extends Struct {
  35 + external SherpaOnnxOfflineTtsModelConfig model;
  36 + external Pointer<Utf8> ruleFsts;
  37 +
  38 + @Int32()
  39 + external int maxNumSenetences;
  40 +
  41 + external Pointer<Utf8> ruleFars;
  42 +}
  43 +
  44 +final class SherpaOnnxGeneratedAudio extends Struct {
  45 + external Pointer<Float> samples;
  46 +
  47 + @Int32()
  48 + external int n;
  49 +
  50 + @Int32()
  51 + external int sampleRate;
  52 +}
  53 +
  54 +final class SherpaOnnxFeatureConfig extends Struct {
  55 + @Int32()
  56 + external int sampleRate;
  57 +
  58 + @Int32()
  59 + external int featureDim;
  60 +}
  61 +
  62 +final class SherpaOnnxOfflineTransducerModelConfig extends Struct {
  63 + external Pointer<Utf8> encoder;
  64 + external Pointer<Utf8> decoder;
  65 + external Pointer<Utf8> joiner;
  66 +}
  67 +
  68 +final class SherpaOnnxOfflineParaformerModelConfig extends Struct {
  69 + external Pointer<Utf8> model;
  70 +}
  71 +
  72 +final class SherpaOnnxOfflineNemoEncDecCtcModelConfig extends Struct {
  73 + external Pointer<Utf8> model;
  74 +}
  75 +
  76 +final class SherpaOnnxOfflineWhisperModelConfig extends Struct {
  77 + external Pointer<Utf8> encoder;
  78 + external Pointer<Utf8> decoder;
  79 + external Pointer<Utf8> language;
  80 + external Pointer<Utf8> task;
  81 +
  82 + @Int32()
  83 + external int tailPaddings;
  84 +}
  85 +
  86 +final class SherpaOnnxOfflineTdnnModelConfig extends Struct {
  87 + external Pointer<Utf8> model;
  88 +}
  89 +
  90 +final class SherpaOnnxOfflineLMConfig extends Struct {
  91 + external Pointer<Utf8> model;
  92 +
  93 + @Float()
  94 + external double scale;
  95 +}
  96 +
  97 +final class SherpaOnnxOfflineModelConfig extends Struct {
  98 + external SherpaOnnxOfflineTransducerModelConfig transducer;
  99 + external SherpaOnnxOfflineParaformerModelConfig paraformer;
  100 + external SherpaOnnxOfflineNemoEncDecCtcModelConfig nemoCtc;
  101 + external SherpaOnnxOfflineWhisperModelConfig whisper;
  102 + external SherpaOnnxOfflineTdnnModelConfig tdnn;
  103 +
  104 + external Pointer<Utf8> tokens;
  105 +
  106 + @Int32()
  107 + external int numThreads;
  108 +
  109 + @Int32()
  110 + external int debug;
  111 +
  112 + external Pointer<Utf8> provider;
  113 +
  114 + external Pointer<Utf8> modelType;
  115 + external Pointer<Utf8> modelingUnit;
  116 + external Pointer<Utf8> bpeVocab;
  117 + external Pointer<Utf8> telespeechCtc;
  118 +}
  119 +
  120 +final class SherpaOnnxOfflineRecognizerConfig extends Struct {
  121 + external SherpaOnnxFeatureConfig feat;
  122 + external SherpaOnnxOfflineModelConfig model;
  123 + external SherpaOnnxOfflineLMConfig lm;
  124 + external Pointer<Utf8> decodingMethod;
  125 +
  126 + @Int32()
  127 + external int maxActivePaths;
  128 +
  129 + external Pointer<Utf8> hotwordsFile;
  130 +
  131 + @Float()
  132 + external double hotwordsScore;
  133 +
  134 + external Pointer<Utf8> ruleFsts;
  135 + external Pointer<Utf8> ruleFars;
  136 +}
  137 +
  138 +final class SherpaOnnxOnlineTransducerModelConfig extends Struct {
  139 + external Pointer<Utf8> encoder;
  140 + external Pointer<Utf8> decoder;
  141 + external Pointer<Utf8> joiner;
  142 +}
  143 +
  144 +final class SherpaOnnxOnlineParaformerModelConfig extends Struct {
  145 + external Pointer<Utf8> encoder;
  146 + external Pointer<Utf8> decoder;
  147 +}
  148 +
  149 +final class SherpaOnnxOnlineZipformer2CtcModelConfig extends Struct {
  150 + external Pointer<Utf8> model;
  151 +}
  152 +
  153 +final class SherpaOnnxOnlineModelConfig extends Struct {
  154 + external SherpaOnnxOnlineTransducerModelConfig transducer;
  155 + external SherpaOnnxOnlineParaformerModelConfig paraformer;
  156 + external SherpaOnnxOnlineZipformer2CtcModelConfig zipformer2Ctc;
  157 +
  158 + external Pointer<Utf8> tokens;
  159 +
  160 + @Int32()
  161 + external int numThreads;
  162 +
  163 + external Pointer<Utf8> provider;
  164 +
  165 + @Int32()
  166 + external int debug;
  167 +
  168 + external Pointer<Utf8> modelType;
  169 +
  170 + external Pointer<Utf8> modelingUnit;
  171 +
  172 + external Pointer<Utf8> bpeVocab;
  173 +}
  174 +
  175 +final class SherpaOnnxOnlineCtcFstDecoderConfig extends Struct {
  176 + external Pointer<Utf8> graph;
  177 +
  178 + @Int32()
  179 + external int maxActive;
  180 +}
  181 +
  182 +final class SherpaOnnxOnlineRecognizerConfig extends Struct {
  183 + external SherpaOnnxFeatureConfig feat;
  184 + external SherpaOnnxOnlineModelConfig model;
  185 + external Pointer<Utf8> decodingMethod;
  186 +
  187 + @Int32()
  188 + external int maxActivePaths;
  189 +
  190 + @Int32()
  191 + external int enableEndpoint;
  192 +
  193 + @Float()
  194 + external double rule1MinTrailingSilence;
  195 +
  196 + @Float()
  197 + external double rule2MinTrailingSilence;
  198 +
  199 + @Float()
  200 + external double rule3MinUtteranceLength;
  201 +
  202 + external Pointer<Utf8> hotwordsFile;
  203 +
  204 + @Float()
  205 + external double hotwordsScore;
  206 +
  207 + external SherpaOnnxOnlineCtcFstDecoderConfig ctcFstDecoderConfig;
  208 +
  209 + external Pointer<Utf8> ruleFsts;
  210 + external Pointer<Utf8> ruleFars;
  211 +}
  212 +
  213 +final class SherpaOnnxSileroVadModelConfig extends Struct {
  214 + external Pointer<Utf8> model;
  215 +
  216 + @Float()
  217 + external double threshold;
  218 +
  219 + @Float()
  220 + external double minSilenceDuration;
  221 +
  222 + @Float()
  223 + external double minSpeechDuration;
  224 +
  225 + @Int32()
  226 + external int windowSize;
  227 +}
  228 +
  229 +final class SherpaOnnxVadModelConfig extends Struct {
  230 + external SherpaOnnxSileroVadModelConfig sileroVad;
  231 +
  232 + @Int32()
  233 + external int sampleRate;
  234 +
  235 + @Int32()
  236 + external int numThreads;
  237 +
  238 + external Pointer<Utf8> provider;
  239 +
  240 + @Int32()
  241 + external int debug;
  242 +}
  243 +
  244 +final class SherpaOnnxSpeechSegment extends Struct {
  245 + @Int32()
  246 + external int start;
  247 +
  248 + external Pointer<Float> samples;
  249 +
  250 + @Int32()
  251 + external int n;
  252 +}
  253 +
  254 +final class SherpaOnnxWave extends Struct {
  255 + external Pointer<Float> samples;
  256 +
  257 + @Int32()
  258 + external int sampleRate;
  259 +
  260 + @Int32()
  261 + external int numSamples;
  262 +}
  263 +
  264 +final class SherpaOnnxSpeakerEmbeddingExtractorConfig extends Struct {
  265 + external Pointer<Utf8> model;
  266 +
  267 + @Int32()
  268 + external int numThreads;
  269 +
  270 + @Int32()
  271 + external int debug;
  272 +
  273 + external Pointer<Utf8> provider;
  274 +}
  275 +
  276 +final class SherpaOnnxOfflineTts extends Opaque {}
  277 +
  278 +final class SherpaOnnxCircularBuffer extends Opaque {}
  279 +
  280 +final class SherpaOnnxVoiceActivityDetector extends Opaque {}
  281 +
  282 +final class SherpaOnnxOnlineStream extends Opaque {}
  283 +
  284 +final class SherpaOnnxOnlineRecognizer extends Opaque {}
  285 +
  286 +final class SherpaOnnxOfflineRecognizer extends Opaque {}
  287 +
  288 +final class SherpaOnnxOfflineStream extends Opaque {}
  289 +
  290 +final class SherpaOnnxSpeakerEmbeddingExtractor extends Opaque {}
  291 +
  292 +final class SherpaOnnxSpeakerEmbeddingManager extends Opaque {}
  293 +
  294 +typedef SherpaOnnxCreateOfflineTtsNative = Pointer<SherpaOnnxOfflineTts>
  295 + Function(Pointer<SherpaOnnxOfflineTtsConfig>);
  296 +
  297 +typedef SherpaOnnxCreateOfflineTts = SherpaOnnxCreateOfflineTtsNative;
  298 +
  299 +typedef SherpaOnnxDestroyOfflineTtsNative = Void Function(
  300 + Pointer<SherpaOnnxOfflineTts>);
  301 +
  302 +typedef SherpaOnnxDestroyOfflineTts = void Function(
  303 + Pointer<SherpaOnnxOfflineTts>);
  304 +
  305 +typedef SherpaOnnxOfflineTtsSampleRateNative = Int32 Function(
  306 + Pointer<SherpaOnnxOfflineTts>);
  307 +
  308 +typedef SherpaOnnxOfflineTtsSampleRate = int Function(
  309 + Pointer<SherpaOnnxOfflineTts>);
  310 +
  311 +typedef SherpaOnnxOfflineTtsNumSpeakersNative = Int32 Function(
  312 + Pointer<SherpaOnnxOfflineTts>);
  313 +
  314 +typedef SherpaOnnxOfflineTtsNumSpeakers = int Function(
  315 + Pointer<SherpaOnnxOfflineTts>);
  316 +
  317 +typedef SherpaOnnxOfflineTtsGenerateNative = Pointer<SherpaOnnxGeneratedAudio>
  318 + Function(Pointer<SherpaOnnxOfflineTts>, Pointer<Utf8>, Int32, Float);
  319 +
  320 +typedef SherpaOnnxOfflineTtsGenerate = Pointer<SherpaOnnxGeneratedAudio>
  321 + Function(Pointer<SherpaOnnxOfflineTts>, Pointer<Utf8>, int, double);
  322 +
  323 +typedef SherpaOnnxDestroyOfflineTtsGeneratedAudioNative = Void Function(
  324 + Pointer<SherpaOnnxGeneratedAudio>);
  325 +
  326 +typedef SherpaOnnxDestroyOfflineTtsGeneratedAudio = void Function(
  327 + Pointer<SherpaOnnxGeneratedAudio>);
  328 +
  329 +typedef SherpaOnnxGeneratedAudioCallbackNative = Int Function(
  330 + Pointer<Float>, Int32);
  331 +
  332 +typedef SherpaOnnxOfflineTtsGenerateWithCallbackNative
  333 + = Pointer<SherpaOnnxGeneratedAudio> Function(
  334 + Pointer<SherpaOnnxOfflineTts>,
  335 + Pointer<Utf8>,
  336 + Int32,
  337 + Float,
  338 + Pointer<NativeFunction<SherpaOnnxGeneratedAudioCallbackNative>>);
  339 +
  340 +typedef SherpaOnnxOfflineTtsGenerateWithCallback
  341 + = Pointer<SherpaOnnxGeneratedAudio> Function(
  342 + Pointer<SherpaOnnxOfflineTts>,
  343 + Pointer<Utf8>,
  344 + int,
  345 + double,
  346 + Pointer<NativeFunction<SherpaOnnxGeneratedAudioCallbackNative>>);
  347 +
  348 +typedef CreateOfflineRecognizerNative = Pointer<SherpaOnnxOfflineRecognizer>
  349 + Function(Pointer<SherpaOnnxOfflineRecognizerConfig>);
  350 +
  351 +typedef CreateOfflineRecognizer = CreateOfflineRecognizerNative;
  352 +
  353 +typedef DestroyOfflineRecognizerNative = Void Function(
  354 + Pointer<SherpaOnnxOfflineRecognizer>);
  355 +
  356 +typedef DestroyOfflineRecognizer = void Function(
  357 + Pointer<SherpaOnnxOfflineRecognizer>);
  358 +
  359 +typedef CreateOfflineStreamNative = Pointer<SherpaOnnxOfflineStream> Function(
  360 + Pointer<SherpaOnnxOfflineRecognizer>);
  361 +
  362 +typedef CreateOfflineStream = CreateOfflineStreamNative;
  363 +
  364 +typedef DestroyOfflineStreamNative = Void Function(
  365 + Pointer<SherpaOnnxOfflineStream>);
  366 +
  367 +typedef DestroyOfflineStream = void Function(Pointer<SherpaOnnxOfflineStream>);
  368 +
  369 +typedef AcceptWaveformOfflineNative = Void Function(
  370 + Pointer<SherpaOnnxOfflineStream>, Int32, Pointer<Float>, Int32);
  371 +
  372 +typedef AcceptWaveformOffline = void Function(
  373 + Pointer<SherpaOnnxOfflineStream>, int, Pointer<Float>, int);
  374 +
  375 +typedef DecodeOfflineStreamNative = Void Function(
  376 + Pointer<SherpaOnnxOfflineRecognizer>, Pointer<SherpaOnnxOfflineStream>);
  377 +
  378 +typedef DecodeOfflineStream = void Function(
  379 + Pointer<SherpaOnnxOfflineRecognizer>, Pointer<SherpaOnnxOfflineStream>);
  380 +
  381 +typedef GetOfflineStreamResultAsJsonNative = Pointer<Utf8> Function(
  382 + Pointer<SherpaOnnxOfflineStream>);
  383 +
  384 +typedef GetOfflineStreamResultAsJson = GetOfflineStreamResultAsJsonNative;
  385 +
  386 +typedef DestroyOfflineStreamResultJsonNative = Void Function(Pointer<Utf8>);
  387 +
  388 +typedef DestroyOfflineStreamResultJson = void Function(Pointer<Utf8>);
  389 +
  390 +typedef CreateOnlineRecognizerNative = Pointer<SherpaOnnxOnlineRecognizer>
  391 + Function(Pointer<SherpaOnnxOnlineRecognizerConfig>);
  392 +
  393 +typedef CreateOnlineRecognizer = CreateOnlineRecognizerNative;
  394 +
  395 +typedef DestroyOnlineRecognizerNative = Void Function(
  396 + Pointer<SherpaOnnxOnlineRecognizer>);
  397 +
  398 +typedef DestroyOnlineRecognizer = void Function(
  399 + Pointer<SherpaOnnxOnlineRecognizer>);
  400 +
  401 +typedef CreateOnlineStreamNative = Pointer<SherpaOnnxOnlineStream> Function(
  402 + Pointer<SherpaOnnxOnlineRecognizer>);
  403 +
  404 +typedef CreateOnlineStream = CreateOnlineStreamNative;
  405 +
  406 +typedef CreateOnlineStreamWithHotwordsNative = Pointer<SherpaOnnxOnlineStream>
  407 + Function(Pointer<SherpaOnnxOnlineRecognizer>, Pointer<Utf8>);
  408 +
  409 +typedef CreateOnlineStreamWithHotwords = CreateOnlineStreamWithHotwordsNative;
  410 +
  411 +typedef IsOnlineStreamReadyNative = Int32 Function(
  412 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  413 +
  414 +typedef IsOnlineStreamReady = int Function(
  415 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  416 +
  417 +typedef DecodeOnlineStreamNative = Void Function(
  418 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  419 +
  420 +typedef DecodeOnlineStream = void Function(
  421 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  422 +
  423 +typedef GetOnlineStreamResultAsJsonNative = Pointer<Utf8> Function(
  424 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  425 +
  426 +typedef GetOnlineStreamResultAsJson = GetOnlineStreamResultAsJsonNative;
  427 +
  428 +typedef ResetNative = Void Function(
  429 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  430 +
  431 +typedef Reset = void Function(
  432 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  433 +
  434 +typedef IsEndpointNative = Int32 Function(
  435 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  436 +
  437 +typedef IsEndpoint = int Function(
  438 + Pointer<SherpaOnnxOnlineRecognizer>, Pointer<SherpaOnnxOnlineStream>);
  439 +
  440 +typedef DestroyOnlineStreamResultJsonNative = Void Function(Pointer<Utf8>);
  441 +
  442 +typedef DestroyOnlineStreamResultJson = void Function(Pointer<Utf8>);
  443 +
  444 +typedef SherpaOnnxCreateVoiceActivityDetectorNative
  445 + = Pointer<SherpaOnnxVoiceActivityDetector> Function(
  446 + Pointer<SherpaOnnxVadModelConfig>, Float);
  447 +
  448 +typedef SherpaOnnxCreateVoiceActivityDetector
  449 + = Pointer<SherpaOnnxVoiceActivityDetector> Function(
  450 + Pointer<SherpaOnnxVadModelConfig>, double);
  451 +
  452 +typedef SherpaOnnxDestroyVoiceActivityDetectorNative = Void Function(
  453 + Pointer<SherpaOnnxVoiceActivityDetector>);
  454 +
  455 +typedef SherpaOnnxDestroyVoiceActivityDetector = void Function(
  456 + Pointer<SherpaOnnxVoiceActivityDetector>);
  457 +
  458 +typedef SherpaOnnxVoiceActivityDetectorAcceptWaveformNative = Void Function(
  459 + Pointer<SherpaOnnxVoiceActivityDetector>, Pointer<Float>, Int32);
  460 +
  461 +typedef SherpaOnnxVoiceActivityDetectorAcceptWaveform = void Function(
  462 + Pointer<SherpaOnnxVoiceActivityDetector>, Pointer<Float>, int);
  463 +
  464 +typedef SherpaOnnxVoiceActivityDetectorEmptyNative = Int32 Function(
  465 + Pointer<SherpaOnnxVoiceActivityDetector>);
  466 +
  467 +typedef SherpaOnnxVoiceActivityDetectorEmpty = int Function(
  468 + Pointer<SherpaOnnxVoiceActivityDetector>);
  469 +
  470 +typedef SherpaOnnxVoiceActivityDetectorDetectedNative = Int32 Function(
  471 + Pointer<SherpaOnnxVoiceActivityDetector>);
  472 +
  473 +typedef SherpaOnnxVoiceActivityDetectorDetected = int Function(
  474 + Pointer<SherpaOnnxVoiceActivityDetector>);
  475 +
  476 +typedef SherpaOnnxVoiceActivityDetectorPopNative = Void Function(
  477 + Pointer<SherpaOnnxVoiceActivityDetector>);
  478 +
  479 +typedef SherpaOnnxVoiceActivityDetectorPop = void Function(
  480 + Pointer<SherpaOnnxVoiceActivityDetector>);
  481 +
  482 +typedef SherpaOnnxVoiceActivityDetectorClearNative = Void Function(
  483 + Pointer<SherpaOnnxVoiceActivityDetector>);
  484 +
  485 +typedef SherpaOnnxVoiceActivityDetectorClear = void Function(
  486 + Pointer<SherpaOnnxVoiceActivityDetector>);
  487 +
  488 +typedef SherpaOnnxVoiceActivityDetectorResetNative = Void Function(
  489 + Pointer<SherpaOnnxVoiceActivityDetector>);
  490 +
  491 +typedef SherpaOnnxVoiceActivityDetectorReset = void Function(
  492 + Pointer<SherpaOnnxVoiceActivityDetector>);
  493 +
  494 +typedef SherpaOnnxVoiceActivityDetectorFrontNative
  495 + = Pointer<SherpaOnnxSpeechSegment> Function(
  496 + Pointer<SherpaOnnxVoiceActivityDetector>);
  497 +
  498 +typedef SherpaOnnxVoiceActivityDetectorFront
  499 + = SherpaOnnxVoiceActivityDetectorFrontNative;
  500 +
  501 +typedef SherpaOnnxDestroySpeechSegmentNative = Void Function(
  502 + Pointer<SherpaOnnxSpeechSegment>);
  503 +
  504 +typedef SherpaOnnxDestroySpeechSegment = void Function(
  505 + Pointer<SherpaOnnxSpeechSegment>);
  506 +
  507 +typedef SherpaOnnxCreateCircularBufferNative = Pointer<SherpaOnnxCircularBuffer>
  508 + Function(Int32);
  509 +
  510 +typedef SherpaOnnxCreateCircularBuffer = Pointer<SherpaOnnxCircularBuffer>
  511 + Function(int);
  512 +
  513 +typedef SherpaOnnxDestroyCircularBufferNative = Void Function(
  514 + Pointer<SherpaOnnxCircularBuffer>);
  515 +
  516 +typedef SherpaOnnxDestroyCircularBuffer = void Function(
  517 + Pointer<SherpaOnnxCircularBuffer>);
  518 +
  519 +typedef SherpaOnnxCircularBufferPushNative = Void Function(
  520 + Pointer<SherpaOnnxCircularBuffer>, Pointer<Float>, Int32);
  521 +
  522 +typedef SherpaOnnxCircularBufferPush = void Function(
  523 + Pointer<SherpaOnnxCircularBuffer>, Pointer<Float>, int);
  524 +
  525 +typedef SherpaOnnxCircularBufferGetNative = Pointer<Float> Function(
  526 + Pointer<SherpaOnnxCircularBuffer>, Int32, Int32);
  527 +
  528 +typedef SherpaOnnxCircularBufferGet = Pointer<Float> Function(
  529 + Pointer<SherpaOnnxCircularBuffer>, int, int);
  530 +
  531 +typedef SherpaOnnxCircularBufferFreeNative = Void Function(Pointer<Float>);
  532 +
  533 +typedef SherpaOnnxCircularBufferFree = void Function(Pointer<Float>);
  534 +
  535 +typedef SherpaOnnxCircularBufferPopNative = Void Function(
  536 + Pointer<SherpaOnnxCircularBuffer>, Int32);
  537 +
  538 +typedef SherpaOnnxCircularBufferPop = void Function(
  539 + Pointer<SherpaOnnxCircularBuffer>, int);
  540 +
  541 +typedef SherpaOnnxCircularBufferSizeNative = Int32 Function(
  542 + Pointer<SherpaOnnxCircularBuffer>);
  543 +
  544 +typedef SherpaOnnxCircularBufferSize = int Function(
  545 + Pointer<SherpaOnnxCircularBuffer>);
  546 +
  547 +typedef SherpaOnnxCircularBufferHeadNative = Int32 Function(
  548 + Pointer<SherpaOnnxCircularBuffer>);
  549 +
  550 +typedef SherpaOnnxCircularBufferHead = int Function(
  551 + Pointer<SherpaOnnxCircularBuffer>);
  552 +
  553 +typedef SherpaOnnxCircularBufferResetNative = Void Function(
  554 + Pointer<SherpaOnnxCircularBuffer>);
  555 +
  556 +typedef SherpaOnnxCircularBufferReset = void Function(
  557 + Pointer<SherpaOnnxCircularBuffer>);
  558 +
  559 +typedef SherpaOnnxCreateSpeakerEmbeddingManagerNative
  560 + = Pointer<SherpaOnnxSpeakerEmbeddingManager> Function(Int32);
  561 +
  562 +typedef SherpaOnnxCreateSpeakerEmbeddingManager
  563 + = Pointer<SherpaOnnxSpeakerEmbeddingManager> Function(int);
  564 +
  565 +typedef SherpaOnnxDestroySpeakerEmbeddingManagerNative = Void Function(
  566 + Pointer<SherpaOnnxSpeakerEmbeddingManager>);
  567 +
  568 +typedef SherpaOnnxDestroySpeakerEmbeddingManager = void Function(
  569 + Pointer<SherpaOnnxSpeakerEmbeddingManager>);
  570 +
  571 +typedef SherpaOnnxSpeakerEmbeddingManagerAddNative = Int32 Function(
  572 + Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Utf8>, Pointer<Float>);
  573 +
  574 +typedef SherpaOnnxSpeakerEmbeddingManagerAdd = int Function(
  575 + Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Utf8>, Pointer<Float>);
  576 +
  577 +typedef SherpaOnnxSpeakerEmbeddingManagerAddListFlattenedNative
  578 + = Int32 Function(Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Utf8>,
  579 + Pointer<Float>, Int32);
  580 +
  581 +typedef SherpaOnnxSpeakerEmbeddingManagerAddListFlattened = int Function(
  582 + Pointer<SherpaOnnxSpeakerEmbeddingManager>,
  583 + Pointer<Utf8>,
  584 + Pointer<Float>,
  585 + int);
  586 +
  587 +typedef SherpaOnnxSpeakerEmbeddingManagerRemoveNative = Int32 Function(
  588 + Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Utf8>);
  589 +
  590 +typedef SherpaOnnxSpeakerEmbeddingManagerRemove = int Function(
  591 + Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Utf8>);
  592 +
  593 +typedef SherpaOnnxSpeakerEmbeddingManagerContainsNative = Int32 Function(
  594 + Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Utf8>);
  595 +
  596 +typedef SherpaOnnxSpeakerEmbeddingManagerContains = int Function(
  597 + Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Utf8>);
  598 +
  599 +typedef SherpaOnnxSpeakerEmbeddingManagerSearchNative = Pointer<Utf8> Function(
  600 + Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Float>, Float);
  601 +
  602 +typedef SherpaOnnxSpeakerEmbeddingManagerSearch = Pointer<Utf8> Function(
  603 + Pointer<SherpaOnnxSpeakerEmbeddingManager>, Pointer<Float>, double);
  604 +
  605 +typedef SherpaOnnxSpeakerEmbeddingManagerFreeSearchNative = Void Function(
  606 + Pointer<Utf8>);
  607 +
  608 +typedef SherpaOnnxSpeakerEmbeddingManagerFreeSearch = void Function(
  609 + Pointer<Utf8>);
  610 +
  611 +typedef SherpaOnnxSpeakerEmbeddingManagerNumSpeakersNative = Int32 Function(
  612 + Pointer<SherpaOnnxSpeakerEmbeddingManager>);
  613 +
  614 +typedef SherpaOnnxSpeakerEmbeddingManagerNumSpeakers = int Function(
  615 + Pointer<SherpaOnnxSpeakerEmbeddingManager>);
  616 +
  617 +typedef SherpaOnnxSpeakerEmbeddingManagerVerifyNative = Int32 Function(
  618 + Pointer<SherpaOnnxSpeakerEmbeddingManager>,
  619 + Pointer<Utf8>,
  620 + Pointer<Float>,
  621 + Float);
  622 +
  623 +typedef SherpaOnnxSpeakerEmbeddingManagerVerify = int Function(
  624 + Pointer<SherpaOnnxSpeakerEmbeddingManager>,
  625 + Pointer<Utf8>,
  626 + Pointer<Float>,
  627 + double);
  628 +
  629 +typedef SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakersNative
  630 + = Pointer<Pointer<Utf8>> Function(
  631 + Pointer<SherpaOnnxSpeakerEmbeddingManager>);
  632 +
  633 +typedef SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakers
  634 + = SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakersNative;
  635 +
  636 +typedef SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakersNative = Void Function(
  637 + Pointer<Pointer<Utf8>>);
  638 +
  639 +typedef SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers = void Function(
  640 + Pointer<Pointer<Utf8>>);
  641 +
  642 +typedef SherpaOnnxCreateSpeakerEmbeddingExtractorNative
  643 + = Pointer<SherpaOnnxSpeakerEmbeddingExtractor> Function(
  644 + Pointer<SherpaOnnxSpeakerEmbeddingExtractorConfig>);
  645 +
  646 +typedef SherpaOnnxCreateSpeakerEmbeddingExtractor
  647 + = SherpaOnnxCreateSpeakerEmbeddingExtractorNative;
  648 +
  649 +typedef SherpaOnnxDestroySpeakerEmbeddingExtractorNative = Void Function(
  650 + Pointer<SherpaOnnxSpeakerEmbeddingExtractor>);
  651 +
  652 +typedef SherpaOnnxDestroySpeakerEmbeddingExtractor = void Function(
  653 + Pointer<SherpaOnnxSpeakerEmbeddingExtractor>);
  654 +
  655 +typedef SherpaOnnxSpeakerEmbeddingExtractorDimNative = Int32 Function(
  656 + Pointer<SherpaOnnxSpeakerEmbeddingExtractor>);
  657 +
  658 +typedef SherpaOnnxSpeakerEmbeddingExtractorDim = int Function(
  659 + Pointer<SherpaOnnxSpeakerEmbeddingExtractor>);
  660 +
  661 +typedef SherpaOnnxSpeakerEmbeddingExtractorCreateStreamNative
  662 + = Pointer<SherpaOnnxOnlineStream> Function(
  663 + Pointer<SherpaOnnxSpeakerEmbeddingExtractor>);
  664 +
  665 +typedef SherpaOnnxSpeakerEmbeddingExtractorCreateStream
  666 + = SherpaOnnxSpeakerEmbeddingExtractorCreateStreamNative;
  667 +
  668 +typedef DestroyOnlineStreamNative = Void Function(
  669 + Pointer<SherpaOnnxOnlineStream>);
  670 +
  671 +typedef DestroyOnlineStream = void Function(Pointer<SherpaOnnxOnlineStream>);
  672 +
  673 +typedef OnlineStreamAcceptWaveformNative = Void Function(
  674 + Pointer<SherpaOnnxOnlineStream>, Int32, Pointer<Float>, Int32);
  675 +
  676 +typedef OnlineStreamAcceptWaveform = void Function(
  677 + Pointer<SherpaOnnxOnlineStream>, int, Pointer<Float>, int);
  678 +
  679 +typedef OnlineStreamInputFinishedNative = Void Function(
  680 + Pointer<SherpaOnnxOnlineStream>);
  681 +
  682 +typedef OnlineStreamInputFinished = void Function(
  683 + Pointer<SherpaOnnxOnlineStream>);
  684 +
  685 +typedef SherpaOnnxSpeakerEmbeddingExtractorIsReadyNative = Int32 Function(
  686 + Pointer<SherpaOnnxSpeakerEmbeddingExtractor>,
  687 + Pointer<SherpaOnnxOnlineStream>);
  688 +
  689 +typedef SherpaOnnxSpeakerEmbeddingExtractorIsReady = int Function(
  690 + Pointer<SherpaOnnxSpeakerEmbeddingExtractor>,
  691 + Pointer<SherpaOnnxOnlineStream>);
  692 +
  693 +typedef SherpaOnnxSpeakerEmbeddingExtractorComputeEmbeddingNative
  694 + = Pointer<Float> Function(Pointer<SherpaOnnxSpeakerEmbeddingExtractor>,
  695 + Pointer<SherpaOnnxOnlineStream>);
  696 +
  697 +typedef SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding
  698 + = SherpaOnnxSpeakerEmbeddingExtractorComputeEmbeddingNative;
  699 +
  700 +typedef SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbeddingNative = Void
  701 + Function(Pointer<Float>);
  702 +
  703 +typedef SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding = void Function(
  704 + Pointer<Float>);
  705 +
  706 +typedef SherpaOnnxReadWaveNative = Pointer<SherpaOnnxWave> Function(
  707 + Pointer<Utf8>);
  708 +
  709 +typedef SherpaOnnxReadWave = SherpaOnnxReadWaveNative;
  710 +
  711 +typedef SherpaOnnxWriteWaveNative = Int32 Function(
  712 + Pointer<Float>, Int32, Int32, Pointer<Utf8>);
  713 +
  714 +typedef SherpaOnnxWriteWave = int Function(
  715 + Pointer<Float>, int, int, Pointer<Utf8>);
  716 +
  717 +typedef SherpaOnnxFreeWaveNative = Void Function(Pointer<SherpaOnnxWave>);
  718 +
  719 +typedef SherpaOnnxFreeWave = void Function(Pointer<SherpaOnnxWave>);
  720 +
  721 +class SherpaOnnxBindings {
  722 + static SherpaOnnxCreateOfflineTts? createOfflineTts;
  723 + static SherpaOnnxDestroyOfflineTts? destroyOfflineTts;
  724 + static SherpaOnnxOfflineTtsSampleRate? offlineTtsSampleRate;
  725 + static SherpaOnnxOfflineTtsNumSpeakers? offlineTtsNumSpeakers;
  726 + static SherpaOnnxOfflineTtsGenerate? offlineTtsGenerate;
  727 + static SherpaOnnxDestroyOfflineTtsGeneratedAudio?
  728 + destroyOfflineTtsGeneratedAudio;
  729 + static SherpaOnnxOfflineTtsGenerateWithCallback?
  730 + offlineTtsGenerateWithCallback;
  731 +
  732 + static CreateOfflineRecognizer? createOfflineRecognizer;
  733 + static DestroyOfflineRecognizer? destroyOfflineRecognizer;
  734 + static CreateOfflineStream? createOfflineStream;
  735 + static DestroyOfflineStream? destroyOfflineStream;
  736 + static AcceptWaveformOffline? acceptWaveformOffline;
  737 + static DecodeOfflineStream? decodeOfflineStream;
  738 + static GetOfflineStreamResultAsJson? getOfflineStreamResultAsJson;
  739 + static DestroyOfflineStreamResultJson? destroyOfflineStreamResultJson;
  740 +
  741 + static CreateOnlineRecognizer? createOnlineRecognizer;
  742 +
  743 + static DestroyOnlineRecognizer? destroyOnlineRecognizer;
  744 +
  745 + static CreateOnlineStream? createOnlineStream;
  746 +
  747 + static CreateOnlineStreamWithHotwords? createOnlineStreamWithHotwords;
  748 +
  749 + static IsOnlineStreamReady? isOnlineStreamReady;
  750 +
  751 + static DecodeOnlineStream? decodeOnlineStream;
  752 +
  753 + static GetOnlineStreamResultAsJson? getOnlineStreamResultAsJson;
  754 +
  755 + static Reset? reset;
  756 +
  757 + static IsEndpoint? isEndpoint;
  758 +
  759 + static DestroyOnlineStreamResultJson? destroyOnlineStreamResultJson;
  760 +
  761 + static SherpaOnnxCreateVoiceActivityDetector? createVoiceActivityDetector;
  762 +
  763 + static SherpaOnnxDestroyVoiceActivityDetector? destroyVoiceActivityDetector;
  764 +
  765 + static SherpaOnnxVoiceActivityDetectorAcceptWaveform?
  766 + voiceActivityDetectorAcceptWaveform;
  767 +
  768 + static SherpaOnnxVoiceActivityDetectorEmpty? voiceActivityDetectorEmpty;
  769 +
  770 + static SherpaOnnxVoiceActivityDetectorDetected? voiceActivityDetectorDetected;
  771 +
  772 + static SherpaOnnxVoiceActivityDetectorPop? voiceActivityDetectorPop;
  773 +
  774 + static SherpaOnnxVoiceActivityDetectorClear? voiceActivityDetectorClear;
  775 +
  776 + static SherpaOnnxVoiceActivityDetectorFront? voiceActivityDetectorFront;
  777 +
  778 + static SherpaOnnxDestroySpeechSegment? destroySpeechSegment;
  779 +
  780 + static SherpaOnnxVoiceActivityDetectorReset? voiceActivityDetectorReset;
  781 +
  782 + static SherpaOnnxCreateCircularBuffer? createCircularBuffer;
  783 +
  784 + static SherpaOnnxDestroyCircularBuffer? destroyCircularBuffer;
  785 +
  786 + static SherpaOnnxCircularBufferPush? circularBufferPush;
  787 +
  788 + static SherpaOnnxCircularBufferGet? circularBufferGet;
  789 +
  790 + static SherpaOnnxCircularBufferFree? circularBufferFree;
  791 +
  792 + static SherpaOnnxCircularBufferPop? circularBufferPop;
  793 +
  794 + static SherpaOnnxCircularBufferSize? circularBufferSize;
  795 +
  796 + static SherpaOnnxCircularBufferHead? circularBufferHead;
  797 +
  798 + static SherpaOnnxCircularBufferReset? circularBufferReset;
  799 +
  800 + static SherpaOnnxCreateSpeakerEmbeddingExtractor?
  801 + createSpeakerEmbeddingExtractor;
  802 +
  803 + static SherpaOnnxDestroySpeakerEmbeddingExtractor?
  804 + destroySpeakerEmbeddingExtractor;
  805 +
  806 + static SherpaOnnxSpeakerEmbeddingExtractorDim? speakerEmbeddingExtractorDim;
  807 +
  808 + static SherpaOnnxSpeakerEmbeddingExtractorCreateStream?
  809 + speakerEmbeddingExtractorCreateStream;
  810 +
  811 + static SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding?
  812 + speakerEmbeddingExtractorComputeEmbedding;
  813 +
  814 + static SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding?
  815 + speakerEmbeddingExtractorDestroyEmbedding;
  816 +
  817 + static DestroyOnlineStream? destroyOnlineStream;
  818 +
  819 + static OnlineStreamAcceptWaveform? onlineStreamAcceptWaveform;
  820 +
  821 + static OnlineStreamInputFinished? onlineStreamInputFinished;
  822 +
  823 + static SherpaOnnxSpeakerEmbeddingExtractorIsReady?
  824 + speakerEmbeddingExtractorIsReady;
  825 +
  826 + static SherpaOnnxCreateSpeakerEmbeddingManager? createSpeakerEmbeddingManager;
  827 +
  828 + static SherpaOnnxDestroySpeakerEmbeddingManager?
  829 + destroySpeakerEmbeddingManager;
  830 +
  831 + static SherpaOnnxSpeakerEmbeddingManagerAdd? speakerEmbeddingManagerAdd;
  832 +
  833 + static SherpaOnnxSpeakerEmbeddingManagerAddListFlattened?
  834 + speakerEmbeddingManagerAddListFlattened;
  835 +
  836 + static SherpaOnnxSpeakerEmbeddingManagerRemove? speakerEmbeddingManagerRemove;
  837 +
  838 + static SherpaOnnxSpeakerEmbeddingManagerContains?
  839 + speakerEmbeddingManagerContains;
  840 +
  841 + static SherpaOnnxSpeakerEmbeddingManagerSearch? speakerEmbeddingManagerSearch;
  842 +
  843 + static SherpaOnnxSpeakerEmbeddingManagerFreeSearch?
  844 + speakerEmbeddingManagerFreeSearch;
  845 +
  846 + static SherpaOnnxSpeakerEmbeddingManagerNumSpeakers?
  847 + speakerEmbeddingManagerNumSpeakers;
  848 +
  849 + static SherpaOnnxSpeakerEmbeddingManagerVerify? speakerEmbeddingManagerVerify;
  850 +
  851 + static SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakers?
  852 + speakerEmbeddingManagerGetAllSpeakers;
  853 +
  854 + static SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers?
  855 + speakerEmbeddingManagerFreeAllSpeakers;
  856 +
  857 + static SherpaOnnxReadWave? readWave;
  858 +
  859 + static SherpaOnnxWriteWave? writeWave;
  860 +
  861 + static SherpaOnnxFreeWave? freeWave;
  862 +
  863 + static void init(DynamicLibrary dynamicLibrary) {
  864 + createOfflineTts ??= dynamicLibrary
  865 + .lookup<NativeFunction<SherpaOnnxCreateOfflineTtsNative>>(
  866 + 'SherpaOnnxCreateOfflineTts')
  867 + .asFunction();
  868 +
  869 + destroyOfflineTts ??= dynamicLibrary
  870 + .lookup<NativeFunction<SherpaOnnxDestroyOfflineTtsNative>>(
  871 + 'SherpaOnnxDestroyOfflineTts')
  872 + .asFunction();
  873 +
  874 + offlineTtsSampleRate ??= dynamicLibrary
  875 + .lookup<NativeFunction<SherpaOnnxOfflineTtsSampleRateNative>>(
  876 + 'SherpaOnnxOfflineTtsSampleRate')
  877 + .asFunction();
  878 +
  879 + offlineTtsNumSpeakers ??= dynamicLibrary
  880 + .lookup<NativeFunction<SherpaOnnxOfflineTtsNumSpeakersNative>>(
  881 + 'SherpaOnnxOfflineTtsNumSpeakers')
  882 + .asFunction();
  883 +
  884 + offlineTtsGenerate ??= dynamicLibrary
  885 + .lookup<NativeFunction<SherpaOnnxOfflineTtsGenerateNative>>(
  886 + 'SherpaOnnxOfflineTtsGenerate')
  887 + .asFunction();
  888 +
  889 + destroyOfflineTtsGeneratedAudio ??= dynamicLibrary
  890 + .lookup<
  891 + NativeFunction<
  892 + SherpaOnnxDestroyOfflineTtsGeneratedAudioNative>>(
  893 + 'SherpaOnnxDestroyOfflineTtsGeneratedAudio')
  894 + .asFunction();
  895 +
  896 + offlineTtsGenerateWithCallback ??= dynamicLibrary
  897 + .lookup<NativeFunction<SherpaOnnxOfflineTtsGenerateWithCallbackNative>>(
  898 + 'SherpaOnnxOfflineTtsGenerateWithCallback')
  899 + .asFunction();
  900 +
  901 + createOfflineRecognizer ??= dynamicLibrary
  902 + .lookup<NativeFunction<CreateOfflineRecognizerNative>>(
  903 + 'CreateOfflineRecognizer')
  904 + .asFunction();
  905 +
  906 + destroyOfflineRecognizer ??= dynamicLibrary
  907 + .lookup<NativeFunction<DestroyOfflineRecognizerNative>>(
  908 + 'DestroyOfflineRecognizer')
  909 + .asFunction();
  910 +
  911 + createOfflineStream ??= dynamicLibrary
  912 + .lookup<NativeFunction<CreateOfflineStreamNative>>(
  913 + 'CreateOfflineStream')
  914 + .asFunction();
  915 +
  916 + destroyOfflineStream ??= dynamicLibrary
  917 + .lookup<NativeFunction<DestroyOfflineStreamNative>>(
  918 + 'DestroyOfflineStream')
  919 + .asFunction();
  920 +
  921 + acceptWaveformOffline ??= dynamicLibrary
  922 + .lookup<NativeFunction<AcceptWaveformOfflineNative>>(
  923 + 'AcceptWaveformOffline')
  924 + .asFunction();
  925 +
  926 + decodeOfflineStream ??= dynamicLibrary
  927 + .lookup<NativeFunction<DecodeOfflineStreamNative>>(
  928 + 'DecodeOfflineStream')
  929 + .asFunction();
  930 +
  931 + getOfflineStreamResultAsJson ??= dynamicLibrary
  932 + .lookup<NativeFunction<GetOfflineStreamResultAsJsonNative>>(
  933 + 'GetOfflineStreamResultAsJson')
  934 + .asFunction();
  935 +
  936 + destroyOfflineStreamResultJson ??= dynamicLibrary
  937 + .lookup<NativeFunction<DestroyOfflineStreamResultJsonNative>>(
  938 + 'DestroyOfflineStreamResultJson')
  939 + .asFunction();
  940 +
  941 + createOnlineRecognizer ??= dynamicLibrary
  942 + .lookup<NativeFunction<CreateOnlineRecognizerNative>>(
  943 + 'CreateOnlineRecognizer')
  944 + .asFunction();
  945 +
  946 + destroyOnlineRecognizer ??= dynamicLibrary
  947 + .lookup<NativeFunction<DestroyOnlineRecognizerNative>>(
  948 + 'DestroyOnlineRecognizer')
  949 + .asFunction();
  950 +
  951 + createOnlineStream ??= dynamicLibrary
  952 + .lookup<NativeFunction<CreateOnlineStreamNative>>('CreateOnlineStream')
  953 + .asFunction();
  954 +
  955 + createOnlineStreamWithHotwords ??= dynamicLibrary
  956 + .lookup<NativeFunction<CreateOnlineStreamWithHotwordsNative>>(
  957 + 'CreateOnlineStreamWithHotwords')
  958 + .asFunction();
  959 +
  960 + isOnlineStreamReady ??= dynamicLibrary
  961 + .lookup<NativeFunction<IsOnlineStreamReadyNative>>(
  962 + 'IsOnlineStreamReady')
  963 + .asFunction();
  964 +
  965 + decodeOnlineStream ??= dynamicLibrary
  966 + .lookup<NativeFunction<DecodeOnlineStreamNative>>('DecodeOnlineStream')
  967 + .asFunction();
  968 +
  969 + getOnlineStreamResultAsJson ??= dynamicLibrary
  970 + .lookup<NativeFunction<GetOnlineStreamResultAsJsonNative>>(
  971 + 'GetOnlineStreamResultAsJson')
  972 + .asFunction();
  973 +
  974 + reset ??= dynamicLibrary
  975 + .lookup<NativeFunction<ResetNative>>('Reset')
  976 + .asFunction();
  977 +
  978 + isEndpoint ??= dynamicLibrary
  979 + .lookup<NativeFunction<IsEndpointNative>>('IsEndpoint')
  980 + .asFunction();
  981 +
  982 + destroyOnlineStreamResultJson ??= dynamicLibrary
  983 + .lookup<NativeFunction<DestroyOnlineStreamResultJsonNative>>(
  984 + 'DestroyOnlineStreamResultJson')
  985 + .asFunction();
  986 +
  987 + createVoiceActivityDetector ??= dynamicLibrary
  988 + .lookup<NativeFunction<SherpaOnnxCreateVoiceActivityDetectorNative>>(
  989 + 'SherpaOnnxCreateVoiceActivityDetector')
  990 + .asFunction();
  991 +
  992 + destroyVoiceActivityDetector ??= dynamicLibrary
  993 + .lookup<NativeFunction<SherpaOnnxDestroyVoiceActivityDetectorNative>>(
  994 + 'SherpaOnnxDestroyVoiceActivityDetector')
  995 + .asFunction();
  996 +
  997 + voiceActivityDetectorAcceptWaveform ??= dynamicLibrary
  998 + .lookup<
  999 + NativeFunction<
  1000 + SherpaOnnxVoiceActivityDetectorAcceptWaveformNative>>(
  1001 + 'SherpaOnnxVoiceActivityDetectorAcceptWaveform')
  1002 + .asFunction();
  1003 +
  1004 + voiceActivityDetectorEmpty ??= dynamicLibrary
  1005 + .lookup<NativeFunction<SherpaOnnxVoiceActivityDetectorEmptyNative>>(
  1006 + 'SherpaOnnxVoiceActivityDetectorEmpty')
  1007 + .asFunction();
  1008 +
  1009 + voiceActivityDetectorDetected ??= dynamicLibrary
  1010 + .lookup<NativeFunction<SherpaOnnxVoiceActivityDetectorDetectedNative>>(
  1011 + 'SherpaOnnxVoiceActivityDetectorDetected')
  1012 + .asFunction();
  1013 +
  1014 + voiceActivityDetectorPop ??= dynamicLibrary
  1015 + .lookup<NativeFunction<SherpaOnnxVoiceActivityDetectorPopNative>>(
  1016 + 'SherpaOnnxVoiceActivityDetectorPop')
  1017 + .asFunction();
  1018 +
  1019 + voiceActivityDetectorClear ??= dynamicLibrary
  1020 + .lookup<NativeFunction<SherpaOnnxVoiceActivityDetectorClearNative>>(
  1021 + 'SherpaOnnxVoiceActivityDetectorClear')
  1022 + .asFunction();
  1023 +
  1024 + voiceActivityDetectorFront ??= dynamicLibrary
  1025 + .lookup<NativeFunction<SherpaOnnxVoiceActivityDetectorFrontNative>>(
  1026 + 'SherpaOnnxVoiceActivityDetectorFront')
  1027 + .asFunction();
  1028 +
  1029 + destroySpeechSegment ??= dynamicLibrary
  1030 + .lookup<NativeFunction<SherpaOnnxDestroySpeechSegmentNative>>(
  1031 + 'SherpaOnnxDestroySpeechSegment')
  1032 + .asFunction();
  1033 +
  1034 + voiceActivityDetectorReset ??= dynamicLibrary
  1035 + .lookup<NativeFunction<SherpaOnnxVoiceActivityDetectorResetNative>>(
  1036 + 'SherpaOnnxVoiceActivityDetectorReset')
  1037 + .asFunction();
  1038 +
  1039 + createCircularBuffer ??= dynamicLibrary
  1040 + .lookup<NativeFunction<SherpaOnnxCreateCircularBufferNative>>(
  1041 + 'SherpaOnnxCreateCircularBuffer')
  1042 + .asFunction();
  1043 +
  1044 + destroyCircularBuffer ??= dynamicLibrary
  1045 + .lookup<NativeFunction<SherpaOnnxDestroyCircularBufferNative>>(
  1046 + 'SherpaOnnxDestroyCircularBuffer')
  1047 + .asFunction();
  1048 +
  1049 + circularBufferPush ??= dynamicLibrary
  1050 + .lookup<NativeFunction<SherpaOnnxCircularBufferPushNative>>(
  1051 + 'SherpaOnnxCircularBufferPush')
  1052 + .asFunction();
  1053 +
  1054 + circularBufferGet ??= dynamicLibrary
  1055 + .lookup<NativeFunction<SherpaOnnxCircularBufferGetNative>>(
  1056 + 'SherpaOnnxCircularBufferGet')
  1057 + .asFunction();
  1058 +
  1059 + circularBufferFree ??= dynamicLibrary
  1060 + .lookup<NativeFunction<SherpaOnnxCircularBufferFreeNative>>(
  1061 + 'SherpaOnnxCircularBufferFree')
  1062 + .asFunction();
  1063 +
  1064 + circularBufferPop ??= dynamicLibrary
  1065 + .lookup<NativeFunction<SherpaOnnxCircularBufferPopNative>>(
  1066 + 'SherpaOnnxCircularBufferPop')
  1067 + .asFunction();
  1068 +
  1069 + circularBufferSize ??= dynamicLibrary
  1070 + .lookup<NativeFunction<SherpaOnnxCircularBufferSizeNative>>(
  1071 + 'SherpaOnnxCircularBufferSize')
  1072 + .asFunction();
  1073 +
  1074 + circularBufferHead ??= dynamicLibrary
  1075 + .lookup<NativeFunction<SherpaOnnxCircularBufferHeadNative>>(
  1076 + 'SherpaOnnxCircularBufferHead')
  1077 + .asFunction();
  1078 +
  1079 + circularBufferReset ??= dynamicLibrary
  1080 + .lookup<NativeFunction<SherpaOnnxCircularBufferResetNative>>(
  1081 + 'SherpaOnnxCircularBufferReset')
  1082 + .asFunction();
  1083 +
  1084 + createSpeakerEmbeddingExtractor ??= dynamicLibrary
  1085 + .lookup<
  1086 + NativeFunction<
  1087 + SherpaOnnxCreateSpeakerEmbeddingExtractorNative>>(
  1088 + 'SherpaOnnxCreateSpeakerEmbeddingExtractor')
  1089 + .asFunction();
  1090 +
  1091 + destroySpeakerEmbeddingExtractor ??= dynamicLibrary
  1092 + .lookup<
  1093 + NativeFunction<
  1094 + SherpaOnnxDestroySpeakerEmbeddingExtractorNative>>(
  1095 + 'SherpaOnnxDestroySpeakerEmbeddingExtractor')
  1096 + .asFunction();
  1097 +
  1098 + speakerEmbeddingExtractorDim ??= dynamicLibrary
  1099 + .lookup<NativeFunction<SherpaOnnxSpeakerEmbeddingExtractorDimNative>>(
  1100 + 'SherpaOnnxSpeakerEmbeddingExtractorDim')
  1101 + .asFunction();
  1102 +
  1103 + speakerEmbeddingExtractorCreateStream ??= dynamicLibrary
  1104 + .lookup<
  1105 + NativeFunction<
  1106 + SherpaOnnxSpeakerEmbeddingExtractorCreateStreamNative>>(
  1107 + 'SherpaOnnxSpeakerEmbeddingExtractorCreateStream')
  1108 + .asFunction();
  1109 +
  1110 + speakerEmbeddingExtractorComputeEmbedding ??= dynamicLibrary
  1111 + .lookup<
  1112 + NativeFunction<
  1113 + SherpaOnnxSpeakerEmbeddingExtractorComputeEmbeddingNative>>(
  1114 + 'SherpaOnnxSpeakerEmbeddingExtractorComputeEmbedding')
  1115 + .asFunction();
  1116 +
  1117 + speakerEmbeddingExtractorDestroyEmbedding ??= dynamicLibrary
  1118 + .lookup<
  1119 + NativeFunction<
  1120 + SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbeddingNative>>(
  1121 + 'SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding')
  1122 + .asFunction();
  1123 +
  1124 + destroyOnlineStream ??= dynamicLibrary
  1125 + .lookup<NativeFunction<DestroyOnlineStreamNative>>(
  1126 + 'DestroyOnlineStream')
  1127 + .asFunction();
  1128 +
  1129 + onlineStreamAcceptWaveform ??= dynamicLibrary
  1130 + .lookup<NativeFunction<OnlineStreamAcceptWaveformNative>>(
  1131 + 'AcceptWaveform')
  1132 + .asFunction();
  1133 +
  1134 + onlineStreamInputFinished ??= dynamicLibrary
  1135 + .lookup<NativeFunction<OnlineStreamInputFinishedNative>>(
  1136 + 'InputFinished')
  1137 + .asFunction();
  1138 +
  1139 + speakerEmbeddingExtractorIsReady ??= dynamicLibrary
  1140 + .lookup<
  1141 + NativeFunction<
  1142 + SherpaOnnxSpeakerEmbeddingExtractorIsReadyNative>>(
  1143 + 'SherpaOnnxSpeakerEmbeddingExtractorIsReady')
  1144 + .asFunction();
  1145 +
  1146 + createSpeakerEmbeddingManager ??= dynamicLibrary
  1147 + .lookup<NativeFunction<SherpaOnnxCreateSpeakerEmbeddingManagerNative>>(
  1148 + 'SherpaOnnxCreateSpeakerEmbeddingManager')
  1149 + .asFunction();
  1150 +
  1151 + destroySpeakerEmbeddingManager ??= dynamicLibrary
  1152 + .lookup<NativeFunction<SherpaOnnxDestroySpeakerEmbeddingManagerNative>>(
  1153 + 'SherpaOnnxDestroySpeakerEmbeddingManager')
  1154 + .asFunction();
  1155 +
  1156 + speakerEmbeddingManagerAdd ??= dynamicLibrary
  1157 + .lookup<NativeFunction<SherpaOnnxSpeakerEmbeddingManagerAddNative>>(
  1158 + 'SherpaOnnxSpeakerEmbeddingManagerAdd')
  1159 + .asFunction();
  1160 +
  1161 + speakerEmbeddingManagerAddListFlattened ??= dynamicLibrary
  1162 + .lookup<
  1163 + NativeFunction<
  1164 + SherpaOnnxSpeakerEmbeddingManagerAddListFlattenedNative>>(
  1165 + 'SherpaOnnxSpeakerEmbeddingManagerAddListFlattened')
  1166 + .asFunction();
  1167 +
  1168 + speakerEmbeddingManagerRemove ??= dynamicLibrary
  1169 + .lookup<NativeFunction<SherpaOnnxSpeakerEmbeddingManagerRemoveNative>>(
  1170 + 'SherpaOnnxSpeakerEmbeddingManagerRemove')
  1171 + .asFunction();
  1172 +
  1173 + speakerEmbeddingManagerContains ??= dynamicLibrary
  1174 + .lookup<
  1175 + NativeFunction<
  1176 + SherpaOnnxSpeakerEmbeddingManagerContainsNative>>(
  1177 + 'SherpaOnnxSpeakerEmbeddingManagerContains')
  1178 + .asFunction();
  1179 +
  1180 + speakerEmbeddingManagerSearch ??= dynamicLibrary
  1181 + .lookup<NativeFunction<SherpaOnnxSpeakerEmbeddingManagerSearchNative>>(
  1182 + 'SherpaOnnxSpeakerEmbeddingManagerSearch')
  1183 + .asFunction();
  1184 +
  1185 + speakerEmbeddingManagerFreeSearch ??= dynamicLibrary
  1186 + .lookup<
  1187 + NativeFunction<
  1188 + SherpaOnnxSpeakerEmbeddingManagerFreeSearchNative>>(
  1189 + 'SherpaOnnxSpeakerEmbeddingManagerFreeSearch')
  1190 + .asFunction();
  1191 +
  1192 + speakerEmbeddingManagerNumSpeakers ??= dynamicLibrary
  1193 + .lookup<
  1194 + NativeFunction<
  1195 + SherpaOnnxSpeakerEmbeddingManagerNumSpeakersNative>>(
  1196 + 'SherpaOnnxSpeakerEmbeddingManagerNumSpeakers')
  1197 + .asFunction();
  1198 +
  1199 + speakerEmbeddingManagerVerify ??= dynamicLibrary
  1200 + .lookup<NativeFunction<SherpaOnnxSpeakerEmbeddingManagerVerifyNative>>(
  1201 + 'SherpaOnnxSpeakerEmbeddingManagerVerify')
  1202 + .asFunction();
  1203 +
  1204 + speakerEmbeddingManagerGetAllSpeakers ??= dynamicLibrary
  1205 + .lookup<
  1206 + NativeFunction<
  1207 + SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakersNative>>(
  1208 + 'SherpaOnnxSpeakerEmbeddingManagerGetAllSpeakers')
  1209 + .asFunction();
  1210 +
  1211 + speakerEmbeddingManagerFreeAllSpeakers ??= dynamicLibrary
  1212 + .lookup<
  1213 + NativeFunction<
  1214 + SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakersNative>>(
  1215 + 'SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers')
  1216 + .asFunction();
  1217 +
  1218 + readWave ??= dynamicLibrary
  1219 + .lookup<NativeFunction<SherpaOnnxReadWaveNative>>('SherpaOnnxReadWave')
  1220 + .asFunction();
  1221 +
  1222 + writeWave ??= dynamicLibrary
  1223 + .lookup<NativeFunction<SherpaOnnxWriteWaveNative>>(
  1224 + 'SherpaOnnxWriteWave')
  1225 + .asFunction();
  1226 +
  1227 + freeWave ??= dynamicLibrary
  1228 + .lookup<NativeFunction<SherpaOnnxFreeWaveNative>>('SherpaOnnxFreeWave')
  1229 + .asFunction();
  1230 + }
  1231 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:ffi';
  3 +import 'dart:typed_data';
  4 +import 'package:ffi/ffi.dart';
  5 +
  6 +import './online_stream.dart';
  7 +import './sherpa_onnx_bindings.dart';
  8 +
  9 +class SpeakerEmbeddingExtractorConfig {
  10 + const SpeakerEmbeddingExtractorConfig(
  11 + {required this.model,
  12 + this.numThreads = 1,
  13 + this.debug = true,
  14 + this.provider = 'cpu'});
  15 +
  16 + @override
  17 + String toString() {
  18 + return 'SpeakerEmbeddingExtractorConfig(model: $model, numThreads: $numThreads, debug: $debug, provider: $provider)';
  19 + }
  20 +
  21 + final String model;
  22 + final int numThreads;
  23 + final bool debug;
  24 + final String provider;
  25 +}
  26 +
  27 +class SpeakerEmbeddingExtractor {
  28 + SpeakerEmbeddingExtractor._({required this.ptr, required this.dim});
  29 +
  30 + /// The user is responsible to call the SpeakerEmbeddingExtractor.free()
  31 + /// method of the returned instance to avoid memory leak.
  32 + factory SpeakerEmbeddingExtractor(
  33 + {required SpeakerEmbeddingExtractorConfig config}) {
  34 + final c = calloc<SherpaOnnxSpeakerEmbeddingExtractorConfig>();
  35 +
  36 + final modelPtr = config.model.toNativeUtf8();
  37 + c.ref.model = modelPtr;
  38 +
  39 + c.ref.numThreads = config.numThreads;
  40 + c.ref.debug = config.debug ? 1 : 0;
  41 +
  42 + final providerPtr = config.provider.toNativeUtf8();
  43 + c.ref.provider = providerPtr;
  44 +
  45 + final ptr =
  46 + SherpaOnnxBindings.createSpeakerEmbeddingExtractor?.call(c) ?? nullptr;
  47 +
  48 + calloc.free(providerPtr);
  49 + calloc.free(modelPtr);
  50 + calloc.free(c);
  51 +
  52 + final dim = SherpaOnnxBindings.speakerEmbeddingExtractorDim?.call(ptr) ?? 0;
  53 +
  54 + return SpeakerEmbeddingExtractor._(ptr: ptr, dim: dim);
  55 + }
  56 +
  57 + void free() {
  58 + SherpaOnnxBindings.destroySpeakerEmbeddingExtractor?.call(ptr);
  59 + ptr = nullptr;
  60 + }
  61 +
  62 + /// The user has to invoke stream.free() on the returned instance
  63 + /// to avoid memory leak
  64 + OnlineStream createStream() {
  65 + final p =
  66 + SherpaOnnxBindings.speakerEmbeddingExtractorCreateStream?.call(ptr) ??
  67 + nullptr;
  68 +
  69 + return OnlineStream(ptr: p);
  70 + }
  71 +
  72 + bool isReady(OnlineStream stream) {
  73 + final int ready = SherpaOnnxBindings.speakerEmbeddingExtractorIsReady
  74 + ?.call(ptr, stream.ptr) ??
  75 + 0;
  76 + return ready == 1;
  77 + }
  78 +
  79 + Float32List compute(OnlineStream stream) {
  80 + final Pointer<Float> embedding = SherpaOnnxBindings
  81 + .speakerEmbeddingExtractorComputeEmbedding
  82 + ?.call(ptr, stream.ptr) ??
  83 + nullptr;
  84 +
  85 + if (embedding == nullptr) {
  86 + return Float32List(0);
  87 + }
  88 +
  89 + final embeddingList = embedding.asTypedList(dim);
  90 + final ans = Float32List(dim);
  91 + ans.setAll(0, embeddingList);
  92 +
  93 + SherpaOnnxBindings.speakerEmbeddingExtractorDestroyEmbedding
  94 + ?.call(embedding);
  95 +
  96 + return ans;
  97 + }
  98 +
  99 + Pointer<SherpaOnnxSpeakerEmbeddingExtractor> ptr;
  100 + final int dim;
  101 +}
  102 +
  103 +class SpeakerEmbeddingManager {
  104 + SpeakerEmbeddingManager._({required this.ptr, required this.dim});
  105 +
  106 + // The user has to use SpeakerEmbeddingManager.free() to avoid memory leak
  107 + factory SpeakerEmbeddingManager(int dim) {
  108 + final p =
  109 + SherpaOnnxBindings.createSpeakerEmbeddingManager?.call(dim) ?? nullptr;
  110 + return SpeakerEmbeddingManager._(ptr: p, dim: dim);
  111 + }
  112 +
  113 + void free() {
  114 + SherpaOnnxBindings.destroySpeakerEmbeddingManager?.call(ptr);
  115 + ptr = nullptr;
  116 + }
  117 +
  118 + /// Return true if added successfully; return false otherwise
  119 + bool add({required String name, required Float32List embedding}) {
  120 + assert(embedding.length == dim, '${embedding.length} vs $dim');
  121 +
  122 + final Pointer<Utf8> namePtr = name.toNativeUtf8();
  123 + final int n = embedding.length;
  124 +
  125 + final Pointer<Float> p = calloc<Float>(n);
  126 + final pList = p.asTypedList(n);
  127 + pList.setAll(0, embedding);
  128 +
  129 + final int ok =
  130 + SherpaOnnxBindings.speakerEmbeddingManagerAdd?.call(ptr, namePtr, p) ??
  131 + 0;
  132 +
  133 + calloc.free(p);
  134 + calloc.free(namePtr);
  135 +
  136 + return ok == 1;
  137 + }
  138 +
  139 + bool addMulti(
  140 + {required String name, required List<Float32List> embeddingList}) {
  141 + final Pointer<Utf8> namePtr = name.toNativeUtf8();
  142 + final int n = embeddingList.length;
  143 +
  144 + final Pointer<Float> p = calloc<Float>(n * dim);
  145 + final pList = p.asTypedList(n * dim);
  146 +
  147 + int offset = 0;
  148 + for (final e in embeddingList) {
  149 + assert(e.length == dim, '${e.length} vs $dim');
  150 +
  151 + pList.setAll(offset, e);
  152 + offset += dim;
  153 + }
  154 +
  155 + final int ok = SherpaOnnxBindings.speakerEmbeddingManagerAddListFlattened
  156 + ?.call(ptr, namePtr, p, n) ??
  157 + 0;
  158 +
  159 + calloc.free(p);
  160 + calloc.free(namePtr);
  161 +
  162 + return ok == 1;
  163 + }
  164 +
  165 + bool contains(String name) {
  166 + final Pointer<Utf8> namePtr = name.toNativeUtf8();
  167 +
  168 + final int found = SherpaOnnxBindings.speakerEmbeddingManagerContains
  169 + ?.call(ptr, namePtr) ??
  170 + 0;
  171 +
  172 + calloc.free(namePtr);
  173 +
  174 + return found == 1;
  175 + }
  176 +
  177 + bool remove(String name) {
  178 + final Pointer<Utf8> namePtr = name.toNativeUtf8();
  179 +
  180 + final int ok =
  181 + SherpaOnnxBindings.speakerEmbeddingManagerRemove?.call(ptr, namePtr) ??
  182 + 0;
  183 +
  184 + calloc.free(namePtr);
  185 +
  186 + return ok == 1;
  187 + }
  188 +
  189 + /// Return an empty string if no speaker is found
  190 + String search({required Float32List embedding, required double threshold}) {
  191 + assert(embedding.length == dim);
  192 +
  193 + final Pointer<Float> p = calloc<Float>(dim);
  194 + final pList = p.asTypedList(dim);
  195 + pList.setAll(0, embedding);
  196 +
  197 + final Pointer<Utf8> name = SherpaOnnxBindings.speakerEmbeddingManagerSearch
  198 + ?.call(ptr, p, threshold) ??
  199 + nullptr;
  200 +
  201 + calloc.free(p);
  202 +
  203 + if (name == nullptr) {
  204 + return '';
  205 + }
  206 +
  207 + final String ans = name.toDartString();
  208 +
  209 + SherpaOnnxBindings.speakerEmbeddingManagerFreeSearch?.call(name);
  210 +
  211 + return ans;
  212 + }
  213 +
  214 + bool verify(
  215 + {required String name,
  216 + required Float32List embedding,
  217 + required double threshold}) {
  218 + assert(embedding.length == dim);
  219 +
  220 + final Pointer<Utf8> namePtr = name.toNativeUtf8();
  221 +
  222 + final Pointer<Float> p = calloc<Float>(dim);
  223 + final pList = p.asTypedList(dim);
  224 + pList.setAll(0, embedding);
  225 +
  226 + final int ok = SherpaOnnxBindings.speakerEmbeddingManagerVerify
  227 + ?.call(ptr, namePtr, p, threshold) ??
  228 + 0;
  229 +
  230 + calloc.free(p);
  231 + calloc.free(namePtr);
  232 +
  233 + return ok == 1;
  234 + }
  235 +
  236 + int get numSpeakers =>
  237 + SherpaOnnxBindings.speakerEmbeddingManagerNumSpeakers?.call(ptr) ?? 0;
  238 +
  239 + List<String> get allSpeakerNames {
  240 + int n = numSpeakers;
  241 + if (n == 0) {
  242 + return <String>[];
  243 + }
  244 +
  245 + final Pointer<Pointer<Utf8>> names =
  246 + SherpaOnnxBindings.speakerEmbeddingManagerGetAllSpeakers?.call(ptr) ??
  247 + nullptr;
  248 +
  249 + if (names == nullptr) {
  250 + return <String>[];
  251 + }
  252 +
  253 + final ans = <String>[];
  254 +
  255 + // see https://api.flutter.dev/flutter/dart-ffi/PointerPointer.html
  256 + for (int i = 0; i != n; ++i) {
  257 + String name = names[i].toDartString();
  258 + ans.add(name);
  259 + }
  260 +
  261 + SherpaOnnxBindings.speakerEmbeddingManagerFreeAllSpeakers?.call(names);
  262 +
  263 + return ans;
  264 + }
  265 +
  266 + Pointer<SherpaOnnxSpeakerEmbeddingManager> ptr;
  267 + final int dim;
  268 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:ffi';
  3 +import 'dart:typed_data';
  4 +
  5 +import 'package:ffi/ffi.dart';
  6 +
  7 +import './sherpa_onnx_bindings.dart';
  8 +
  9 +class OfflineTtsVitsModelConfig {
  10 + const OfflineTtsVitsModelConfig({
  11 + required this.model,
  12 + this.lexicon = '',
  13 + required this.tokens,
  14 + this.dataDir = '',
  15 + this.noiseScale = 0.667,
  16 + this.noiseScaleW = 0.8,
  17 + this.lengthScale = 1.0,
  18 + this.dictDir = '',
  19 + });
  20 +
  21 + @override
  22 + String toString() {
  23 + return 'OfflineTtsVitsModelConfig(model: $model, lexicon: $lexicon, tokens: $tokens, dataDir: $dataDir, noiseScale: $noiseScale, noiseScaleW: $noiseScaleW, lengthScale: $lengthScale, dictDir: $dictDir)';
  24 + }
  25 +
  26 + final String model;
  27 + final String lexicon;
  28 + final String tokens;
  29 + final String dataDir;
  30 + final double noiseScale;
  31 + final double noiseScaleW;
  32 + final double lengthScale;
  33 + final String dictDir;
  34 +}
  35 +
  36 +class OfflineTtsModelConfig {
  37 + const OfflineTtsModelConfig({
  38 + required this.vits,
  39 + this.numThreads = 1,
  40 + this.debug = true,
  41 + this.provider = 'cpu',
  42 + });
  43 +
  44 + @override
  45 + String toString() {
  46 + return 'OfflineTtsModelConfig(vits: $vits, numThreads: $numThreads, debug: $debug, provider: $provider)';
  47 + }
  48 +
  49 + final OfflineTtsVitsModelConfig vits;
  50 + final int numThreads;
  51 + final bool debug;
  52 + final String provider;
  53 +}
  54 +
  55 +class OfflineTtsConfig {
  56 + const OfflineTtsConfig({
  57 + required this.model,
  58 + this.ruleFsts = '',
  59 + this.maxNumSenetences = 1,
  60 + this.ruleFars = '',
  61 + });
  62 +
  63 + @override
  64 + String toString() {
  65 + return 'OfflineTtsConfig(model: $model, ruleFsts: $ruleFsts, maxNumSenetences: $maxNumSenetences, ruleFars: $ruleFars)';
  66 + }
  67 +
  68 + final OfflineTtsModelConfig model;
  69 + final String ruleFsts;
  70 + final int maxNumSenetences;
  71 + final String ruleFars;
  72 +}
  73 +
  74 +class GeneratedAudio {
  75 + GeneratedAudio({
  76 + required this.samples,
  77 + required this.sampleRate,
  78 + });
  79 +
  80 + final Float32List samples;
  81 + final int sampleRate;
  82 +}
  83 +
  84 +class OfflineTts {
  85 + OfflineTts._({required this.ptr, required this.config});
  86 +
  87 + /// The user is responsible to call the OfflineTts.free()
  88 + /// method of the returned instance to avoid memory leak.
  89 + factory OfflineTts(OfflineTtsConfig config) {
  90 + final c = calloc<SherpaOnnxOfflineTtsConfig>();
  91 + c.ref.model.vits.model = config.model.vits.model.toNativeUtf8();
  92 + c.ref.model.vits.lexicon = config.model.vits.lexicon.toNativeUtf8();
  93 + c.ref.model.vits.tokens = config.model.vits.tokens.toNativeUtf8();
  94 + c.ref.model.vits.dataDir = config.model.vits.dataDir.toNativeUtf8();
  95 + c.ref.model.vits.noiseScale = config.model.vits.noiseScale;
  96 + c.ref.model.vits.noiseScaleW = config.model.vits.noiseScaleW;
  97 + c.ref.model.vits.lengthScale = config.model.vits.lengthScale;
  98 + c.ref.model.vits.dictDir = config.model.vits.dictDir.toNativeUtf8();
  99 +
  100 + c.ref.model.numThreads = config.model.numThreads;
  101 + c.ref.model.debug = config.model.debug ? 1 : 0;
  102 + c.ref.model.provider = config.model.provider.toNativeUtf8();
  103 +
  104 + c.ref.ruleFsts = config.ruleFsts.toNativeUtf8();
  105 + c.ref.maxNumSenetences = config.maxNumSenetences;
  106 + c.ref.ruleFars = config.ruleFars.toNativeUtf8();
  107 +
  108 + final ptr = SherpaOnnxBindings.createOfflineTts?.call(c) ?? nullptr;
  109 +
  110 + calloc.free(c.ref.ruleFars);
  111 + calloc.free(c.ref.ruleFsts);
  112 + calloc.free(c.ref.model.provider);
  113 + calloc.free(c.ref.model.vits.dictDir);
  114 + calloc.free(c.ref.model.vits.dataDir);
  115 + calloc.free(c.ref.model.vits.tokens);
  116 + calloc.free(c.ref.model.vits.lexicon);
  117 + calloc.free(c.ref.model.vits.model);
  118 +
  119 + return OfflineTts._(ptr: ptr, config: config);
  120 + }
  121 +
  122 + void free() {
  123 + SherpaOnnxBindings.destroyOfflineTts?.call(ptr);
  124 + ptr = nullptr;
  125 + }
  126 +
  127 + GeneratedAudio generate(
  128 + {required String text, int sid = 0, double speed = 1.0}) {
  129 + final Pointer<Utf8> textPtr = text.toNativeUtf8();
  130 + final p =
  131 + SherpaOnnxBindings.offlineTtsGenerate?.call(ptr, textPtr, sid, speed) ??
  132 + nullptr;
  133 + calloc.free(textPtr);
  134 +
  135 + if (p == nullptr) {
  136 + return GeneratedAudio(samples: Float32List(0), sampleRate: 0);
  137 + }
  138 +
  139 + final samples = p.ref.samples.asTypedList(p.ref.n);
  140 + final sampleRate = p.ref.sampleRate;
  141 + final newSamples = Float32List.fromList(samples);
  142 +
  143 + SherpaOnnxBindings.destroyOfflineTtsGeneratedAudio?.call(p);
  144 +
  145 + return GeneratedAudio(samples: newSamples, sampleRate: sampleRate);
  146 + }
  147 +
  148 + GeneratedAudio generateWithCallback(
  149 + {required String text,
  150 + int sid = 0,
  151 + double speed = 1.0,
  152 + required int Function(Float32List samples) callback}) {
  153 + // see
  154 + // https://github.com/dart-lang/sdk/issues/54276#issuecomment-1846109285
  155 + // https://stackoverflow.com/questions/69537440/callbacks-in-dart-dartffi-only-supports-calling-static-dart-functions-from-nat
  156 + // https://github.com/dart-lang/sdk/blob/main/tests/ffi/isolate_local_function_callbacks_test.dart#L46
  157 + final wrapper =
  158 + NativeCallable<SherpaOnnxGeneratedAudioCallbackNative>.isolateLocal(
  159 + (Pointer<Float> samples, int n) {
  160 + final s = samples.asTypedList(n);
  161 + final newSamples = Float32List.fromList(s);
  162 + return callback(newSamples);
  163 + }, exceptionalReturn: 0);
  164 +
  165 + final Pointer<Utf8> textPtr = text.toNativeUtf8();
  166 + final p = SherpaOnnxBindings.offlineTtsGenerateWithCallback
  167 + ?.call(ptr, textPtr, sid, speed, wrapper.nativeFunction) ??
  168 + nullptr;
  169 +
  170 + calloc.free(textPtr);
  171 + wrapper.close();
  172 +
  173 + if (p == nullptr) {
  174 + return GeneratedAudio(samples: Float32List(0), sampleRate: 0);
  175 + }
  176 +
  177 + final samples = p.ref.samples.asTypedList(p.ref.n);
  178 + final sampleRate = p.ref.sampleRate;
  179 + final newSamples = Float32List.fromList(samples);
  180 +
  181 + SherpaOnnxBindings.destroyOfflineTtsGeneratedAudio?.call(p);
  182 +
  183 + return GeneratedAudio(samples: newSamples, sampleRate: sampleRate);
  184 + }
  185 +
  186 + int get sampleRate => SherpaOnnxBindings.offlineTtsSampleRate?.call(ptr) ?? 0;
  187 +
  188 + int get numSpeakers =>
  189 + SherpaOnnxBindings.offlineTtsNumSpeakers?.call(ptr) ?? 0;
  190 +
  191 + Pointer<SherpaOnnxOfflineTts> ptr;
  192 + OfflineTtsConfig config;
  193 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:ffi';
  3 +import 'dart:typed_data';
  4 +import 'package:ffi/ffi.dart';
  5 +
  6 +import './sherpa_onnx_bindings.dart';
  7 +
  8 +class SileroVadModelConfig {
  9 + const SileroVadModelConfig(
  10 + {this.model = '',
  11 + this.threshold = 0.5,
  12 + this.minSilenceDuration = 0.5,
  13 + this.minSpeechDuration = 0.25,
  14 + this.windowSize = 512});
  15 +
  16 + @override
  17 + String toString() {
  18 + return 'SileroVadModelConfig(model: $model, threshold: $threshold, minSilenceDuration: $minSilenceDuration, minSpeechDuration: $minSpeechDuration, windowSize: $windowSize)';
  19 + }
  20 +
  21 + final String model;
  22 + final double threshold;
  23 + final double minSilenceDuration;
  24 + final double minSpeechDuration;
  25 + final int windowSize;
  26 +}
  27 +
  28 +class VadModelConfig {
  29 + VadModelConfig(
  30 + {this.sileroVad = const SileroVadModelConfig(),
  31 + this.sampleRate = 16000,
  32 + this.numThreads = 1,
  33 + this.provider = 'cpu',
  34 + this.debug = true});
  35 +
  36 + @override
  37 + String toString() {
  38 + return 'VadModelConfig(sileroVad: $sileroVad, sampleRate: $sampleRate, numThreads: $numThreads, provider: $provider, debug: $debug)';
  39 + }
  40 +
  41 + final SileroVadModelConfig sileroVad;
  42 + final int sampleRate;
  43 + final int numThreads;
  44 + final String provider;
  45 + final bool debug;
  46 +}
  47 +
  48 +class SpeechSegment {
  49 + SpeechSegment({required this.samples, required this.start});
  50 + final Float32List samples;
  51 + final int start;
  52 +}
  53 +
  54 +class CircularBuffer {
  55 + CircularBuffer._({required this.ptr});
  56 +
  57 + /// The user has to invoke CircularBuffer.free() on the returned instance
  58 + /// to avoid memory leak.
  59 + factory CircularBuffer({required int capacity}) {
  60 + assert(capacity > 0, 'capacity is $capacity');
  61 + final p =
  62 + SherpaOnnxBindings.createCircularBuffer?.call(capacity) ?? nullptr;
  63 +
  64 + return CircularBuffer._(ptr: p);
  65 + }
  66 +
  67 + void free() {
  68 + SherpaOnnxBindings.destroyCircularBuffer?.call(ptr);
  69 + ptr = nullptr;
  70 + }
  71 +
  72 + void push(Float32List data) {
  73 + final n = data.length;
  74 + final Pointer<Float> p = calloc<Float>(n);
  75 +
  76 + final pList = p.asTypedList(n);
  77 + pList.setAll(0, data);
  78 +
  79 + SherpaOnnxBindings.circularBufferPush?.call(ptr, p, n);
  80 +
  81 + calloc.free(p);
  82 + }
  83 +
  84 + Float32List get({required int startIndex, required int n}) {
  85 + final Pointer<Float> p =
  86 + SherpaOnnxBindings.circularBufferGet?.call(ptr, startIndex, n) ??
  87 + nullptr;
  88 +
  89 + if (p == nullptr) {
  90 + return Float32List(0);
  91 + }
  92 +
  93 + final pList = p.asTypedList(n);
  94 + final Float32List ans = Float32List.fromList(pList);
  95 +
  96 + SherpaOnnxBindings.circularBufferFree?.call(p);
  97 +
  98 + return ans;
  99 + }
  100 +
  101 + void pop(int n) {
  102 + SherpaOnnxBindings.circularBufferPop?.call(ptr, n);
  103 + }
  104 +
  105 + void reset() {
  106 + SherpaOnnxBindings.circularBufferReset?.call(ptr);
  107 + }
  108 +
  109 + int get size => SherpaOnnxBindings.circularBufferSize?.call(ptr) ?? 0;
  110 + int get head => SherpaOnnxBindings.circularBufferHead?.call(ptr) ?? 0;
  111 +
  112 + Pointer<SherpaOnnxCircularBuffer> ptr;
  113 +}
  114 +
  115 +class VoiceActivityDetector {
  116 + VoiceActivityDetector._({required this.ptr, required this.config});
  117 +
  118 + // The user has to invoke VoiceActivityDetector.free() to avoid memory leak.
  119 + factory VoiceActivityDetector(
  120 + {required VadModelConfig config, required double bufferSizeInSeconds}) {
  121 + final c = calloc<SherpaOnnxVadModelConfig>();
  122 +
  123 + final modelPtr = config.sileroVad.model.toNativeUtf8();
  124 + c.ref.sileroVad.model = modelPtr;
  125 +
  126 + c.ref.sileroVad.threshold = config.sileroVad.threshold;
  127 + c.ref.sileroVad.minSilenceDuration = config.sileroVad.minSilenceDuration;
  128 + c.ref.sileroVad.minSpeechDuration = config.sileroVad.minSpeechDuration;
  129 + c.ref.sileroVad.windowSize = config.sileroVad.windowSize;
  130 +
  131 + c.ref.sampleRate = config.sampleRate;
  132 + c.ref.numThreads = config.numThreads;
  133 +
  134 + final providerPtr = config.provider.toNativeUtf8();
  135 + c.ref.provider = providerPtr;
  136 +
  137 + c.ref.debug = config.debug ? 1 : 0;
  138 +
  139 + final ptr = SherpaOnnxBindings.createVoiceActivityDetector
  140 + ?.call(c, bufferSizeInSeconds) ??
  141 + nullptr;
  142 +
  143 + calloc.free(providerPtr);
  144 + calloc.free(modelPtr);
  145 + calloc.free(c);
  146 +
  147 + return VoiceActivityDetector._(ptr: ptr, config: config);
  148 + }
  149 +
  150 + void free() {
  151 + SherpaOnnxBindings.destroyVoiceActivityDetector?.call(ptr);
  152 + ptr = nullptr;
  153 + }
  154 +
  155 + void acceptWaveform(Float32List samples) {
  156 + final n = samples.length;
  157 + final Pointer<Float> p = calloc<Float>(n);
  158 +
  159 + final pList = p.asTypedList(n);
  160 + pList.setAll(0, samples);
  161 +
  162 + SherpaOnnxBindings.voiceActivityDetectorAcceptWaveform?.call(ptr, p, n);
  163 +
  164 + calloc.free(p);
  165 + }
  166 +
  167 + bool isEmpty() {
  168 + final int empty =
  169 + SherpaOnnxBindings.voiceActivityDetectorEmpty?.call(ptr) ?? 0;
  170 +
  171 + return empty == 1;
  172 + }
  173 +
  174 + bool isDetected() {
  175 + final int detected =
  176 + SherpaOnnxBindings.voiceActivityDetectorDetected?.call(ptr) ?? 0;
  177 +
  178 + return detected == 1;
  179 + }
  180 +
  181 + void pop() {
  182 + SherpaOnnxBindings.voiceActivityDetectorPop?.call(ptr);
  183 + }
  184 +
  185 + void clear() {
  186 + SherpaOnnxBindings.voiceActivityDetectorClear?.call(ptr);
  187 + }
  188 +
  189 + SpeechSegment front() {
  190 + final Pointer<SherpaOnnxSpeechSegment> segment =
  191 + SherpaOnnxBindings.voiceActivityDetectorFront?.call(ptr) ?? nullptr;
  192 + if (segment == nullptr) {
  193 + return SpeechSegment(samples: Float32List(0), start: 0);
  194 + }
  195 +
  196 + final sampleList = segment.ref.samples.asTypedList(segment.ref.n);
  197 + final start = segment.ref.start;
  198 +
  199 + final samples = Float32List.fromList(sampleList);
  200 +
  201 + SherpaOnnxBindings.destroySpeechSegment?.call(segment);
  202 +
  203 + return SpeechSegment(samples: samples, start: start);
  204 + }
  205 +
  206 + void reset() {
  207 + SherpaOnnxBindings.voiceActivityDetectorReset?.call(ptr);
  208 + }
  209 +
  210 + Pointer<SherpaOnnxVoiceActivityDetector> ptr;
  211 + final VadModelConfig config;
  212 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:ffi';
  3 +import 'dart:typed_data';
  4 +import 'package:ffi/ffi.dart';
  5 +
  6 +import './sherpa_onnx_bindings.dart';
  7 +
  8 +class WaveData {
  9 + WaveData({required this.samples, required this.sampleRate});
  10 +
  11 + /// normalized to [-1, 1]
  12 + Float32List samples;
  13 + int sampleRate;
  14 +}
  15 +
  16 +WaveData readWave(String filename) {
  17 + final Pointer<Utf8> str = filename.toNativeUtf8();
  18 + Pointer<SherpaOnnxWave> wave =
  19 + SherpaOnnxBindings.readWave?.call(str) ?? nullptr;
  20 + calloc.free(str);
  21 +
  22 + if (wave == nullptr) {
  23 + return WaveData(samples: Float32List(0), sampleRate: 0);
  24 + }
  25 +
  26 + final samples = wave.ref.samples.asTypedList(wave.ref.numSamples);
  27 +
  28 + final newSamples = Float32List.fromList(samples);
  29 + int sampleRate = wave.ref.sampleRate;
  30 + SherpaOnnxBindings.freeWave?.call(wave);
  31 +
  32 + return WaveData(samples: newSamples, sampleRate: sampleRate);
  33 +}
  1 +// Copyright (c) 2024 Xiaomi Corporation
  2 +import 'dart:ffi';
  3 +import 'dart:typed_data';
  4 +import 'package:ffi/ffi.dart';
  5 +
  6 +import './sherpa_onnx_bindings.dart';
  7 +
  8 +bool writeWave(
  9 + {required String filename,
  10 + required Float32List samples,
  11 + required int sampleRate}) {
  12 + final Pointer<Utf8> filenamePtr = filename.toNativeUtf8();
  13 +
  14 + final n = samples.length;
  15 + final Pointer<Float> p = calloc<Float>(n);
  16 +
  17 + final pList = p.asTypedList(n);
  18 + pList.setAll(0, samples);
  19 +
  20 + int ok =
  21 + SherpaOnnxBindings.writeWave?.call(p, n, sampleRate, filenamePtr) ?? 0;
  22 +
  23 + calloc.free(p);
  24 + calloc.free(filenamePtr);
  25 +
  26 + return ok == 1;
  27 +}
  1 +name: sherpa_onnx
  2 +
  3 +description: >
  4 + Speech recognition, speech synthesis, and speaker recognition using next-gen Kaldi
  5 + with onnxruntime without Internet connection.
  6 +
  7 +repository: https://github.com/k2-fsa/sherpa-onnx/tree/master/sherpa-onnx/flutter
  8 +
  9 +issue_tracker: https://github.com/k2-fsa/sherpa-onnx/issues
  10 +documentation: https://k2-fsa.github.io/sherpa/onnx/
  11 +
  12 +topics:
  13 + - speech-recognition
  14 + - speech-synthesis
  15 + - speaker-identification
  16 + - audio-tagging
  17 + - voice-activity-detection
  18 +
  19 +# remember to change the version in ../sherpa_onnx_macos/macos/sherpa_onnx.podspec
  20 +version: 1.10.7
  21 +
  22 +homepage: https://github.com/k2-fsa/sherpa-onnx
  23 +
  24 +environment:
  25 + sdk: '>=3.4.0 <4.0.0'
  26 + flutter: '>=3.3.0'
  27 +
  28 +dependencies:
  29 + ffi: ^2.1.0
  30 + flutter:
  31 + sdk: flutter
  32 +
  33 + sherpa_onnx_android:
  34 + # path: ../sherpa_onnx_android
  35 +
  36 + sherpa_onnx_macos:
  37 + # path: ../sherpa_onnx_macos
  38 +
  39 + sherpa_onnx_linux:
  40 + # path: ../sherpa_onnx_linux
  41 + #
  42 + sherpa_onnx_windows:
  43 + # path: ../sherpa_onnx_windows
  44 +
  45 +flutter:
  46 + plugin:
  47 + platforms:
  48 + android:
  49 + default_package: sherpa_onnx_android
  50 +
  51 + macos:
  52 + default_package: sherpa_onnx_macos
  53 +
  54 + linux:
  55 + default_package: sherpa_onnx_linux
  56 +
  57 + windows:
  58 + default_package: sherpa_onnx_windows
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
  26 +/pubspec.lock
  27 +**/doc/api/
  28 +.dart_tool/
  29 +build/
  1 +# This file tracks properties of this Flutter project.
  2 +# Used by Flutter tool to assess capabilities and perform upgrades etc.
  3 +#
  4 +# This file should be version controlled and should not be manually edited.
  5 +
  6 +version:
  7 + revision: "5dcb86f68f239346676ceb1ed1ea385bd215fba1"
  8 + channel: "stable"
  9 +
  10 +project_type: plugin_ffi
  11 +
  12 +# Tracks metadata for the flutter migrate command
  13 +migration:
  14 + platforms:
  15 + - platform: root
  16 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  17 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  18 + - platform: android
  19 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  20 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  21 +
  22 + # User provided section
  23 +
  24 + # List of Local paths (relative to this file) that should be
  25 + # ignored by the migrate tool.
  26 + #
  27 + # Files that are not part of the templates will be ignored by default.
  28 + unmanaged_files:
  29 + - 'lib/main.dart'
  30 + - 'ios/Runner.xcodeproj/project.pbxproj'
  1 +# sherpa_onnx_android
  2 +
  3 +This is a sub project of [sherpa-onnx](https://github.com/k2-fsa/sherpa-onnx).
  4 +
  5 +You are not expected to use this package directly.
  6 +
  7 +Please see the entry point at <https://pub.dev/packages/sherpa_onnx>.
  1 +include: package:flutter_lints/flutter.yaml
  2 +
  3 +# Additional information about this file can be found at
  4 +# https://dart.dev/guides/language/analysis-options
  1 +*.iml
  2 +.gradle
  3 +/local.properties
  4 +/.idea/workspace.xml
  5 +/.idea/libraries
  6 +.DS_Store
  7 +/build
  8 +/captures
  9 +.cxx
  1 +// The Android Gradle Plugin builds the native code with the Android NDK.
  2 +
  3 +group = "com.k2fsa.sherpa.onnx.sherpa_onnx_android"
  4 +version = "1.0"
  5 +
  6 +buildscript {
  7 + repositories {
  8 + google()
  9 + mavenCentral()
  10 + }
  11 +
  12 + dependencies {
  13 + // The Android Gradle Plugin knows how to build native code with the NDK.
  14 + classpath("com.android.tools.build:gradle:7.3.0")
  15 + }
  16 +}
  17 +
  18 +rootProject.allprojects {
  19 + repositories {
  20 + google()
  21 + mavenCentral()
  22 + }
  23 +}
  24 +
  25 +apply plugin: "com.android.library"
  26 +
  27 +android {
  28 + namespace 'com.k2fsa.sherpa.onnx'
  29 +
  30 + // Bumping the plugin compileSdk version requires all clients of this plugin
  31 + // to bump the version in their app.
  32 + compileSdk = 34
  33 +
  34 + // Use the NDK version
  35 + // declared in /android/app/build.gradle file of the Flutter project.
  36 + // Replace it with a version number if this plugin requires a specific NDK version.
  37 + // (e.g. ndkVersion "23.1.7779620")
  38 + ndkVersion = android.ndkVersion
  39 +
  40 + compileOptions {
  41 + sourceCompatibility = JavaVersion.VERSION_1_8
  42 + targetCompatibility = JavaVersion.VERSION_1_8
  43 + }
  44 +
  45 + defaultConfig {
  46 + minSdk = 21
  47 + }
  48 +}
  1 +rootProject.name = 'sherpa_onnx_android'
  1 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2 + package="com.k2fsa.sherpa.onnx">
  3 +</manifest>
  1 +# Introduction
  2 +
  3 +Pre-built libs are not checked-in.
  4 +
  5 +Please use
  6 +
  7 + - https://github.com/k2-fsa/sherpa-onnx/blob/master/build-android-arm64-v8a.sh
  8 + - https://github.com/k2-fsa/sherpa-onnx/blob/master/build-android-armv7-eabi.sh
  9 + - https://github.com/k2-fsa/sherpa-onnx/blob/master/build-android-x86-64.sh
  10 + - https://github.com/k2-fsa/sherpa-onnx/blob/master/build-android-x86.sh
  11 +
  12 +The following is an example for `arm64-v8a`:
  13 +
  14 +```bash
  15 +git clone https://github.com/k2-fsa/sherpa-onnx
  16 +cd sherpa-onnx
  17 +
  18 +export SHERPA_ONNX_ENABLE_JNI=OFF
  19 +export SHERPA_ONNX_ENABLE_C_API=ON
  20 +./build-android-arm64-v8a.sh
  21 +
  22 +cp -v build-android-arm64-v8a/install/lib/*.so flutter/sherpa_onnx_android/android/src/main/jniLibs/arm64-v8a/
  23 +```
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +**/doc/api/
  26 +**/ios/Flutter/.last_build_id
  27 +.dart_tool/
  28 +.flutter-plugins
  29 +.flutter-plugins-dependencies
  30 +.pub-cache/
  31 +.pub/
  32 +/build/
  33 +
  34 +# Symbolication related
  35 +app.*.symbols
  36 +
  37 +# Obfuscation related
  38 +app.*.map.json
  39 +
  40 +# Android Studio will place build artifacts here
  41 +/android/app/debug
  42 +/android/app/profile
  43 +/android/app/release
  1 +# Introduction
  2 +
  3 +Please find examples at
  4 +
  5 +https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples
  6 +
  7 +and
  8 +
  9 +https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples
  1 +# sherpa-onnx app example
  2 +
  3 +## Streaming speech recognition
  4 +
  5 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/streaming-asr
  6 +
  7 +## Non-streaming speech recognition
  8 +
  9 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/non-streaming-asr
  10 +
  11 +## Text to speech (TTS)
  12 +
  13 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/tts
  14 +
  15 +## Voice activity detection (VAD)
  16 +
  17 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/vad
  18 +
  1 +name: sherpa_onnx_android
  2 +description: "A new Flutter FFI plugin project."
  3 +version: 0.0.1
  4 +homepage:
  5 +
  6 +environment:
  7 + sdk: '>=3.4.0 <4.0.0'
  8 + flutter: '>=3.3.0'
  9 +
  10 +dependencies:
  11 + flutter:
  12 + sdk: flutter
  13 +
  14 +flutter:
  15 + plugin:
  16 + platforms:
  17 + android:
  18 + ffiPlugin: true
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
  26 +/pubspec.lock
  27 +**/doc/api/
  28 +.dart_tool/
  29 +build/
  1 +# This file tracks properties of this Flutter project.
  2 +# Used by Flutter tool to assess capabilities and perform upgrades etc.
  3 +#
  4 +# This file should be version controlled and should not be manually edited.
  5 +
  6 +version:
  7 + revision: "5dcb86f68f239346676ceb1ed1ea385bd215fba1"
  8 + channel: "stable"
  9 +
  10 +project_type: plugin_ffi
  11 +
  12 +# Tracks metadata for the flutter migrate command
  13 +migration:
  14 + platforms:
  15 + - platform: root
  16 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  17 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  18 + - platform: linux
  19 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  20 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  21 +
  22 + # User provided section
  23 +
  24 + # List of Local paths (relative to this file) that should be
  25 + # ignored by the migrate tool.
  26 + #
  27 + # Files that are not part of the templates will be ignored by default.
  28 + unmanaged_files:
  29 + - 'lib/main.dart'
  30 + - 'ios/Runner.xcodeproj/project.pbxproj'
  1 +# sherpa_onnx_linux
  2 +
  3 +This is a sub project of [sherpa-onnx](https://github.com/k2-fsa/sherpa-onnx).
  4 +
  5 +You are not expected to use this package directly.
  6 +
  7 +Please see the entry point at <https://pub.dev/packages/sherpa_onnx>.
  1 +include: package:flutter_lints/flutter.yaml
  2 +
  3 +# Additional information about this file can be found at
  4 +# https://dart.dev/guides/language/analysis-options
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +**/doc/api/
  26 +**/ios/Flutter/.last_build_id
  27 +.dart_tool/
  28 +.flutter-plugins
  29 +.flutter-plugins-dependencies
  30 +.pub-cache/
  31 +.pub/
  32 +/build/
  33 +
  34 +# Symbolication related
  35 +app.*.symbols
  36 +
  37 +# Obfuscation related
  38 +app.*.map.json
  39 +
  40 +# Android Studio will place build artifacts here
  41 +/android/app/debug
  42 +/android/app/profile
  43 +/android/app/release
  1 +# Introduction
  2 +
  3 +Please find examples at
  4 +
  5 +https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples
  6 +
  7 +and
  8 +
  9 +https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples
  1 +# sherpa-onnx app example
  2 +
  3 +## Streaming speech recognition
  4 +
  5 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/streaming-asr
  6 +
  7 +## Non-streaming speech recognition
  8 +
  9 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/non-streaming-asr
  10 +
  11 +## Text to speech (TTS)
  12 +
  13 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/tts
  14 +
  15 +## Voice activity detection (VAD)
  16 +
  17 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/vad
  18 +
  1 +# The Flutter tooling requires that developers have CMake 3.10 or later
  2 +# installed. You should not increase this version, as doing so will cause
  3 +# the plugin to fail to compile for some customers of the plugin.
  4 +cmake_minimum_required(VERSION 3.10)
  5 +
  6 +# Project-level configuration.
  7 +set(PROJECT_NAME "sherpa_onnx_linux")
  8 +project(${PROJECT_NAME} LANGUAGES CXX)
  9 +
  10 +# List of absolute paths to libraries that should be bundled with the plugin.
  11 +# This list could contain prebuilt libraries, or libraries created by an
  12 +# external build triggered from this build file.
  13 +set(sherpa_onnx_linux_bundled_libraries
  14 + "${CMAKE_CURRENT_SOURCE_DIR}/libsherpa-onnx-c-api.so"
  15 + "${CMAKE_CURRENT_SOURCE_DIR}/libsherpa-onnx-core.so"
  16 + "${CMAKE_CURRENT_SOURCE_DIR}/libkaldi-decoder-core.so"
  17 + "${CMAKE_CURRENT_SOURCE_DIR}/libsherpa-onnx-kaldifst-core.so"
  18 + "${CMAKE_CURRENT_SOURCE_DIR}/libsherpa-onnx-fstfar.so"
  19 + "${CMAKE_CURRENT_SOURCE_DIR}/libsherpa-onnx-fst.so"
  20 + "${CMAKE_CURRENT_SOURCE_DIR}/libkaldi-native-fbank-core.so"
  21 + "${CMAKE_CURRENT_SOURCE_DIR}/libpiper_phonemize.so"
  22 + "${CMAKE_CURRENT_SOURCE_DIR}/libespeak-ng.so"
  23 + "${CMAKE_CURRENT_SOURCE_DIR}/libucd.so"
  24 + "${CMAKE_CURRENT_SOURCE_DIR}/libonnxruntime.so"
  25 + "${CMAKE_CURRENT_SOURCE_DIR}/libssentencepiece_core.so"
  26 + PARENT_SCOPE
  27 +)
  1 +# Introduction
  2 +
  3 +`*.so` files are generated dynamically using GitHub actions during a new release.
  4 +
  5 +We don't check-in pre-built library files into git.
  1 +name: sherpa_onnx_linux
  2 +description: "A new Flutter FFI plugin project."
  3 +version: 0.0.1
  4 +homepage:
  5 +
  6 +environment:
  7 + sdk: '>=3.4.0 <4.0.0'
  8 + flutter: '>=3.3.0'
  9 +
  10 +dependencies:
  11 + flutter:
  12 + sdk: flutter
  13 +
  14 +flutter:
  15 + plugin:
  16 + platforms:
  17 + linux:
  18 + ffiPlugin: true
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
  26 +/pubspec.lock
  27 +**/doc/api/
  28 +.dart_tool/
  29 +build/
  1 +# This file tracks properties of this Flutter project.
  2 +# Used by Flutter tool to assess capabilities and perform upgrades etc.
  3 +#
  4 +# This file should be version controlled and should not be manually edited.
  5 +
  6 +version:
  7 + revision: "5dcb86f68f239346676ceb1ed1ea385bd215fba1"
  8 + channel: "stable"
  9 +
  10 +project_type: plugin_ffi
  11 +
  12 +# Tracks metadata for the flutter migrate command
  13 +migration:
  14 + platforms:
  15 + - platform: root
  16 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  17 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  18 + - platform: macos
  19 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  20 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  21 +
  22 + # User provided section
  23 +
  24 + # List of Local paths (relative to this file) that should be
  25 + # ignored by the migrate tool.
  26 + #
  27 + # Files that are not part of the templates will be ignored by default.
  28 + unmanaged_files:
  29 + - 'lib/main.dart'
  30 + - 'ios/Runner.xcodeproj/project.pbxproj'
  1 +# sherpa_onnx_linux
  2 +
  3 +This is a sub project of [sherpa-onnx](https://github.com/k2-fsa/sherpa-onnx).
  4 +
  5 +You are not expected to use this package directly.
  6 +
  7 +Please see the entry point at <https://pub.dev/packages/sherpa_onnx>.
  1 +include: package:flutter_lints/flutter.yaml
  2 +
  3 +# Additional information about this file can be found at
  4 +# https://dart.dev/guides/language/analysis-options
  1 +# Introduction
  2 +
  3 +Please find examples at
  4 +
  5 +https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples
  6 +
  7 +and
  8 +
  9 +https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples
  1 +# sherpa-onnx app example
  2 +
  3 +## Streaming speech recognition
  4 +
  5 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/streaming-asr
  6 +
  7 +## Non-streaming speech recognition
  8 +
  9 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/non-streaming-asr
  10 +
  11 +## Text to speech (TTS)
  12 +
  13 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/tts
  14 +
  15 +## Voice activity detection (VAD)
  16 +
  17 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/vad
  18 +
  1 +# Introduction
  2 +
  3 +`*.dylib` files are generated dynamically using GitHub actions during a new release.
  4 +
  5 +We don't check-in pre-built library files into git.
  1 +#
  2 +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
  3 +# Run `pod lib lint sherpa_onnx_macos.podspec` to validate before publishing.
  4 +#
  5 +Pod::Spec.new do |s|
  6 + s.name = 'sherpa_onnx_macos'
  7 + s.version = '1.10.6'
  8 + s.summary = 'sherpa-onnx Flutter FFI plugin project.'
  9 + s.description = <<-DESC
  10 +sherpa-onnx Flutter FFI plugin project.
  11 + DESC
  12 + s.homepage = 'https://github.com/k2-fsa/sherpa-onnx'
  13 + s.license = { :file => '../LICENSE' }
  14 + s.author = { 'Fangjun Kuang' => 'csukuangfj@gmail.com' }
  15 +
  16 + # This will ensure the source files in Classes/ are included in the native
  17 + # builds of apps using this FFI plugin. Podspec does not support relative
  18 + # paths, so Classes contains a forwarder C file that relatively imports
  19 + # `../src/*` so that the C sources can be shared among all target platforms.
  20 + s.source = { :path => '.' }
  21 + s.dependency 'FlutterMacOS'
  22 + s.vendored_libraries = '*.dylib'
  23 +
  24 + s.platform = :osx, '10.11'
  25 + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
  26 + s.swift_version = '5.0'
  27 +end
  1 +name: sherpa_onnx_macos
  2 +description: "A new Flutter FFI plugin project."
  3 +version: 0.0.1
  4 +homepage:
  5 +
  6 +environment:
  7 + sdk: '>=3.4.0 <4.0.0'
  8 + flutter: '>=3.3.0'
  9 +
  10 +dependencies:
  11 + flutter:
  12 + sdk: flutter
  13 +
  14 +flutter:
  15 + plugin:
  16 + platforms:
  17 + macos:
  18 + ffiPlugin: true
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
  26 +/pubspec.lock
  27 +**/doc/api/
  28 +.dart_tool/
  29 +build/
  1 +# This file tracks properties of this Flutter project.
  2 +# Used by Flutter tool to assess capabilities and perform upgrades etc.
  3 +#
  4 +# This file should be version controlled and should not be manually edited.
  5 +
  6 +version:
  7 + revision: "5dcb86f68f239346676ceb1ed1ea385bd215fba1"
  8 + channel: "stable"
  9 +
  10 +project_type: plugin_ffi
  11 +
  12 +# Tracks metadata for the flutter migrate command
  13 +migration:
  14 + platforms:
  15 + - platform: root
  16 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  17 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  18 + - platform: windows
  19 + create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  20 + base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
  21 +
  22 + # User provided section
  23 +
  24 + # List of Local paths (relative to this file) that should be
  25 + # ignored by the migrate tool.
  26 + #
  27 + # Files that are not part of the templates will be ignored by default.
  28 + unmanaged_files:
  29 + - 'lib/main.dart'
  30 + - 'ios/Runner.xcodeproj/project.pbxproj'
  1 +# sherpa_onnx_linux
  2 +
  3 +This is a sub project of [sherpa-onnx](https://github.com/k2-fsa/sherpa-onnx).
  4 +
  5 +You are not expected to use this package directly.
  6 +
  7 +Please see the entry point at <https://pub.dev/packages/sherpa_onnx>.
  1 +include: package:flutter_lints/flutter.yaml
  2 +
  3 +# Additional information about this file can be found at
  4 +# https://dart.dev/guides/language/analysis-options
  1 +# Miscellaneous
  2 +*.class
  3 +*.log
  4 +*.pyc
  5 +*.swp
  6 +.DS_Store
  7 +.atom/
  8 +.buildlog/
  9 +.history
  10 +.svn/
  11 +migrate_working_dir/
  12 +
  13 +# IntelliJ related
  14 +*.iml
  15 +*.ipr
  16 +*.iws
  17 +.idea/
  18 +
  19 +# The .vscode folder contains launch configuration and tasks you configure in
  20 +# VS Code which you may wish to be included in version control, so this line
  21 +# is commented out by default.
  22 +#.vscode/
  23 +
  24 +# Flutter/Dart/Pub related
  25 +**/doc/api/
  26 +**/ios/Flutter/.last_build_id
  27 +.dart_tool/
  28 +.flutter-plugins
  29 +.flutter-plugins-dependencies
  30 +.pub-cache/
  31 +.pub/
  32 +/build/
  33 +
  34 +# Symbolication related
  35 +app.*.symbols
  36 +
  37 +# Obfuscation related
  38 +app.*.map.json
  39 +
  40 +# Android Studio will place build artifacts here
  41 +/android/app/debug
  42 +/android/app/profile
  43 +/android/app/release
  1 +# Introduction
  2 +
  3 +Please find examples at
  4 +
  5 +https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples
  6 +
  7 +and
  8 +
  9 +https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples
  1 +# sherpa-onnx app example
  2 +
  3 +## Streaming speech recognition
  4 +
  5 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/streaming-asr
  6 +
  7 +## Non-streaming speech recognition
  8 +
  9 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/non-streaming-asr
  10 +
  11 +## Text to speech (TTS)
  12 +
  13 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/tts
  14 +
  15 +## Voice activity detection (VAD)
  16 +
  17 +Please see https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/vad
  18 +