Fangjun Kuang
Committed by GitHub

Fix building for .Net (#463)

name: dot-net
name: release-nuget-package
on:
push:
branches:
- dot-net
- fix-dot-net
tags:
- '*'
workflow_dispatch:
concurrency:
group: dot-net-${{ github.ref }}
group: release-nuget-package
cancel-in-progress: true
permissions:
contents: read
jobs:
build-libs:
name: dot-net for ${{ matrix.os }}
release-nuget-package:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
# see https://cibuildwheel.readthedocs.io/en/stable/changelog/
# for a list of versions
- name: Build wheels
uses: pypa/cibuildwheel@v2.11.4
env:
CIBW_BEFORE_BUILD: "pip install -U cmake numpy"
CIBW_BUILD: "cp38-*64"
CIBW_SKIP: "cp27-* cp35-* cp36-* *-win32 pp* *-musllinux* *-manylinux_i686"
CIBW_BUILD_VERBOSITY: 3
CIBW_ENVIRONMENT_LINUX: LD_LIBRARY_PATH='/project/build/bdist.linux-x86_64/wheel/sherpa_onnx/lib'
CIBW_REPAIR_WHEEL_COMMAND_MACOS: ""
- name: Display wheels
shell: bash
run: |
ls -lh ./wheelhouse/*.whl
unzip -l ./wheelhouse/*.whl
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}-wheels
path: ./wheelhouse/*.whl
build-nuget-packages:
name: build-nuget-packages
runs-on: ubuntu-latest
needs: build-libs
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: Retrieve artifact from ubuntu-latest
uses: actions/download-artifact@v2
with:
name: ubuntu-latest-wheels
path: ./linux
- name: Retrieve artifact from macos-latest
uses: actions/download-artifact@v2
with:
name: macos-latest-wheels
path: ./macos
- name: Retrieve artifact from windows-latest
uses: actions/download-artifact@v2
with:
name: windows-latest-wheels
path: ./windows
- name: Display wheels
shell: bash
run: |
tree .
- name: Unzip Ubuntu wheels
shell: bash
run: |
cd linux
unzip ./*.whl
tree .
- name: Unzip macOS wheels
shell: bash
run: |
cd macos
unzip ./*.whl
tree .
- name: Unzip Windows wheels
shell: bash
run: |
cd windows
unzip ./*.whl
tree .
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
fetch-depth: 0
- name: Setup .NET 7.0
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x
dotnet-version: |
6.0.x
7.0.x
- name: Check dotnet
run: dotnet --info
- name: build nuget packages
- name: Build
shell: bash
run: |
cd scripts/dotnet
./run.sh
ls -lh packages
- uses: actions/upload-artifact@v3
name: upload nuget packages
with:
name: nuget-packages
path: scripts/dotnet/packages/*.nupkg
ls -lh /tmp/packages
- name: publish .Net packages to nuget.org
if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
... ... @@ -133,13 +48,5 @@ jobs:
API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
# API_KEY is valid until 2024.05.02
cd scripts/dotnet/packages
cd /tmp/packages
dotnet nuget push ./org.k2fsa.sherpa.onnx.*.nupkg --skip-duplicate --api-key $API_KEY --source https://api.nuget.org/v3/index.json
- name: Release nuget packages
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: scripts/dotnet/packages/*.nupkg
... ...
name: test-dot-net-nuget
on:
workflow_dispatch:
schedule:
# minute (0-59)
# hour (0-23)
# day of the month (1-31)
# month (1-12)
# day of the week (0-6)
# nightly build at 23:50 UTC time every day
- cron: "50 23 * * *"
concurrency:
group: test-dot-net-nuget
cancel-in-progress: true
permissions:
contents: read
jobs:
test-dot-net-nuget:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Check dotnet
run: dotnet --info
- name: Decode a file
shell: bash
run: |
cd dotnet-examples/
cd online-decode-files
./run-transducer.sh
./run-paraformer.sh
cd ../offline-decode-files
./run-nemo-ctc.sh
./run-paraformer.sh
./run-zipformer.sh
./run-whisper.sh
./run-tdnn-yesno.sh
... ...
... ... @@ -4,28 +4,13 @@ on:
push:
branches:
- master
paths:
- '.github/workflows/test-dot-net'
- 'dotnet-examples/**'
pull_request:
branches:
- master
paths:
- '.github/workflows/test-dot-net'
- 'dotnet-examples/**'
workflow_dispatch:
schedule:
# minute (0-59)
# hour (0-23)
# day of the month (1-31)
# month (1-12)
# day of the week (0-6)
# nightly build at 23:50 UTC time every day
- cron: "50 23 * * *"
concurrency:
group: test-dot-net
cancel-in-progress: true
... ... @@ -34,31 +19,124 @@ permissions:
contents: read
jobs:
test-dot-net:
build-libs:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ matrix.os }}-release-shared
- name: Build sherpa-onnx
shell: bash
run: |
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --target install --config Release
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}
path: ./build/install/lib/
test-dot-net:
runs-on: ${{ matrix.os }}
needs: [build-libs]
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.8"]
steps:
- uses: actions/checkout@v4
with:
dotnet-version: 3.1.x
fetch-depth: 0
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
dotnet-version: 6.0.x
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip Jinja2
- name: Retrieve artifact from ubuntu-latest
uses: actions/download-artifact@v2
with:
name: ubuntu-latest
path: /tmp/linux
- name: Retrieve artifact from macos-latest
uses: actions/download-artifact@v2
with:
name: macos-latest
path: /tmp/macos
- name: Retrieve artifact from windows-latest
uses: actions/download-artifact@v2
with:
name: windows-latest
path: /tmp/windows
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.0.x
7.0.x
- name: Check dotnet
run: dotnet --info
- name: Display files
shell: bash
run: |
echo "----------/tmp/----------"
ls -lh /tmp/
echo "----------/tmp/linux----------"
ls -lh /tmp/linux
echo "----------/tmp/macos----------"
ls -lh /tmp/macos
echo "----------/tmp/windows----------"
ls -lh /tmp/windows
- name: Build
shell: bash
run: |
cd scripts/dotnet
./run.sh
- name: Copy files
shell: bash
run: |
cp -v scripts/dotnet/examples/offline-decode-files.csproj dotnet-examples/offline-decode-files/
cp -v scripts/dotnet/examples/online-decode-files.csproj dotnet-examples/online-decode-files/
cp -v scripts/dotnet/examples/speech-recognition-from-microphone.csproj dotnet-examples/speech-recognition-from-microphone/
ls -lh /tmp
- name: Decode a file
shell: bash
run: |
... ...
# Introduction
Files in this directory are used exclusively by CI.
... ...
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>offline_decode_files</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup>
</Project>
... ...
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>online_decode_files</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup>
</Project>
... ...
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>speech_recognition_from_microphone</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
<PackageReference Include="PortAudioSharp2" Version="*" />
</ItemGroup>
</Project>
... ...
... ... @@ -33,12 +33,18 @@ def get_dict():
def process_linux(s):
libs = [
"libespeak-ng.so",
"libkaldi-decoder-core.so",
"libkaldi-native-fbank-core.so",
"libonnxruntime.so.1.16.2",
"libonnxruntime.so.1.16.3",
"libpiper_phonemize.so.1",
"libsherpa-onnx-c-api.so",
"libsherpa-onnx-core.so",
"libsherpa-onnx-fst.so.6",
"libsherpa-onnx-kaldifst-core.so",
"libucd.so",
]
prefix = f"{SHERPA_ONNX_DIR}/linux/sherpa_onnx/lib/"
prefix = "/tmp/linux/"
libs = [prefix + lib for lib in libs]
libs = "\n ;".join(libs)
... ... @@ -55,12 +61,18 @@ def process_linux(s):
def process_macos(s):
libs = [
"libespeak-ng.dylib",
"libkaldi-decoder-core.dylib",
"libkaldi-native-fbank-core.dylib",
"libonnxruntime.1.16.2.dylib",
"libonnxruntime.1.16.3.dylib",
"libpiper_phonemize.1.dylib",
"libsherpa-onnx-c-api.dylib",
"libsherpa-onnx-core.dylib",
"libsherpa-onnx-fst.6.dylib",
"libsherpa-onnx-kaldifst-core.dylib",
"libucd.dylib",
]
prefix = f"{SHERPA_ONNX_DIR}/macos/sherpa_onnx/lib/"
prefix = f"/tmp/macos/"
libs = [prefix + lib for lib in libs]
libs = "\n ;".join(libs)
... ... @@ -77,30 +89,23 @@ def process_macos(s):
def process_windows(s):
libs = [
"espeak-ng.dll",
"kaldi-decoder-core.dll",
"kaldi-native-fbank-core.dll",
"onnxruntime.dll",
"piper_phonemize.dll",
"sherpa-onnx-c-api.dll",
"sherpa-onnx-core.dll",
"sherpa-onnx-fst.lib",
"sherpa-onnx-kaldifst-core.lib",
"ucd.dll",
]
version = get_version()
prefix1 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx/lib/"
prefix2 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx/"
prefix3 = f"{SHERPA_ONNX_DIR}/windows/"
prefix4 = f"{SHERPA_ONNX_DIR}/windows/sherpa_onnx-{version}.data/data/bin/"
print(prefix1, prefix2, prefix3, prefix4)
lib_list = []
for lib in libs:
for prefix in [prefix1, prefix2, prefix3, prefix4]:
f = Path(prefix) / lib
if f.is_file():
lib_list.append(str(f))
break
print("lib_list", lib_list)
libs = "\n ;".join(lib_list)
prefix = "/tmp/windows/"
libs = [prefix + lib for lib in libs]
libs = "\n ;".join(libs)
d = get_dict()
d["dotnet_rid"] = "win-x64"
... ...
... ... @@ -138,6 +138,8 @@ namespace SherpaOnnx
DecodingMethod = "greedy_search";
MaxActivePaths = 4;
HotwordsFile = "";
HotwordsScore = 1.5F;
}
public FeatureConfig FeatConfig;
... ... @@ -148,6 +150,11 @@ namespace SherpaOnnx
public string DecodingMethod;
public int MaxActivePaths;
[MarshalAs(UnmanagedType.LPStr)]
public string HotwordsFile;
public float HotwordsScore;
}
public class OfflineRecognizerResult
... ...
... ... @@ -3,6 +3,75 @@
set -ex
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SHERPA_ONNX_DIR=$(cd $SCRIPT_DIR/../.. && pwd)
echo "SCRIPT_DIR: $SCRIPT_DIR"
echo "SHERPA_ONNX_DIR: $SHERPA_ONNX_DIR"
SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" $SHERPA_ONNX_DIR/CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
mkdir -p /tmp/
pushd /tmp
mkdir -p linux macos windows
if [ ! -f /tmp/linux/libsherpa-onnx-core.so ]; then
echo "---linux x86_64---"
cd linux
mkdir wheel
cd wheel
curl -OL https://huggingface.co/csukuangfj/sherpa-onnx-wheels/resolve/main/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
unzip sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cp -v sherpa_onnx/lib/*.so* ../
cd ..
rm -v libpiper_phonemize.so libpiper_phonemize.so.1.2.0
rm -v libsherpa-onnx-fst.so
rm -v libonnxruntime.so
rm -v libcargs.so
rm -rf wheel
ls -lh
cd ..
fi
if [ ! -f /tmp/macos/libsherpa-onnx-core.dylib ]; then
echo "---macOS x86_64---"
cd macos
mkdir wheel
cd wheel
curl -OL https://huggingface.co/csukuangfj/sherpa-onnx-wheels/resolve/main/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-macosx_10_14_x86_64.whl
unzip sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-macosx_10_14_x86_64.whl
cp -v sherpa_onnx/lib/*.dylib ../
cd ..
rm -v libcargs.dylib
rm -v libonnxruntime.dylib
rm -v libpiper_phonemize.1.2.0.dylib libpiper_phonemize.dylib
rm -v libsherpa-onnx-fst.dylib
rm -rf wheel
ls -lh
cd ..
fi
if [ ! -f /tmp/windows/libsherpa-onnx-core.dll ]; then
echo "---windows x64---"
cd windows
mkdir wheel
cd wheel
curl -OL https://huggingface.co/csukuangfj/sherpa-onnx-wheels/resolve/main/sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl
unzip sherpa_onnx-${SHERPA_ONNX_VERSION}-cp38-cp38-win_amd64.whl
cp -v sherpa_onnx-${SHERPA_ONNX_VERSION}.data/data/bin/*.dll ../
cp -v sherpa_onnx-${SHERPA_ONNX_VERSION}.data/data/bin/*.lib ../
cd ..
rm -rf wheel
ls -lh
cd ..
fi
popd
mkdir -p macos linux windows all
cp ./online.cs all
... ... @@ -31,3 +100,6 @@ dotnet pack -c Release -o ../packages
popd
ls -lh packages
mkdir /tmp/packages
cp -v packages/*.nupkg /tmp/packages
... ...