Skip to content

Commit

Permalink
Add VAD example for Dart API (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jun 14, 2024
1 parent c214d8f commit d08cc04
Show file tree
Hide file tree
Showing 33 changed files with 883 additions and 142 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build-wheels-macos-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
path: ./wheelhouse/*.whl

- name: Publish to huggingface
if: matrix.python-version == 'cp38'
if: matrix.python-version == 'cp39'
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v3
Expand Down Expand Up @@ -82,7 +82,13 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 -m pip install --break-system-packages --upgrade pip
python3 -m pip install --break-system-packages wheel twine setuptools
opts='--break-system-packages'
v=${{ matrix.python-version }}
if [[ $v == cp38 || $v == cp39 ]]; then
opts=''
fi
python3 -m pip install $opts --upgrade pip
python3 -m pip install $opts wheel twine setuptools
twine upload ./wheelhouse/*.whl
2 changes: 1 addition & 1 deletion .github/workflows/build-wheels-macos-universal2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
path: ./wheelhouse/*.whl

- name: Publish to huggingface
if: matrix.python-version == 'cp38'
if: matrix.python-version == 'cp39'
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v3
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/build-wheels-macos-x64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
path: ./wheelhouse/*.whl

- name: Publish to huggingface
if: matrix.python-version == 'cp38'
if: matrix.python-version == 'cp39'
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v3
Expand Down Expand Up @@ -99,7 +99,13 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 -m pip install --break-system-packages --upgrade pip
python3 -m pip install --break-system-packages wheel twine setuptools
opts='--break-system-packages'
v=${{ matrix.python-version }}
if [[ $v == cp38 || $v == cp39 ]]; then
opts=''
fi
python3 -m pip install $opts --upgrade pip
python3 -m pip install $opts wheel twine setuptools
twine upload ./wheelhouse/*.whl
48 changes: 40 additions & 8 deletions .github/workflows/flutter-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ jobs:
- name: Build flutter
shell: bash
run: |
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
d=$PWD
pushd sherpa-onnx/flutter
Expand All @@ -166,7 +168,7 @@ jobs:
tree ./sherpa_onnx.app
app=flutter_sherpa_onnx_macos_${{ matrix.arch }}.app
app=sherpa-onnx-osx-${{ matrix.arch }}-$SHERPA_ONNX_VERSION.app
mv sherpa_onnx.app $app
tar cjfv $app.tar.bz2 $app
ls -lh
Expand All @@ -178,13 +180,43 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: flutter-sherpa-onnx-app-macos-${{ matrix.arch }}
name: sherpa-onnx-osx-${{ matrix.arch }}
path: ./*.tar.bz2

- name: Release android libs
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
- name: Publish to huggingface
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v3
with:
file_glob: true
overwrite: true
file: flutter*.tar.bz2
max_attempts: 20
timeout_seconds: 200
shell: bash
command: |
git config --global user.email "csukuangfj@gmail.com"
git config --global user.name "Fangjun Kuang"
rm -rf huggingface
export GIT_LFS_SKIP_SMUDGE=1
export GIT_CLONE_PROTECTION_ACTIVE=false
git clone https://huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface
cd huggingface
git fetch
git pull
git merge -m "merge remote" --ff origin main
mkdir -p flutter
cp -v ../*.tar.bz2 ./flutter
git status
git lfs track "*.bz2"
git add .
git commit -m "add more files"
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-flutter main
# - name: Release android libs
# if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
# uses: svenstaro/upload-release-action@v2
# with:
# file_glob: true
# overwrite: true
# file: sherpa*.tar.bz2
46 changes: 38 additions & 8 deletions .github/workflows/flutter-windows-x64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
cd build/windows/x64/runner/
dst=flutter_sherpa_onnx_windows_x64
dst=sherpa-onnx-win-x64-$SHERPA_ONNX_VERSION
mv Release $dst
tar cjfv $dst.tar.bz2 ./$dst
Expand All @@ -155,13 +155,43 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: flutter-sherpa-onnx-windows-x64
name: sherpa-onnx-win-x64
path: ./*.tar.bz2

- name: Release android libs
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
- name: Publish to huggingface
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v3
with:
file_glob: true
overwrite: true
file: flutter*.tar.bz2
max_attempts: 20
timeout_seconds: 200
shell: bash
command: |
git config --global user.email "csukuangfj@gmail.com"
git config --global user.name "Fangjun Kuang"
rm -rf huggingface
export GIT_LFS_SKIP_SMUDGE=1
export GIT_CLONE_PROTECTION_ACTIVE=false
git clone https://huggingface.co/csukuangfj/sherpa-onnx-flutter huggingface
cd huggingface
git fetch
git pull
git merge -m "merge remote" --ff origin main
mkdir -p flutter
cp -v ../*.tar.bz2 ./flutter
git status
git lfs track "*.bz2"
git add .
git commit -m "add more files"
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-flutter main
# - name: Release android libs
# if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
# uses: svenstaro/upload-release-action@v2
# with:
# file_glob: true
# overwrite: true
# file: sherpa*.tar.bz2
60 changes: 60 additions & 0 deletions .github/workflows/test-dart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: test-dart

on:
push:
branches:
- master
paths:
- '.github/workflows/test-dart.yaml'
- 'dart-api-examples/**'
pull_request:
branches:
- master
paths:
- '.github/workflows/test-dart.yaml'
- 'dart-api-examples/**'

workflow_dispatch:

concurrency:
group: test-dart-${{ github.ref }}
cancel-in-progress: true

jobs:
dart:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest] #, windows-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Flutter SDK
uses: flutter-actions/setup-flutter@v3
with:
channel: stable
version: latest

- name: Display flutter info
shell: bash
run: |
which flutter
which dart
flutter --version
dart --version
flutter doctor
- name: Run tests
shell: bash
run: |
cd dart-api-examples
pushd vad
./run.sh
popd
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment ve

project(sherpa-onnx)

set(SHERPA_ONNX_VERSION "1.9.28")
# Remember to update
# ./nodejs-addon-examples
# ./dart-api-examples/
set(SHERPA_ONNX_VERSION "1.9.29")

# Disable warning about
#
Expand Down
8 changes: 4 additions & 4 deletions cmake/cmake_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def get_binaries():
"piper_phonemize.dll",
"sherpa-onnx-c-api.dll",
"sherpa-onnx-core.dll",
"sherpa-onnx-fstfar.lib",
"sherpa-onnx-fst.lib",
"sherpa-onnx-kaldifst-core.lib",
"sherpa-onnx-fstfar.dll",
"sherpa-onnx-fst.dll",
"sherpa-onnx-kaldifst-core.dll",
"sherpa-onnx-portaudio.dll",
"ucd.dll",
]
Expand Down Expand Up @@ -211,7 +211,7 @@ def build_extension(self, ext: setuptools.extension.Extension):
binaries = get_binaries()

for f in binaries:
suffix = "" if (".dll" in f or ".lib" in f) else suffix
suffix = "" if ".dll" in f else suffix
src_file = install_dir / "bin" / (f + suffix)
if not src_file.is_file():
src_file = install_dir / "lib" / (f + suffix)
Expand Down
16 changes: 8 additions & 8 deletions cmake/kaldi-decoder.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function(download_kaldi_decoder)
include(FetchContent)

set(kaldi_decoder_URL "https://github.com/k2-fsa/kaldi-decoder/archive/refs/tags/v0.2.5.tar.gz")
set(kaldi_decoder_URL2 "https://hub.nuaa.cf/k2-fsa/kaldi-decoder/archive/refs/tags/v0.2.5.tar.gz")
set(kaldi_decoder_HASH "SHA256=f663e58aef31b33cd8086eaa09ff1383628039845f31300b5abef817d8cc2fff")
set(kaldi_decoder_URL "https://github.com/k2-fsa/kaldi-decoder/archive/refs/tags/v0.2.6.tar.gz")
set(kaldi_decoder_URL2 "https://hub.nuaa.cf/k2-fsa/kaldi-decoder/archive/refs/tags/v0.2.6.tar.gz")
set(kaldi_decoder_HASH "SHA256=b13c78b37495cafc6ef3f8a7b661b349c55a51abbd7f7f42f389408dcf86a463")

set(KALDI_DECODER_BUILD_PYTHON OFF CACHE BOOL "" FORCE)
set(KALDI_DECODER_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
Expand All @@ -12,11 +12,11 @@ function(download_kaldi_decoder)
# If you don't have access to the Internet,
# please pre-download kaldi-decoder
set(possible_file_locations
$ENV{HOME}/Downloads/kaldi-decoder-0.2.5.tar.gz
${CMAKE_SOURCE_DIR}/kaldi-decoder-0.2.5.tar.gz
${CMAKE_BINARY_DIR}/kaldi-decoder-0.2.5.tar.gz
/tmp/kaldi-decoder-0.2.5.tar.gz
/star-fj/fangjun/download/github/kaldi-decoder-0.2.5.tar.gz
$ENV{HOME}/Downloads/kaldi-decoder-0.2.6.tar.gz
${CMAKE_SOURCE_DIR}/kaldi-decoder-0.2.6.tar.gz
${CMAKE_BINARY_DIR}/kaldi-decoder-0.2.6.tar.gz
/tmp/kaldi-decoder-0.2.6.tar.gz
/star-fj/fangjun/download/github/kaldi-decoder-0.2.6.tar.gz
)

foreach(f IN LISTS possible_file_locations)
Expand Down
17 changes: 9 additions & 8 deletions cmake/kaldifst.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function(download_kaldifst)
include(FetchContent)

set(kaldifst_URL "https://github.com/k2-fsa/kaldifst/archive/refs/tags/v1.7.10.tar.gz")
set(kaldifst_URL2 "https://hub.nuaa.cf/k2-fsa/kaldifst/archive/refs/tags/v1.7.10.tar.gz")
set(kaldifst_HASH "SHA256=7f7b3173a6584a6b1987f65ae7af2ac453d66b845f875a9d31074b8d2cd0de54")
set(kaldifst_URL "https://github.com/k2-fsa/kaldifst/archive/refs/tags/v1.7.11.tar.gz")
set(kaldifst_URL2 "https://hub.nuaa.cf/k2-fsa/kaldifst/archive/refs/tags/v1.7.11.tar.gz")
set(kaldifst_HASH "SHA256=b43b3332faa2961edc730e47995a58cd4e22ead21905d55b0c4a41375b4a525f")

# If you don't have access to the Internet,
# please pre-download kaldifst
set(possible_file_locations
$ENV{HOME}/Downloads/kaldifst-1.7.10.tar.gz
${CMAKE_SOURCE_DIR}/kaldifst-1.7.10.tar.gz
${CMAKE_BINARY_DIR}/kaldifst-1.7.10.tar.gz
/tmp/kaldifst-1.7.10.tar.gz
/star-fj/fangjun/download/github/kaldifst-1.7.10.tar.gz
$ENV{HOME}/Downloads/kaldifst-1.7.11.tar.gz
${CMAKE_SOURCE_DIR}/kaldifst-1.7.11.tar.gz
${CMAKE_BINARY_DIR}/kaldifst-1.7.11.tar.gz
/tmp/kaldifst-1.7.11.tar.gz
/star-fj/fangjun/download/github/kaldifst-1.7.11.tar.gz
)

foreach(f IN LISTS possible_file_locations)
Expand Down Expand Up @@ -51,6 +51,7 @@ function(download_kaldifst)
)

set_target_properties(kaldifst_core PROPERTIES OUTPUT_NAME "sherpa-onnx-kaldifst-core")
# installed in ./kaldi-decoder.cmake
endfunction()

download_kaldifst()
20 changes: 9 additions & 11 deletions cmake/openfst.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
function(download_openfst)
include(FetchContent)

set(openfst_URL "https://github.com/csukuangfj/openfst/archive/refs/tags/sherpa-onnx-2024-05-22-2.tar.gz")
set(openfst_URL2 "https://hub.nuaa.cf/csukuangfj/openfst/archive/refs/tags/sherpa-onnx-2024-05-22-2.tar.gz")
set(openfst_HASH "SHA256=ec52d32ab46ac884d77c87918155ca9d0cae424095ce3bd7e3cc7eaab8235a39")
set(openfst_URL "https://github.com/csukuangfj/openfst/archive/refs/tags/sherpa-onnx-2024-06-13.tar.gz")
set(openfst_URL2 "https://hub.nuaa.cf/csukuangfj/openfst/archive/refs/tags/sherpa-onnx-2024-06-13.tar.gz")
set(openfst_HASH "SHA256=f10a71c6b64d89eabdc316d372b956c30c825c7c298e2f20c780320e8181ffb6")

# If you don't have access to the Internet,
# please pre-download it
set(possible_file_locations
$ENV{HOME}/Downloads/openfst-sherpa-onnx-2024-05-22-2.tar.gz
${CMAKE_SOURCE_DIR}/openfst-sherpa-onnx-2024-05-22-2.tar.gz
${CMAKE_BINARY_DIR}/openfst-sherpa-onnx-2024-05-22-2.tar.gz
/tmp/openfst-sherpa-onnx-2024-05-22-2.tar.gz
/star-fj/fangjun/download/github/openfst-sherpa-onnx-2024-05-22-2.tar.gz
$ENV{HOME}/Downloads/openfst-sherpa-onnx-2024-06-13.tar.gz
${CMAKE_SOURCE_DIR}/openfst-sherpa-onnx-2024-06-13.tar.gz
${CMAKE_BINARY_DIR}/openfst-sherpa-onnx-2024-06-13.tar.gz
/tmp/openfst-sherpa-onnx-2024-06-13.tar.gz
/star-fj/fangjun/download/github/openfst-sherpa-onnx-2024-06-13.tar.gz
)

foreach(f IN LISTS possible_file_locations)
Expand All @@ -27,7 +27,7 @@ function(download_openfst)
endforeach()

set(HAVE_BIN OFF CACHE BOOL "" FORCE)
set(HAVE_SCRIPT ON CACHE BOOL "" FORCE)
set(HAVE_SCRIPT OFF CACHE BOOL "" FORCE)
set(HAVE_COMPACT OFF CACHE BOOL "" FORCE)
set(HAVE_COMPRESS OFF CACHE BOOL "" FORCE)
set(HAVE_CONST OFF CACHE BOOL "" FORCE)
Expand Down Expand Up @@ -70,8 +70,6 @@ function(download_openfst)
add_subdirectory(${openfst_SOURCE_DIR} ${openfst_BINARY_DIR} EXCLUDE_FROM_ALL)
set(openfst_SOURCE_DIR ${openfst_SOURCE_DIR} PARENT_SCOPE)

# Rename libfst.so.6 to libsherpa-onnx-fst.so.6 to avoid potential conflicts
# when sherpa-onnx is installed.
set_target_properties(fst PROPERTIES OUTPUT_NAME "sherpa-onnx-fst")
set_target_properties(fstfar PROPERTIES OUTPUT_NAME "sherpa-onnx-fstfar")

Expand Down
Loading

0 comments on commit d08cc04

Please sign in to comment.