Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor flutter to support Android #1072

Merged
merged 58 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8be2ddb
commit after creating sherpa_onnx without any modifications
csukuangfj Jul 3, 2024
0896a20
add LINCESE
csukuangfj Jul 3, 2024
c6570a1
remove example and test files
csukuangfj Jul 3, 2024
e621604
update pubspect.yaml
csukuangfj Jul 3, 2024
335302e
remove files in lib/
csukuangfj Jul 3, 2024
8db5a6e
add files to lib/
csukuangfj Jul 3, 2024
78cf1c5
update example readme
csukuangfj Jul 3, 2024
403e17d
add sherpa_onnx_macos after creating it without any changes
csukuangfj Jul 3, 2024
83da905
remove extra files
csukuangfj Jul 3, 2024
bbdb7ad
update podspec for macos in sherpa_onnx_macos
csukuangfj Jul 3, 2024
4ea0708
fix CI for dart api
csukuangfj Jul 3, 2024
c53ab47
refactor dart CI
csukuangfj Jul 3, 2024
04c4bc2
add sherpa_onnx_linux without any changes
csukuangfj Jul 3, 2024
4c41a8b
remove examples
csukuangfj Jul 3, 2024
b9d312c
add example descriptions
csukuangfj Jul 3, 2024
aebe088
remove extra .c and .h files
csukuangfj Jul 3, 2024
1ca81bf
Update test-dart.yaml
csukuangfj Jul 3, 2024
41432ca
Update init.dart
csukuangfj Jul 3, 2024
6094d8c
Merge remote-tracking branch 'origin/refactor-flutter' into refactor-…
csukuangfj Jul 3, 2024
f783f16
Update Linux CMakeLists.txt
csukuangfj Jul 3, 2024
ca7c025
test also ubuntu in CI
csukuangfj Jul 3, 2024
0fb660b
update pubspec
csukuangfj Jul 3, 2024
6fb5943
add sherpa_onnx_windows after creation without any changes
csukuangfj Jul 3, 2024
568824b
remove examples
csukuangfj Jul 3, 2024
31dac60
remove lib files
csukuangfj Jul 3, 2024
fe45cc4
remove src files
csukuangfj Jul 3, 2024
9f9b2f6
remove src
csukuangfj Jul 3, 2024
128e822
update windows CMakeLists.txt
csukuangfj Jul 3, 2024
0fcc6c7
update windows pubspec
csukuangfj Jul 3, 2024
f09c4a6
remove linux src
csukuangfj Jul 3, 2024
b5819d1
remove linux lib
csukuangfj Jul 3, 2024
7c20d2b
update linux cmakelists.txt
csukuangfj Jul 3, 2024
c128585
Update pubspec for CI
csukuangfj Jul 3, 2024
c349904
remove macos lib files
csukuangfj Jul 3, 2024
be1d923
add ci for windows
csukuangfj Jul 3, 2024
7644935
fix typos in CI
csukuangfj Jul 3, 2024
2e926c4
minor fixes
csukuangfj Jul 3, 2024
ff2deae
fix CI erros by adding a dummy file to lib
csukuangfj Jul 3, 2024
ba97717
Add README for lib files
csukuangfj Jul 3, 2024
b734373
remove unused files
csukuangfj Jul 3, 2024
e5e7f1c
Fix CI for windows
csukuangfj Jul 3, 2024
da83d87
add android after creation without any changes
csukuangfj Jul 3, 2024
69476cc
remove lib files for android
csukuangfj Jul 3, 2024
959181d
add a dummy file to lib
csukuangfj Jul 3, 2024
ea6e8f4
remove src for android
csukuangfj Jul 3, 2024
69c6436
update android build.gradle
csukuangfj Jul 3, 2024
8144118
update AndroidManifest.xml
csukuangfj Jul 3, 2024
2ec31ce
add jniLibs
csukuangfj Jul 3, 2024
2094976
remove android examples
csukuangfj Jul 3, 2024
cd10408
remove extra comments from pubspec for android
csukuangfj Jul 3, 2024
ba4e3c7
support android in pubspec
csukuangfj Jul 3, 2024
ce65a50
add android examples
csukuangfj Jul 3, 2024
2914c98
use minSdk 23 as required by recording package
csukuangfj Jul 3, 2024
33d8b69
fix settings.gradle as required by the recording package
csukuangfj Jul 3, 2024
aece777
Add android example for streaming asr
csukuangfj Jul 3, 2024
a5ce457
remove unused files
csukuangfj Jul 3, 2024
17c2c0f
fix android building scripts
csukuangfj Jul 3, 2024
6f90ab3
fix typos
csukuangfj Jul 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/test-dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ on:
- '.github/workflows/test-dart.yaml'
- '.github/scripts/test-dart.sh'
- 'dart-api-examples/**'
- 'flutter/**'
pull_request:
branches:
- master
paths:
- '.github/workflows/test-dart.yaml'
- '.github/scripts/test-dart.sh'
- 'dart-api-examples/**'
- 'flutter/**'

workflow_dispatch:

Expand All @@ -29,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest] #, windows-latest]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -75,16 +77,29 @@ jobs:
-DSHERPA_ONNX_ENABLE_BINARY=OFF \
-DCMAKE_INSTALL_PREFIX=./install \
..
make -j install

cmake --build . --target install --config Release

- name: Copy libs
shell: bash
run: |
cp -v build/install/lib/lib* ./sherpa-onnx/flutter/linux/
if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
os=linux
elif [[ ${{ matrix.os }} == macos-latest ]]; then
os=macos
elif [[ ${{ matrix.os }} == windows-latest ]]; then
os=windows
fi

if [[ $os == windows ]]; then
cp -fv build/install/lib/*.dll ./flutter/sherpa_onnx_$os/$os
else
cp -fv build/install/lib/lib* ./flutter/sherpa_onnx_$os/$os
fi

echo "--------------------"

ls -lh ./sherpa-onnx/flutter/linux/
ls -lh ./flutter/sherpa_onnx_$os/$os

- name: Run tests
shell: bash
Expand All @@ -93,5 +108,6 @@ jobs:
cp scripts/dart/non-streaming-asr-pubspec.yaml dart-api-examples/non-streaming-asr/pubspec.yaml
cp scripts/dart/streaming-asr-pubspec.yaml dart-api-examples/streaming-asr/pubspec.yaml
cp scripts/dart/tts-pubspec.yaml dart-api-examples/tts/pubspec.yaml
cp scripts/dart/sherpa-onnx-pubspec.yaml flutter/sherpa_onnx/pubspec.yaml

.github/scripts/test-dart.sh
12 changes: 10 additions & 2 deletions build-android-arm64-v8a.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
SHERPA_ONNX_ENABLE_BINARY=OFF
fi

if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
SHERPA_ONNX_ENABLE_C_API=OFF
fi

if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
SHERPA_ONNX_ENABLE_JNI=ON
fi

cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
-DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
-DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
Expand All @@ -80,8 +88,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
-DSHERPA_ONNX_ENABLE_JNI=ON \
-DSHERPA_ONNX_ENABLE_C_API=OFF \
-DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
-DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
-DCMAKE_INSTALL_PREFIX=./install \
-DANDROID_ABI="arm64-v8a" \
-DANDROID_PLATFORM=android-21 ..
Expand Down
12 changes: 10 additions & 2 deletions build-android-armv7-eabi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
SHERPA_ONNX_ENABLE_BINARY=OFF
fi

if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
SHERPA_ONNX_ENABLE_C_API=OFF
fi

if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
SHERPA_ONNX_ENABLE_JNI=ON
fi

cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
-DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
-DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
Expand All @@ -81,8 +89,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
-DSHERPA_ONNX_ENABLE_JNI=ON \
-DSHERPA_ONNX_ENABLE_C_API=OFF \
-DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
-DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
-DCMAKE_INSTALL_PREFIX=./install \
-DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON \
-DANDROID_PLATFORM=android-21 ..
Expand Down
12 changes: 10 additions & 2 deletions build-android-x86-64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
SHERPA_ONNX_ENABLE_BINARY=OFF
fi

if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
SHERPA_ONNX_ENABLE_C_API=OFF
fi

if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
SHERPA_ONNX_ENABLE_JNI=ON
fi

cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
-DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
-DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
Expand All @@ -81,10 +89,10 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
-DSHERPA_ONNX_ENABLE_JNI=ON \
-DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
-DCMAKE_INSTALL_PREFIX=./install \
-DANDROID_ABI="x86_64" \
-DSHERPA_ONNX_ENABLE_C_API=OFF \
-DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
-DANDROID_PLATFORM=android-21 ..

Expand Down
12 changes: 10 additions & 2 deletions build-android-x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ if [ -z $SHERPA_ONNX_ENABLE_BINARY ]; then
SHERPA_ONNX_ENABLE_BINARY=OFF
fi

if [ -z $SHERPA_ONNX_ENABLE_C_API ]; then
SHERPA_ONNX_ENABLE_C_API=OFF
fi

if [ -z $SHERPA_ONNX_ENABLE_JNI ]; then
SHERPA_ONNX_ENABLE_JNI=ON
fi

cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
-DSHERPA_ONNX_ENABLE_TTS=$SHERPA_ONNX_ENABLE_TTS \
-DSHERPA_ONNX_ENABLE_BINARY=$SHERPA_ONNX_ENABLE_BINARY \
Expand All @@ -81,10 +89,10 @@ cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
-DSHERPA_ONNX_ENABLE_JNI=ON \
-DSHERPA_ONNX_ENABLE_JNI=$SHERPA_ONNX_ENABLE_JNI \
-DCMAKE_INSTALL_PREFIX=./install \
-DANDROID_ABI="x86" \
-DSHERPA_ONNX_ENABLE_C_API=OFF \
-DSHERPA_ONNX_ENABLE_C_API=$SHERPA_ONNX_ENABLE_C_API \
-DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \
-DANDROID_PLATFORM=android-21 ..

Expand Down
16 changes: 8 additions & 8 deletions dart-api-examples/vad/bin/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import 'package:path/path.dart' as p;
import 'package:sherpa_onnx/sherpa_onnx.dart' as sherpa_onnx;

Future<void> initSherpaOnnx() async {
var uri = await Isolate.resolvePackageUri(
Uri.parse('package:sherpa_onnx/sherpa_onnx.dart'));

if (uri == null) {
print('File not found');
exit(1);
}

String platform = '';

if (Platform.isMacOS) {
Expand All @@ -25,6 +17,14 @@ Future<void> initSherpaOnnx() async {
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}

var uri = await Isolate.resolvePackageUri(
Uri.parse('package:sherpa_onnx_$platform/any_path_is_ok_here.dart'));

if (uri == null) {
print('File not found');
exit(1);
}

final libPath = p.join(p.dirname(p.fromUri(uri)), '..', platform);
sherpa_onnx.initBindings(libPath);
}
138 changes: 138 additions & 0 deletions flutter-examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Do not remove or rename entries in this file, only add new ones
# See https://github.com/flutter/flutter/issues/128635 for more context.

# Miscellaneous
*.class
*.lock
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.classpath
.project
.settings/
.vscode/*

# Flutter repo-specific
/bin/cache/
/bin/internal/bootstrap.bat
/bin/internal/bootstrap.sh
/bin/mingit/
/dev/benchmarks/mega_gallery/
/dev/bots/.recipe_deps
/dev/bots/android_tools/
/dev/devicelab/ABresults*.json
/dev/docs/doc/
/dev/docs/api_docs.zip
/dev/docs/flutter.docs.zip
/dev/docs/lib/
/dev/docs/pubspec.yaml
/dev/integration_tests/**/xcuserdata
/dev/integration_tests/**/Pods
/packages/flutter/coverage/
version
analysis_benchmark.json

# packages file containing multi-root paths
.packages.generated

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
**/generated_plugin_registrant.dart
.packages
.pub-preload-cache/
.pub-cache/
.pub/
build/
flutter_*.png
linked_*.ds
unlinked.ds
unlinked_spec.ds

# Android related
**/android/**/gradle-wrapper.jar
.gradle/
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
**/android/key.properties
*.jks

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/.last_build_id
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/ephemeral
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# macOS
**/Flutter/ephemeral/
**/Pods/
**/macos/Flutter/GeneratedPluginRegistrant.swift
**/macos/Flutter/ephemeral
**/xcuserdata/

# Windows
**/windows/flutter/generated_plugin_registrant.cc
**/windows/flutter/generated_plugin_registrant.h
**/windows/flutter/generated_plugins.cmake

# Linux
**/linux/flutter/generated_plugin_registrant.cc
**/linux/flutter/generated_plugin_registrant.h
**/linux/flutter/generated_plugins.cmake

# Coverage
coverage/

# Symbols
app.*.symbols

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
!/dev/ci/**/Gemfile.lock
!.vscode/settings.json
Loading