From 80ba78938f0e842242d2e3d90989f3fe7fed85e5 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:07:27 +0200 Subject: [PATCH 01/79] WIP --- .github/workflows/dotnet.yml | 45 ++++++++++++++++-- .github/workflows/linux-cuda-native-build.yml | 41 +++++++++++++++++ .github/workflows/linux-native-build.yml | 8 ---- .../workflows/windows-cuda-native-build.yml | 46 +++++++++++++++++++ .github/workflows/windows-native-build.yml | 14 +----- Makefile | 4 +- .../Whisper.net.Runtime.targets | 3 +- Whisper.net.sln | 2 + windows-scripts.ps1 | 1 - 9 files changed, 137 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/linux-cuda-native-build.yml create mode 100644 .github/workflows/windows-cuda-native-build.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 8d03da23..54fffe0d 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -6,8 +6,8 @@ name: CI on: push: branches: [ "main" ] - #pull_request: - # branches: [ "main" ] + pull_request: + branches: [ "main" ] jobs: build: @@ -22,13 +22,51 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x + + - name: Download Wasm artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + name: wasm-build + + - name: Download Windows artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + name: windows-build + + - name: Download Linux artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + name: linux-build + + - name: Download Mac Arm artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + name: mac-arm-build + + - name: Download Mac Intel artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + name: mac-intel-build + + - name: Download Android artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + name: android-build + - name: Install Java if: runner.os == 'Windows' uses: actions/setup-java@v2 with: distribution: 'microsoft' java-version: '11' + - name: Install .NET Workloads if: runner.os == 'Windows' run: | @@ -36,6 +74,7 @@ jobs: dotnet workload install ios --ignore-failed-sources dotnet workload install tvos --ignore-failed-sources dotnet workload install maccatalyst --ignore-failed-sources + - name: Restore dependencies run: dotnet restore ./Whisper.net.sln - name: Build diff --git a/.github/workflows/linux-cuda-native-build.yml b/.github/workflows/linux-cuda-native-build.yml new file mode 100644 index 00000000..16170c36 --- /dev/null +++ b/.github/workflows/linux-cuda-native-build.yml @@ -0,0 +1,41 @@ +name: Linux Cuda Native build + +on: + workflow_dispatch: + + +jobs: + build: + + runs-on: ubuntu-20.04 + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + ref: ${{ github.head_ref }} + + - name: Install aarch64-linux-gnu-gcc + run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu && sudo apt-get install -y g++-aarch64-linux-gnu + + - name: Install gcc-arm-linux-gnueabihf + run: sudo apt-get update && sudo apt-get install -y gcc-arm-linux-gnueabihf && sudo apt-get install -y g++-arm-linux-gnueabihf + + - name: Install CUDA Toolkit + uses: Jimver/cuda-toolkit@v0.2.11 + with: + cuda: '12.1.0' + + - name: Run linux + run: make linux_cuda + + - name: Remove CUDA installer + run: rm -rf cuda_installer-* + + - name: Upload Linux Cuda Build Artifacts + uses: actions/upload-artifact@v3 + with: + name: linux-build + path: 'Whisper.net.Run*/linux-*/*' diff --git a/.github/workflows/linux-native-build.yml b/.github/workflows/linux-native-build.yml index b55e8500..a9f0736b 100644 --- a/.github/workflows/linux-native-build.yml +++ b/.github/workflows/linux-native-build.yml @@ -23,17 +23,9 @@ jobs: - name: Install gcc-arm-linux-gnueabihf run: sudo apt-get update && sudo apt-get install -y gcc-arm-linux-gnueabihf && sudo apt-get install -y g++-arm-linux-gnueabihf - - name: Install CUDA Toolkit - uses: Jimver/cuda-toolkit@v0.2.11 - with: - cuda: '12.1.0' - - name: Run linux run: make linux - - name: Remove CUDA installer - run: rm -rf cuda_installer-* - - name: Upload Linux Build Artifacts uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/windows-cuda-native-build.yml b/.github/workflows/windows-cuda-native-build.yml new file mode 100644 index 00000000..91df4657 --- /dev/null +++ b/.github/workflows/windows-cuda-native-build.yml @@ -0,0 +1,46 @@ +name: Windows Cuda native build + +on: + workflow_dispatch: + + +jobs: + build: + + runs-on: windows-2019 + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + + with: + submodules: true + ref: ${{ github.head_ref }} + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1 + + - name: Install OpenCl with vcpkg + run: | + vcpkg --triplet=x64-windows install opencl + + - name: Install CUDA Toolkit + uses: Jimver/cuda-toolkit@v0.2.11 + with: + cuda: '12.1.0' + + - name: Run Build + run: | + Import-Module ./windows-scripts.ps1 + BuildWindowsBase -Arch "x64" -Cuda $true -Configuration $Configuration; + shell: pwsh + + - name: Remove CUDA installer + run: Remove-Item -Path 'cuda_installer-*' -Recurse -Force -ErrorAction Ignore + + - name: Upload Windows Cuda Build Artifacts + uses: actions/upload-artifact@v3 + with: + name: windows-cuda-build + path: 'Whisper.net.Run*/win-*/*' diff --git a/.github/workflows/windows-native-build.yml b/.github/workflows/windows-native-build.yml index 023ec905..47cf6de6 100644 --- a/.github/workflows/windows-native-build.yml +++ b/.github/workflows/windows-native-build.yml @@ -21,24 +21,12 @@ jobs: - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1 - - name: Install OpenCl with vcpkg - run: | - vcpkg --triplet=x64-windows install opencl - - - name: Install CUDA Toolkit - uses: Jimver/cuda-toolkit@v0.2.11 - with: - cuda: '12.1.0' - - name: Run Build run: | Import-Module ./windows-scripts.ps1 BuildWindowsIntel shell: pwsh - - - name: Remove CUDA installer - run: Remove-Item -Path 'cuda_installer-*' -Recurse -Force -ErrorAction Ignore - + - name: Upload Windows Build Artifacts uses: actions/upload-artifact@v3 with: diff --git a/Makefile b/Makefile index dbb7b12f..7661c834 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,9 @@ apple_arm: macos_arm64 ios maccatalyst_arm64 ios_simulator_arm64 tvos_simulato apple_coreml_x64: copy_metal_coreml macos_x64_coreml apple_coreml_arm: macos_arm64_coreml ios_coreml maccatalyst_arm64_coreml ios_simulator_coreml tvos_simulator_coreml tvos_coreml -linux: linux_x64_cuda linux_x64 linux_arm64 linux_arm +linux: linux_x64 linux_arm64 linux_arm + +linux_cuda: linux_x64_cuda copy_metal: cp whisper.cpp/ggml/src/ggml-metal.m Whisper.net.Runtime/ggml-metal.metal diff --git a/Whisper.net.Runtime/Whisper.net.Runtime.targets b/Whisper.net.Runtime/Whisper.net.Runtime.targets index 687f309c..52d34158 100644 --- a/Whisper.net.Runtime/Whisper.net.Runtime.targets +++ b/Whisper.net.Runtime/Whisper.net.Runtime.targets @@ -22,8 +22,9 @@ true true PreserveNewest - runtimes/maccatalyst/libwhisper.dylib + libwhisper.dylib + diff --git a/Whisper.net.sln b/Whisper.net.sln index c6829a5b..19faef10 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -20,11 +20,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C8656 ProjectSection(SolutionItems) = preProject .github\workflows\android-native-build.yaml = .github\workflows\android-native-build.yaml .github\workflows\dotnet.yml = .github\workflows\dotnet.yml + .github\workflows\linux-cuda-native-build.yml = .github\workflows\linux-cuda-native-build.yml .github\workflows\linux-native-build.yml = .github\workflows\linux-native-build.yml .github\workflows\linux-openvino-build.yml = .github\workflows\linux-openvino-build.yml .github\workflows\macos-native-build.yaml = .github\workflows\macos-native-build.yaml .github\workflows\wasm-native-build.yaml = .github\workflows\wasm-native-build.yaml .github\workflows\windows-arm-native-build.yml = .github\workflows\windows-arm-native-build.yml + .github\workflows\windows-cuda-native-build.yml = .github\workflows\windows-cuda-native-build.yml .github\workflows\windows-native-build.yml = .github\workflows\windows-native-build.yml .github\workflows\windows-openvino-build.yml = .github\workflows\windows-openvino-build.yml .github\workflows\windows-vulkan-build.yml = .github\workflows\windows-vulkan-build.yml diff --git a/windows-scripts.ps1 b/windows-scripts.ps1 index bac144b2..c194dc0c 100644 --- a/windows-scripts.ps1 +++ b/windows-scripts.ps1 @@ -142,7 +142,6 @@ function BuildWindowsArm([Parameter(Mandatory = $false)] [string]$Configuration } function BuildWindowsIntel([Parameter(Mandatory = $false)] [string]$Configuration = "Release") { - BuildWindowsBase -Arch "x64" -Cuda $true -Configuration $Configuration; BuildWindowsBase -Arch "x64" -Configuration $Configuration; BuildWindowsBase -Arch "x86" -Configuration $Configuration; } From 35dc11788f8ebd88ad664db1ba8ce9520f598fee Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:11:15 +0200 Subject: [PATCH 02/79] a --- .github/workflows/dotnet.yml | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 54fffe0d..c0e9dae0 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -24,41 +24,11 @@ jobs: with: dotnet-version: 8.0.x - - name: Download Wasm artifacts + - name: Download Artifacts id: download-artifact uses: actions/download-artifact@v4 with: name: wasm-build - - - name: Download Windows artifacts - id: download-artifact - uses: actions/download-artifact@v4 - with: - name: windows-build - - - name: Download Linux artifacts - id: download-artifact - uses: actions/download-artifact@v4 - with: - name: linux-build - - - name: Download Mac Arm artifacts - id: download-artifact - uses: actions/download-artifact@v4 - with: - name: mac-arm-build - - - name: Download Mac Intel artifacts - id: download-artifact - uses: actions/download-artifact@v4 - with: - name: mac-intel-build - - - name: Download Android artifacts - id: download-artifact - uses: actions/download-artifact@v4 - with: - name: android-build - name: Install Java if: runner.os == 'Windows' From c6e7351551017c3b3fb983fed538d5a27c598ee8 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:35:24 +0200 Subject: [PATCH 03/79] T --- .github/workflows/android-native-build.yaml | 3 +- .github/workflows/cpu-build-and-test.yml | 36 ++++++++++++++ .github/workflows/dotnet.yml | 47 ++++++++++++++----- .github/workflows/linux-cuda-native-build.yml | 2 - .github/workflows/linux-native-build.yml | 3 +- .github/workflows/linux-openvino-build.yml | 2 - .github/workflows/macos-native-build.yaml | 4 +- .github/workflows/wasm-native-build.yaml | 3 +- .../workflows/windows-arm-native-build.yml | 2 - .../workflows/windows-cuda-native-build.yml | 2 - .github/workflows/windows-native-build.yml | 32 +++++++++++-- .github/workflows/windows-openvino-build.yml | 2 - .github/workflows/windows-vulkan-build.yml | 2 - Whisper.net.sln | 1 + 14 files changed, 104 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/cpu-build-and-test.yml diff --git a/.github/workflows/android-native-build.yaml b/.github/workflows/android-native-build.yaml index 28e98056..46b1e4ea 100644 --- a/.github/workflows/android-native-build.yaml +++ b/.github/workflows/android-native-build.yaml @@ -3,14 +3,13 @@ name: Android Native build on: workflow_dispatch: + workflow_call: jobs: build: runs-on: ubuntu-20.04 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/cpu-build-and-test.yml b/.github/workflows/cpu-build-and-test.yml new file mode 100644 index 00000000..f303185f --- /dev/null +++ b/.github/workflows/cpu-build-and-test.yml @@ -0,0 +1,36 @@ +# This workflow will build a .NET project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: CI (Native + dotnet) + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + android: + uses: ./android-native-build.yml + + macos: + uses: ./macos-native-build.yml + + windows: + uses: ./windows-native-build.yml + + wasm: + uses: ./wasm-native-build.yml + + linux: + uses: ./linux-native-build.yml + + dotnet-build: + needs: + - android + - macos + - windows + - wasm + - linux + uses: ./dotnet.yml + diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index c0e9dae0..2b2f0ed9 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -4,21 +4,16 @@ name: CI on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] + workflow_call: jobs: - build: + dotnet-windows: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest] + runs-on: windows-latest steps: - uses: actions/checkout@v3 + - name: Setup .NET uses: actions/setup-dotnet@v3 with: @@ -28,17 +23,15 @@ jobs: id: download-artifact uses: actions/download-artifact@v4 with: - name: wasm-build + merge-multiple: true - name: Install Java - if: runner.os == 'Windows' uses: actions/setup-java@v2 with: distribution: 'microsoft' java-version: '11' - name: Install .NET Workloads - if: runner.os == 'Windows' run: | dotnet workload install android --ignore-failed-sources dotnet workload install ios --ignore-failed-sources @@ -47,8 +40,36 @@ jobs: - name: Restore dependencies run: dotnet restore ./Whisper.net.sln + - name: Build - run: dotnet build ./Whisper.net.sln --no-restore -warnaserror + run: dotnet build ./Whisper.net.sln --no-restore -warnaserror + - name: Test run: | dotnet test ./Whisper.net.sln --no-build + + dotnet-linux: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + - name: Download Artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + merge-multiple: true + - name: Restore dependencies + run: dotnet restore ./Whisper.net.sln + + - name: Build + run: dotnet build ./Whisper.net.sln --no-restore -warnaserror + + - name: Test + run: | + dotnet test ./Whisper.net.sln --no-build diff --git a/.github/workflows/linux-cuda-native-build.yml b/.github/workflows/linux-cuda-native-build.yml index 16170c36..8e18e17a 100644 --- a/.github/workflows/linux-cuda-native-build.yml +++ b/.github/workflows/linux-cuda-native-build.yml @@ -8,8 +8,6 @@ jobs: build: runs-on: ubuntu-20.04 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/linux-native-build.yml b/.github/workflows/linux-native-build.yml index a9f0736b..c155fcab 100644 --- a/.github/workflows/linux-native-build.yml +++ b/.github/workflows/linux-native-build.yml @@ -2,14 +2,13 @@ name: Linux Native build on: workflow_dispatch: + workflow_call: jobs: build: runs-on: ubuntu-20.04 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/linux-openvino-build.yml b/.github/workflows/linux-openvino-build.yml index 2afdd71f..9d18960d 100644 --- a/.github/workflows/linux-openvino-build.yml +++ b/.github/workflows/linux-openvino-build.yml @@ -7,8 +7,6 @@ jobs: build: runs-on: ubuntu-20.04 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/macos-native-build.yaml b/.github/workflows/macos-native-build.yaml index c5a46cfc..206cb8d0 100644 --- a/.github/workflows/macos-native-build.yaml +++ b/.github/workflows/macos-native-build.yaml @@ -3,13 +3,12 @@ name: MacOs Native build on: workflow_dispatch: + workflow_call: jobs: intel-build: runs-on: macos-13 - permissions: - contents: write steps: - uses: actions/checkout@v4 @@ -32,7 +31,6 @@ jobs: Whisper.net.Run*/*.metal arm-build: - needs: intel-build runs-on: macos-14 permissions: contents: write diff --git a/.github/workflows/wasm-native-build.yaml b/.github/workflows/wasm-native-build.yaml index d3ebd595..522c781a 100644 --- a/.github/workflows/wasm-native-build.yaml +++ b/.github/workflows/wasm-native-build.yaml @@ -3,13 +3,12 @@ name: Wasm Native build on: workflow_dispatch: + workflow_call: jobs: build: runs-on: ubuntu-20.04 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/windows-arm-native-build.yml b/.github/workflows/windows-arm-native-build.yml index dabcb0f9..91a1ea18 100644 --- a/.github/workflows/windows-arm-native-build.yml +++ b/.github/workflows/windows-arm-native-build.yml @@ -8,8 +8,6 @@ jobs: build: runs-on: windows-latest - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/windows-cuda-native-build.yml b/.github/workflows/windows-cuda-native-build.yml index 91df4657..d6c064bf 100644 --- a/.github/workflows/windows-cuda-native-build.yml +++ b/.github/workflows/windows-cuda-native-build.yml @@ -8,8 +8,6 @@ jobs: build: runs-on: windows-2019 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/windows-native-build.yml b/.github/workflows/windows-native-build.yml index 47cf6de6..6e134177 100644 --- a/.github/workflows/windows-native-build.yml +++ b/.github/workflows/windows-native-build.yml @@ -2,14 +2,13 @@ name: Windows native build on: workflow_dispatch: + workflow_call: jobs: - build: + intel-build: runs-on: windows-2019 - permissions: - contents: write steps: - uses: actions/checkout@v4 @@ -32,3 +31,30 @@ jobs: with: name: windows-build path: 'Whisper.net.Run*/win-*/*' + + arm-build: + + runs-on: windows-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + ref: ${{ github.head_ref }} + + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1 + + - name: Run Build + run: | + Import-Module ./windows-scripts.ps1 + BuildWindowsArm + shell: pwsh + + - name: Upload Windows Build Artifacts + uses: actions/upload-artifact@v3 + with: + name: windows-arm-build + path: 'Whisper.net.Run*/win-*/*' diff --git a/.github/workflows/windows-openvino-build.yml b/.github/workflows/windows-openvino-build.yml index e33d0385..0ec58309 100644 --- a/.github/workflows/windows-openvino-build.yml +++ b/.github/workflows/windows-openvino-build.yml @@ -7,8 +7,6 @@ jobs: build: runs-on: windows-2022 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/windows-vulkan-build.yml b/.github/workflows/windows-vulkan-build.yml index ef024b7a..9359d7ae 100644 --- a/.github/workflows/windows-vulkan-build.yml +++ b/.github/workflows/windows-vulkan-build.yml @@ -7,8 +7,6 @@ jobs: build: runs-on: windows-2022 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/Whisper.net.sln b/Whisper.net.sln index 19faef10..f100c388 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -19,6 +19,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C865649-4AED-4BBF-A7CA-BD68D21EF48F}" ProjectSection(SolutionItems) = preProject .github\workflows\android-native-build.yaml = .github\workflows\android-native-build.yaml + .github\workflows\cpu-build-and-test.yml = .github\workflows\cpu-build-and-test.yml .github\workflows\dotnet.yml = .github\workflows\dotnet.yml .github\workflows\linux-cuda-native-build.yml = .github\workflows\linux-cuda-native-build.yml .github\workflows\linux-native-build.yml = .github\workflows\linux-native-build.yml From d12ab7ca73fe1caf606c11749c0180049445f2ef Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:36:42 +0200 Subject: [PATCH 04/79] a --- .github/workflows/cpu-build-and-test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cpu-build-and-test.yml b/.github/workflows/cpu-build-and-test.yml index f303185f..3864d314 100644 --- a/.github/workflows/cpu-build-and-test.yml +++ b/.github/workflows/cpu-build-and-test.yml @@ -11,19 +11,19 @@ on: jobs: android: - uses: ./android-native-build.yml + uses: ./.android-native-build.yml macos: - uses: ./macos-native-build.yml + uses: ./.macos-native-build.yml windows: - uses: ./windows-native-build.yml + uses: ./.windows-native-build.yml wasm: - uses: ./wasm-native-build.yml + uses: ./.wasm-native-build.yml linux: - uses: ./linux-native-build.yml + uses: ./.linux-native-build.yml dotnet-build: needs: From 56dc3b117c1047d61358f8407307570fd5bd8155 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:38:58 +0200 Subject: [PATCH 05/79] USed @${{ github.head_ref }} --- .github/workflows/cpu-build-and-test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cpu-build-and-test.yml b/.github/workflows/cpu-build-and-test.yml index 3864d314..d977f751 100644 --- a/.github/workflows/cpu-build-and-test.yml +++ b/.github/workflows/cpu-build-and-test.yml @@ -11,19 +11,19 @@ on: jobs: android: - uses: ./.android-native-build.yml + uses: ./.android-native-build.yml@${{ github.head_ref }} macos: - uses: ./.macos-native-build.yml + uses: ./.macos-native-build.yml@${{ github.head_ref }} windows: - uses: ./.windows-native-build.yml + uses: ./.windows-native-build.yml@${{ github.head_ref }} wasm: - uses: ./.wasm-native-build.yml + uses: ./.wasm-native-build.yml@${{ github.head_ref }} linux: - uses: ./.linux-native-build.yml + uses: ./.linux-native-build.yml@${{ github.head_ref }} dotnet-build: needs: @@ -32,5 +32,5 @@ jobs: - windows - wasm - linux - uses: ./dotnet.yml + uses: ./dotnet.yml@${{ github.head_ref }} From fde75fdc1e936d0519597103b2a05222df9cc981 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:44:42 +0200 Subject: [PATCH 06/79] Try again --- .github/workflows/cpu-build-and-test.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cpu-build-and-test.yml b/.github/workflows/cpu-build-and-test.yml index d977f751..1807d5fb 100644 --- a/.github/workflows/cpu-build-and-test.yml +++ b/.github/workflows/cpu-build-and-test.yml @@ -10,20 +10,21 @@ on: branches: [ "main" ] jobs: + android: - uses: ./.android-native-build.yml@${{ github.head_ref }} + uses: ./.github/workflows/android-native-build.yml macos: - uses: ./.macos-native-build.yml@${{ github.head_ref }} + uses: ./.github/workflows/macos-native-build.yml windows: - uses: ./.windows-native-build.yml@${{ github.head_ref }} + uses: ./.github/workflows/windows-native-build.yml wasm: - uses: ./.wasm-native-build.yml@${{ github.head_ref }} + uses: ./.github/workflows/wasm-native-build.yml linux: - uses: ./.linux-native-build.yml@${{ github.head_ref }} + uses: ./.github/workflows/linux-native-build.yml dotnet-build: needs: @@ -32,5 +33,5 @@ jobs: - windows - wasm - linux - uses: ./dotnet.yml@${{ github.head_ref }} + uses: ./.github/workflows/dotnet.yml From 0531fbeb141f15e034d8a726fc46c4c795e0499c Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:45:41 +0200 Subject: [PATCH 07/79] one more --- .github/workflows/cpu-build-and-test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cpu-build-and-test.yml b/.github/workflows/cpu-build-and-test.yml index 1807d5fb..550f3f2e 100644 --- a/.github/workflows/cpu-build-and-test.yml +++ b/.github/workflows/cpu-build-and-test.yml @@ -12,19 +12,19 @@ on: jobs: android: - uses: ./.github/workflows/android-native-build.yml + uses: .github/workflows/android-native-build.yml macos: - uses: ./.github/workflows/macos-native-build.yml + uses: .github/workflows/macos-native-build.yml windows: - uses: ./.github/workflows/windows-native-build.yml + uses: .github/workflows/windows-native-build.yml wasm: - uses: ./.github/workflows/wasm-native-build.yml + uses: .github/workflows/wasm-native-build.yml linux: - uses: ./.github/workflows/linux-native-build.yml + uses: .github/workflows/linux-native-build.yml dotnet-build: needs: @@ -33,5 +33,5 @@ jobs: - windows - wasm - linux - uses: ./.github/workflows/dotnet.yml + uses: .github/workflows/dotnet.yml From de72c0f00a227d7fd55d252f8d8c53eda42dabc8 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:49:35 +0200 Subject: [PATCH 08/79] a --- .github/workflows/cpu-build-and-test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cpu-build-and-test.yml b/.github/workflows/cpu-build-and-test.yml index 550f3f2e..1807d5fb 100644 --- a/.github/workflows/cpu-build-and-test.yml +++ b/.github/workflows/cpu-build-and-test.yml @@ -12,19 +12,19 @@ on: jobs: android: - uses: .github/workflows/android-native-build.yml + uses: ./.github/workflows/android-native-build.yml macos: - uses: .github/workflows/macos-native-build.yml + uses: ./.github/workflows/macos-native-build.yml windows: - uses: .github/workflows/windows-native-build.yml + uses: ./.github/workflows/windows-native-build.yml wasm: - uses: .github/workflows/wasm-native-build.yml + uses: ./.github/workflows/wasm-native-build.yml linux: - uses: .github/workflows/linux-native-build.yml + uses: ./.github/workflows/linux-native-build.yml dotnet-build: needs: @@ -33,5 +33,5 @@ jobs: - windows - wasm - linux - uses: .github/workflows/dotnet.yml + uses: ./.github/workflows/dotnet.yml From 94fff048948b63fe5f56cb938659ae4b32404e0c Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:51:32 +0200 Subject: [PATCH 09/79] renamed yaml -> yml --- .../{android-native-build.yaml => android-native-build.yml} | 0 .../{macos-native-build.yaml => macos-native-build.yml} | 0 .../{wasm-native-build.yaml => wasm-native-build.yml} | 0 Whisper.net.sln | 6 +++--- 4 files changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{android-native-build.yaml => android-native-build.yml} (100%) rename .github/workflows/{macos-native-build.yaml => macos-native-build.yml} (100%) rename .github/workflows/{wasm-native-build.yaml => wasm-native-build.yml} (100%) diff --git a/.github/workflows/android-native-build.yaml b/.github/workflows/android-native-build.yml similarity index 100% rename from .github/workflows/android-native-build.yaml rename to .github/workflows/android-native-build.yml diff --git a/.github/workflows/macos-native-build.yaml b/.github/workflows/macos-native-build.yml similarity index 100% rename from .github/workflows/macos-native-build.yaml rename to .github/workflows/macos-native-build.yml diff --git a/.github/workflows/wasm-native-build.yaml b/.github/workflows/wasm-native-build.yml similarity index 100% rename from .github/workflows/wasm-native-build.yaml rename to .github/workflows/wasm-native-build.yml diff --git a/Whisper.net.sln b/Whisper.net.sln index f100c388..7b62e07f 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -18,14 +18,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whisper.net.Tests", "Whispe EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C865649-4AED-4BBF-A7CA-BD68D21EF48F}" ProjectSection(SolutionItems) = preProject - .github\workflows\android-native-build.yaml = .github\workflows\android-native-build.yaml + .github\workflows\android-native-build.yml = .github\workflows\android-native-build.yml .github\workflows\cpu-build-and-test.yml = .github\workflows\cpu-build-and-test.yml .github\workflows\dotnet.yml = .github\workflows\dotnet.yml .github\workflows\linux-cuda-native-build.yml = .github\workflows\linux-cuda-native-build.yml .github\workflows\linux-native-build.yml = .github\workflows\linux-native-build.yml .github\workflows\linux-openvino-build.yml = .github\workflows\linux-openvino-build.yml - .github\workflows\macos-native-build.yaml = .github\workflows\macos-native-build.yaml - .github\workflows\wasm-native-build.yaml = .github\workflows\wasm-native-build.yaml + .github\workflows\macos-native-build.yml = .github\workflows\macos-native-build.yml + .github\workflows\wasm-native-build.yml = .github\workflows\wasm-native-build.yml .github\workflows\windows-arm-native-build.yml = .github\workflows\windows-arm-native-build.yml .github\workflows\windows-cuda-native-build.yml = .github\workflows\windows-cuda-native-build.yml .github\workflows\windows-native-build.yml = .github\workflows\windows-native-build.yml From 962ebb8b2ebab36164fdda9b820c621059c2890f Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 16:52:47 +0200 Subject: [PATCH 10/79] Permissions fix --- .github/workflows/macos-native-build.yml | 2 -- .github/workflows/windows-native-build.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.github/workflows/macos-native-build.yml b/.github/workflows/macos-native-build.yml index 206cb8d0..77f55de0 100644 --- a/.github/workflows/macos-native-build.yml +++ b/.github/workflows/macos-native-build.yml @@ -32,8 +32,6 @@ jobs: arm-build: runs-on: macos-14 - permissions: - contents: write steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/windows-native-build.yml b/.github/workflows/windows-native-build.yml index 6e134177..3f647644 100644 --- a/.github/workflows/windows-native-build.yml +++ b/.github/workflows/windows-native-build.yml @@ -35,8 +35,6 @@ jobs: arm-build: runs-on: windows-latest - permissions: - contents: write steps: - uses: actions/checkout@v4 From ecbb8203f12ec6bcbdf74950c9389c62ea9f570c Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 17:25:15 +0200 Subject: [PATCH 11/79] v3 and v4 issue --- .github/workflows/android-native-build.yml | 2 +- .../{cpu-build-and-test.yml => build-all.yml} | 18 ++++++++++++ .github/workflows/linux-cuda-native-build.yml | 2 +- .github/workflows/linux-native-build.yml | 2 +- .github/workflows/linux-openvino-build.yml | 2 +- .../workflows/macos-coreml-native-build.yml | 28 +++++++++++++++++++ .github/workflows/macos-native-build.yml | 7 ++--- .github/workflows/wasm-native-build.yml | 2 +- .../workflows/windows-arm-native-build.yml | 2 +- .../workflows/windows-cuda-native-build.yml | 2 +- .github/workflows/windows-native-build.yml | 4 +-- ....yml => windows-openvino-native-build.yml} | 2 +- ...ld.yml => windows-vulkan-native-build.yml} | 2 +- Whisper.net.sln | 7 +++-- nuget.config | 4 +-- 15 files changed, 65 insertions(+), 21 deletions(-) rename .github/workflows/{cpu-build-and-test.yml => build-all.yml} (60%) create mode 100644 .github/workflows/macos-coreml-native-build.yml rename .github/workflows/{windows-openvino-build.yml => windows-openvino-native-build.yml} (96%) rename .github/workflows/{windows-vulkan-build.yml => windows-vulkan-native-build.yml} (95%) diff --git a/.github/workflows/android-native-build.yml b/.github/workflows/android-native-build.yml index 46b1e4ea..2b62ffa7 100644 --- a/.github/workflows/android-native-build.yml +++ b/.github/workflows/android-native-build.yml @@ -26,7 +26,7 @@ jobs: run: make android - name: Upload Android Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: android-build path: 'Whisper.net.Run*/android-*/*' diff --git a/.github/workflows/cpu-build-and-test.yml b/.github/workflows/build-all.yml similarity index 60% rename from .github/workflows/cpu-build-and-test.yml rename to .github/workflows/build-all.yml index 1807d5fb..feb77de8 100644 --- a/.github/workflows/cpu-build-and-test.yml +++ b/.github/workflows/build-all.yml @@ -26,6 +26,24 @@ jobs: linux: uses: ./.github/workflows/linux-native-build.yml + windows-cuda: + uses: ./.github/workflows/windows-cuda-native-build.yml + + windows-vulkan: + uses: ./.github/workflows/windows-vulkan-native-build.yml + + windows-openvino: + uses: ./.github/workflows/windows-openvino-native-build.yml + + linux-cuda: + uses: ./.github/workflows/linux-cuda-native-build.yml + + linux-openvino: + uses: ./.github/workflows/linux-openvino-native-build.yml + + macos-coreml: + uses: ./.github/workflows/macos-coreml-native-build.yml + dotnet-build: needs: - android diff --git a/.github/workflows/linux-cuda-native-build.yml b/.github/workflows/linux-cuda-native-build.yml index 8e18e17a..13207b54 100644 --- a/.github/workflows/linux-cuda-native-build.yml +++ b/.github/workflows/linux-cuda-native-build.yml @@ -33,7 +33,7 @@ jobs: run: rm -rf cuda_installer-* - name: Upload Linux Cuda Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linux-build path: 'Whisper.net.Run*/linux-*/*' diff --git a/.github/workflows/linux-native-build.yml b/.github/workflows/linux-native-build.yml index c155fcab..c35e4c22 100644 --- a/.github/workflows/linux-native-build.yml +++ b/.github/workflows/linux-native-build.yml @@ -26,7 +26,7 @@ jobs: run: make linux - name: Upload Linux Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linux-build path: 'Whisper.net.Run*/linux-*/*' diff --git a/.github/workflows/linux-openvino-build.yml b/.github/workflows/linux-openvino-build.yml index 9d18960d..6bce861d 100644 --- a/.github/workflows/linux-openvino-build.yml +++ b/.github/workflows/linux-openvino-build.yml @@ -29,7 +29,7 @@ jobs: make linux_x64_openvino - name: Upload Linux OpenVino Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linux-openvino-build path: 'Whisper.net.Run*/linux-*/*' diff --git a/.github/workflows/macos-coreml-native-build.yml b/.github/workflows/macos-coreml-native-build.yml new file mode 100644 index 00000000..4e9dfe0e --- /dev/null +++ b/.github/workflows/macos-coreml-native-build.yml @@ -0,0 +1,28 @@ + +name: MacOs CoreML Native build + +on: + workflow_dispatch: + workflow_call: + + +jobs: + build: + runs-on: macos-14 + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + ref: ${{ github.head_ref }} + + - name: Run apple coreml build for arm + run: make apple_coreml_arm + + - name: Upload CoreML Mac Arm Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: mac-coreml-arm-build + path: | + Whisper.net.Run*/*/* + Whisper.net.Run*/*.metal diff --git a/.github/workflows/macos-native-build.yml b/.github/workflows/macos-native-build.yml index 77f55de0..e9e45c46 100644 --- a/.github/workflows/macos-native-build.yml +++ b/.github/workflows/macos-native-build.yml @@ -23,7 +23,7 @@ jobs: run: make apple_x64 - name: Upload Mac Intel Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: mac-intel-build path: | @@ -41,12 +41,9 @@ jobs: - name: Run apple build for arm run: make apple_arm - - - name: Run apple coreml build for arm - run: make apple_coreml_arm - name: Upload Mac Arm Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: mac-arm-build path: | diff --git a/.github/workflows/wasm-native-build.yml b/.github/workflows/wasm-native-build.yml index 522c781a..3ce13440 100644 --- a/.github/workflows/wasm-native-build.yml +++ b/.github/workflows/wasm-native-build.yml @@ -26,7 +26,7 @@ jobs: run: rm -rf emsdk* - name: Upload Wasm Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: wasm-build path: 'Whisper.net.Run*/browser-wasm/*' diff --git a/.github/workflows/windows-arm-native-build.yml b/.github/workflows/windows-arm-native-build.yml index 91a1ea18..8cf1eef9 100644 --- a/.github/workflows/windows-arm-native-build.yml +++ b/.github/workflows/windows-arm-native-build.yml @@ -25,7 +25,7 @@ jobs: shell: pwsh - name: Upload Windows Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: windows-arm-build path: 'Whisper.net.Run*/win-*/*' diff --git a/.github/workflows/windows-cuda-native-build.yml b/.github/workflows/windows-cuda-native-build.yml index d6c064bf..77b562d0 100644 --- a/.github/workflows/windows-cuda-native-build.yml +++ b/.github/workflows/windows-cuda-native-build.yml @@ -38,7 +38,7 @@ jobs: run: Remove-Item -Path 'cuda_installer-*' -Recurse -Force -ErrorAction Ignore - name: Upload Windows Cuda Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: windows-cuda-build path: 'Whisper.net.Run*/win-*/*' diff --git a/.github/workflows/windows-native-build.yml b/.github/workflows/windows-native-build.yml index 3f647644..c7ec2785 100644 --- a/.github/workflows/windows-native-build.yml +++ b/.github/workflows/windows-native-build.yml @@ -27,7 +27,7 @@ jobs: shell: pwsh - name: Upload Windows Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: windows-build path: 'Whisper.net.Run*/win-*/*' @@ -52,7 +52,7 @@ jobs: shell: pwsh - name: Upload Windows Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: windows-arm-build path: 'Whisper.net.Run*/win-*/*' diff --git a/.github/workflows/windows-openvino-build.yml b/.github/workflows/windows-openvino-native-build.yml similarity index 96% rename from .github/workflows/windows-openvino-build.yml rename to .github/workflows/windows-openvino-native-build.yml index 0ec58309..3c0432fa 100644 --- a/.github/workflows/windows-openvino-build.yml +++ b/.github/workflows/windows-openvino-native-build.yml @@ -27,7 +27,7 @@ jobs: shell: pwsh - name: Upload Windows OpenVino Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: windows-openvino-build path: 'Whisper.net.Run*/win-*/*' diff --git a/.github/workflows/windows-vulkan-build.yml b/.github/workflows/windows-vulkan-native-build.yml similarity index 95% rename from .github/workflows/windows-vulkan-build.yml rename to .github/workflows/windows-vulkan-native-build.yml index 9359d7ae..efa78d0b 100644 --- a/.github/workflows/windows-vulkan-build.yml +++ b/.github/workflows/windows-vulkan-native-build.yml @@ -33,7 +33,7 @@ jobs: shell: pwsh - name: Upload Windows Vulkan Build Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: windows-vulkan-build path: 'Whisper.net.Run*/win-*/*' diff --git a/Whisper.net.sln b/Whisper.net.sln index 7b62e07f..133bf7e1 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -19,18 +19,19 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C865649-4AED-4BBF-A7CA-BD68D21EF48F}" ProjectSection(SolutionItems) = preProject .github\workflows\android-native-build.yml = .github\workflows\android-native-build.yml - .github\workflows\cpu-build-and-test.yml = .github\workflows\cpu-build-and-test.yml .github\workflows\dotnet.yml = .github\workflows\dotnet.yml + .github\workflows\build-all.yml = .github\workflows\build-all.yml .github\workflows\linux-cuda-native-build.yml = .github\workflows\linux-cuda-native-build.yml .github\workflows\linux-native-build.yml = .github\workflows\linux-native-build.yml .github\workflows\linux-openvino-build.yml = .github\workflows\linux-openvino-build.yml + .github\workflows\macos-coreml-native-build.yml = .github\workflows\macos-coreml-native-build.yml .github\workflows\macos-native-build.yml = .github\workflows\macos-native-build.yml .github\workflows\wasm-native-build.yml = .github\workflows\wasm-native-build.yml .github\workflows\windows-arm-native-build.yml = .github\workflows\windows-arm-native-build.yml .github\workflows\windows-cuda-native-build.yml = .github\workflows\windows-cuda-native-build.yml .github\workflows\windows-native-build.yml = .github\workflows\windows-native-build.yml - .github\workflows\windows-openvino-build.yml = .github\workflows\windows-openvino-build.yml - .github\workflows\windows-vulkan-build.yml = .github\workflows\windows-vulkan-build.yml + .github\workflows\windows-vulkan-native-build.yml = .github\workflows\windows-vulkan-native-build.yml + .github\workflows\windows-openvino-native-build.yml = .github\workflows\windows-openvino-native-build.yml EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{52C6C243-3BD7-41CF-A0B0-1DE31AC2C884}" diff --git a/nuget.config b/nuget.config index 1c540ce2..70f6b824 100644 --- a/nuget.config +++ b/nuget.config @@ -1,8 +1,8 @@ - + - + From 0159c28a030adc5bc812d9dbf867f54cc8871f8a Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 17:26:52 +0200 Subject: [PATCH 12/79] added workflow_call: --- .github/workflows/linux-cuda-native-build.yml | 1 + .github/workflows/linux-openvino-build.yml | 1 + .../workflows/windows-arm-native-build.yml | 31 ------------------- .../workflows/windows-cuda-native-build.yml | 1 + .../windows-openvino-native-build.yml | 1 + .../workflows/windows-vulkan-native-build.yml | 1 + Whisper.net.sln | 1 - 7 files changed, 5 insertions(+), 32 deletions(-) delete mode 100644 .github/workflows/windows-arm-native-build.yml diff --git a/.github/workflows/linux-cuda-native-build.yml b/.github/workflows/linux-cuda-native-build.yml index 13207b54..d51830af 100644 --- a/.github/workflows/linux-cuda-native-build.yml +++ b/.github/workflows/linux-cuda-native-build.yml @@ -2,6 +2,7 @@ name: Linux Cuda Native build on: workflow_dispatch: + workflow_call: jobs: diff --git a/.github/workflows/linux-openvino-build.yml b/.github/workflows/linux-openvino-build.yml index 6bce861d..033c2c12 100644 --- a/.github/workflows/linux-openvino-build.yml +++ b/.github/workflows/linux-openvino-build.yml @@ -2,6 +2,7 @@ name: Linux OpenVino native build on: workflow_dispatch: + workflow_call: jobs: build: diff --git a/.github/workflows/windows-arm-native-build.yml b/.github/workflows/windows-arm-native-build.yml deleted file mode 100644 index 8cf1eef9..00000000 --- a/.github/workflows/windows-arm-native-build.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Windows ARM native build - -on: - workflow_dispatch: - - -jobs: - build: - - runs-on: windows-latest - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - ref: ${{ github.head_ref }} - - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1 - - - name: Run Build - run: | - Import-Module ./windows-scripts.ps1 - BuildWindowsArm - shell: pwsh - - - name: Upload Windows Build Artifacts - uses: actions/upload-artifact@v4 - with: - name: windows-arm-build - path: 'Whisper.net.Run*/win-*/*' diff --git a/.github/workflows/windows-cuda-native-build.yml b/.github/workflows/windows-cuda-native-build.yml index 77b562d0..16fa0e9e 100644 --- a/.github/workflows/windows-cuda-native-build.yml +++ b/.github/workflows/windows-cuda-native-build.yml @@ -2,6 +2,7 @@ name: Windows Cuda native build on: workflow_dispatch: + workflow_call: jobs: diff --git a/.github/workflows/windows-openvino-native-build.yml b/.github/workflows/windows-openvino-native-build.yml index 3c0432fa..ea2e1e95 100644 --- a/.github/workflows/windows-openvino-native-build.yml +++ b/.github/workflows/windows-openvino-native-build.yml @@ -2,6 +2,7 @@ name: Windows OpenVino native build on: workflow_dispatch: + workflow_call: jobs: build: diff --git a/.github/workflows/windows-vulkan-native-build.yml b/.github/workflows/windows-vulkan-native-build.yml index efa78d0b..39a08753 100644 --- a/.github/workflows/windows-vulkan-native-build.yml +++ b/.github/workflows/windows-vulkan-native-build.yml @@ -2,6 +2,7 @@ name: Windows Vulkan native build on: workflow_dispatch: + workflow_call: jobs: build: diff --git a/Whisper.net.sln b/Whisper.net.sln index 133bf7e1..6bf7351e 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -27,7 +27,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C8656 .github\workflows\macos-coreml-native-build.yml = .github\workflows\macos-coreml-native-build.yml .github\workflows\macos-native-build.yml = .github\workflows\macos-native-build.yml .github\workflows\wasm-native-build.yml = .github\workflows\wasm-native-build.yml - .github\workflows\windows-arm-native-build.yml = .github\workflows\windows-arm-native-build.yml .github\workflows\windows-cuda-native-build.yml = .github\workflows\windows-cuda-native-build.yml .github\workflows\windows-native-build.yml = .github\workflows\windows-native-build.yml .github\workflows\windows-vulkan-native-build.yml = .github\workflows\windows-vulkan-native-build.yml From d4b8862a72c8e46295fc9f4e5bf50374db6f78b1 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 17:27:40 +0200 Subject: [PATCH 13/79] Fixed linux-openvino-native-build.yml --- ...linux-openvino-build.yml => linux-openvino-native-build.yml} | 0 Whisper.net.sln | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{linux-openvino-build.yml => linux-openvino-native-build.yml} (100%) diff --git a/.github/workflows/linux-openvino-build.yml b/.github/workflows/linux-openvino-native-build.yml similarity index 100% rename from .github/workflows/linux-openvino-build.yml rename to .github/workflows/linux-openvino-native-build.yml diff --git a/Whisper.net.sln b/Whisper.net.sln index 6bf7351e..c5a7e980 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -23,8 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C8656 .github\workflows\build-all.yml = .github\workflows\build-all.yml .github\workflows\linux-cuda-native-build.yml = .github\workflows\linux-cuda-native-build.yml .github\workflows\linux-native-build.yml = .github\workflows\linux-native-build.yml - .github\workflows\linux-openvino-build.yml = .github\workflows\linux-openvino-build.yml .github\workflows\macos-coreml-native-build.yml = .github\workflows\macos-coreml-native-build.yml + .github\workflows\linux-openvino-native-build.yml = .github\workflows\linux-openvino-native-build.yml .github\workflows\macos-native-build.yml = .github\workflows\macos-native-build.yml .github\workflows\wasm-native-build.yml = .github\workflows\wasm-native-build.yml .github\workflows\windows-cuda-native-build.yml = .github\workflows\windows-cuda-native-build.yml From 67cc3ccff28947a93528699ee14fc4d75f2e426b Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 21:31:37 +0200 Subject: [PATCH 14/79] a --- .github/workflows/android-native-build.yml | 1 + .github/workflows/build-all.yml | 24 +++++++++---------- .github/workflows/dotnet.yml | 10 +++++++- .github/workflows/linux-cuda-native-build.yml | 1 + .github/workflows/linux-native-build.yml | 1 + .../workflows/linux-openvino-native-build.yml | 1 + .../workflows/macos-coreml-native-build.yml | 1 + .github/workflows/macos-native-build.yml | 2 ++ .github/workflows/wasm-native-build.yml | 1 + .../workflows/windows-cuda-native-build.yml | 3 ++- .github/workflows/windows-native-build.yml | 6 +++-- .../windows-openvino-native-build.yml | 3 ++- .../workflows/windows-vulkan-native-build.yml | 3 ++- 13 files changed, 39 insertions(+), 18 deletions(-) diff --git a/.github/workflows/android-native-build.yml b/.github/workflows/android-native-build.yml index 2b62ffa7..dd6cbdae 100644 --- a/.github/workflows/android-native-build.yml +++ b/.github/workflows/android-native-build.yml @@ -30,3 +30,4 @@ jobs: with: name: android-build path: 'Whisper.net.Run*/android-*/*' + retention-days: 7 diff --git a/.github/workflows/build-all.yml b/.github/workflows/build-all.yml index feb77de8..df7b9aca 100644 --- a/.github/workflows/build-all.yml +++ b/.github/workflows/build-all.yml @@ -26,23 +26,23 @@ jobs: linux: uses: ./.github/workflows/linux-native-build.yml - windows-cuda: - uses: ./.github/workflows/windows-cuda-native-build.yml + # windows-cuda: + # uses: ./.github/workflows/windows-cuda-native-build.yml - windows-vulkan: - uses: ./.github/workflows/windows-vulkan-native-build.yml + # windows-vulkan: + # uses: ./.github/workflows/windows-vulkan-native-build.yml - windows-openvino: - uses: ./.github/workflows/windows-openvino-native-build.yml + # windows-openvino: + # uses: ./.github/workflows/windows-openvino-native-build.yml - linux-cuda: - uses: ./.github/workflows/linux-cuda-native-build.yml + # linux-cuda: + # uses: ./.github/workflows/linux-cuda-native-build.yml - linux-openvino: - uses: ./.github/workflows/linux-openvino-native-build.yml + # linux-openvino: + # uses: ./.github/workflows/linux-openvino-native-build.yml - macos-coreml: - uses: ./.github/workflows/macos-coreml-native-build.yml + # macos-coreml: + # uses: ./.github/workflows/macos-coreml-native-build.yml dotnet-build: needs: diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 2b2f0ed9..737d82c9 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -69,7 +69,15 @@ jobs: - name: Build run: dotnet build ./Whisper.net.sln --no-restore -warnaserror - + + - name: Check the runtime library + run: | + ls -l Whisper.net.Tests/bin/Debug/net8.0 + ls -l Whisper.net.Tests/bin/Debug/net8.0/runtimes + ls -l Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64 + ldd Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libwhisper.so + ldd Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libggml.so + - name: Test run: | dotnet test ./Whisper.net.sln --no-build diff --git a/.github/workflows/linux-cuda-native-build.yml b/.github/workflows/linux-cuda-native-build.yml index d51830af..975d5e29 100644 --- a/.github/workflows/linux-cuda-native-build.yml +++ b/.github/workflows/linux-cuda-native-build.yml @@ -38,3 +38,4 @@ jobs: with: name: linux-build path: 'Whisper.net.Run*/linux-*/*' + retention-days: 7 diff --git a/.github/workflows/linux-native-build.yml b/.github/workflows/linux-native-build.yml index c35e4c22..32b112fd 100644 --- a/.github/workflows/linux-native-build.yml +++ b/.github/workflows/linux-native-build.yml @@ -30,3 +30,4 @@ jobs: with: name: linux-build path: 'Whisper.net.Run*/linux-*/*' + retention-days: 7 diff --git a/.github/workflows/linux-openvino-native-build.yml b/.github/workflows/linux-openvino-native-build.yml index 033c2c12..c039ce00 100644 --- a/.github/workflows/linux-openvino-native-build.yml +++ b/.github/workflows/linux-openvino-native-build.yml @@ -34,3 +34,4 @@ jobs: with: name: linux-openvino-build path: 'Whisper.net.Run*/linux-*/*' + retention-days: 7 diff --git a/.github/workflows/macos-coreml-native-build.yml b/.github/workflows/macos-coreml-native-build.yml index 4e9dfe0e..b90a084f 100644 --- a/.github/workflows/macos-coreml-native-build.yml +++ b/.github/workflows/macos-coreml-native-build.yml @@ -26,3 +26,4 @@ jobs: path: | Whisper.net.Run*/*/* Whisper.net.Run*/*.metal + retention-days: 7 diff --git a/.github/workflows/macos-native-build.yml b/.github/workflows/macos-native-build.yml index e9e45c46..51cd185f 100644 --- a/.github/workflows/macos-native-build.yml +++ b/.github/workflows/macos-native-build.yml @@ -29,6 +29,7 @@ jobs: path: | Whisper.net.Run*/*/* Whisper.net.Run*/*.metal + retention-days: 7 arm-build: runs-on: macos-14 @@ -49,3 +50,4 @@ jobs: path: | Whisper.net.Run*/*/* Whisper.net.Run*/*.metal + retention-days: 7 diff --git a/.github/workflows/wasm-native-build.yml b/.github/workflows/wasm-native-build.yml index 3ce13440..cd1e1061 100644 --- a/.github/workflows/wasm-native-build.yml +++ b/.github/workflows/wasm-native-build.yml @@ -30,3 +30,4 @@ jobs: with: name: wasm-build path: 'Whisper.net.Run*/browser-wasm/*' + retention-days: 7 diff --git a/.github/workflows/windows-cuda-native-build.yml b/.github/workflows/windows-cuda-native-build.yml index 16fa0e9e..e5840de3 100644 --- a/.github/workflows/windows-cuda-native-build.yml +++ b/.github/workflows/windows-cuda-native-build.yml @@ -18,7 +18,7 @@ jobs: ref: ${{ github.head_ref }} - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1 + uses: microsoft/setup-msbuild@v2 - name: Install OpenCl with vcpkg run: | @@ -43,3 +43,4 @@ jobs: with: name: windows-cuda-build path: 'Whisper.net.Run*/win-*/*' + retention-days: 7 diff --git a/.github/workflows/windows-native-build.yml b/.github/workflows/windows-native-build.yml index c7ec2785..3dcda36d 100644 --- a/.github/workflows/windows-native-build.yml +++ b/.github/workflows/windows-native-build.yml @@ -18,7 +18,7 @@ jobs: ref: ${{ github.head_ref }} - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1 + uses: microsoft/setup-msbuild@v2 - name: Run Build run: | @@ -31,6 +31,7 @@ jobs: with: name: windows-build path: 'Whisper.net.Run*/win-*/*' + retention-days: 7 arm-build: @@ -43,7 +44,7 @@ jobs: ref: ${{ github.head_ref }} - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1 + uses: microsoft/setup-msbuild@v2 - name: Run Build run: | @@ -56,3 +57,4 @@ jobs: with: name: windows-arm-build path: 'Whisper.net.Run*/win-*/*' + retention-days: 7 diff --git a/.github/workflows/windows-openvino-native-build.yml b/.github/workflows/windows-openvino-native-build.yml index ea2e1e95..12a206bf 100644 --- a/.github/workflows/windows-openvino-native-build.yml +++ b/.github/workflows/windows-openvino-native-build.yml @@ -16,7 +16,7 @@ jobs: ref: ${{ github.head_ref }} - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1 + uses: microsoft/setup-msbuild@v2 - name: Run Build run: | @@ -32,3 +32,4 @@ jobs: with: name: windows-openvino-build path: 'Whisper.net.Run*/win-*/*' + retention-days: 7 diff --git a/.github/workflows/windows-vulkan-native-build.yml b/.github/workflows/windows-vulkan-native-build.yml index 39a08753..8b7b387e 100644 --- a/.github/workflows/windows-vulkan-native-build.yml +++ b/.github/workflows/windows-vulkan-native-build.yml @@ -16,7 +16,7 @@ jobs: ref: ${{ github.head_ref }} - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1 + uses: microsoft/setup-msbuild@v2 - name: Install Vulkan SDK uses: jakoch/install-vulkan-sdk-action@v1.0.4 @@ -38,3 +38,4 @@ jobs: with: name: windows-vulkan-build path: 'Whisper.net.Run*/win-*/*' + retention-days: 7 From 324e4e2085074e23052ac5e8bbaea95c22f02be1 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 21:43:28 +0200 Subject: [PATCH 15/79] Try to fix --- Whisper.net/LibraryLoader/ILibraryLoader.cs | 2 +- Whisper.net/LibraryLoader/LinuxLibraryLoader.cs | 6 +++--- Whisper.net/LibraryLoader/MacOsLibraryLoader.cs | 4 ++-- Whisper.net/LibraryLoader/NativeLibraryLoader.cs | 7 +++++-- Whisper.net/LibraryLoader/WindowsLibraryLoader.cs | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Whisper.net/LibraryLoader/ILibraryLoader.cs b/Whisper.net/LibraryLoader/ILibraryLoader.cs index 5a21bef1..894aee3b 100644 --- a/Whisper.net/LibraryLoader/ILibraryLoader.cs +++ b/Whisper.net/LibraryLoader/ILibraryLoader.cs @@ -4,5 +4,5 @@ namespace Whisper.net.LibraryLoader; internal interface ILibraryLoader { - LoadResult OpenLibrary(string? fileName); + LoadResult OpenLibrary(string? fileName, bool global); } diff --git a/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs b/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs index 18573cdd..ea4160fe 100644 --- a/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs @@ -18,17 +18,17 @@ internal class LinuxLibraryLoader : ILibraryLoader [DllImport("libdl.so.2", ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = "dlerror")] public static extern IntPtr GetLoadError2(); - public LoadResult OpenLibrary(string? fileName) + public LoadResult OpenLibrary(string? fileName, bool global) { IntPtr loadedLib; try { // open with rtls lazy flag - loadedLib = NativeOpenLibraryLibdl2(fileName, 0x00001); + loadedLib = NativeOpenLibraryLibdl2(fileName, global ? 0x00102 : 0x00002); } catch (DllNotFoundException) { - loadedLib = NativeOpenLibraryLibdl(fileName, 0x00001); + loadedLib = NativeOpenLibraryLibdl(fileName, global ? 0x00102 : 0x00002); } if (loadedLib == IntPtr.Zero) diff --git a/Whisper.net/LibraryLoader/MacOsLibraryLoader.cs b/Whisper.net/LibraryLoader/MacOsLibraryLoader.cs index 3e115b11..b6bfca41 100644 --- a/Whisper.net/LibraryLoader/MacOsLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/MacOsLibraryLoader.cs @@ -12,9 +12,9 @@ internal class MacOsLibraryLoader : ILibraryLoader [DllImport("libdl.dylib", ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = "dlerror")] public static extern IntPtr GetLoadError(); - public LoadResult OpenLibrary(string? fileName) + public LoadResult OpenLibrary(string? fileName, bool global) { - var loadedLib = NativeOpenLibraryLibdl(fileName, 0x00001); + var loadedLib = NativeOpenLibraryLibdl(fileName, global ? 0x00102 : 0x00001); if (loadedLib == IntPtr.Zero) { diff --git a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs index 325bc114..7e22ed00 100644 --- a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs @@ -50,7 +50,9 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", continue; } - var ggmlLoadResult = libraryLoader.OpenLibrary(ggmlPath); + var ggmlLoadResult = libraryLoader.OpenLibrary(ggmlPath, global: true); + + Console.WriteLine($"Success loaded ggml: {ggmlLoadResult.IsSuccess} --- Error message: {ggmlLoadResult.ErrorMessage}" ); // Maybe GPU is not available but we still have other runtime installed if (!ggmlLoadResult.IsSuccess) @@ -61,7 +63,8 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", // Ggml was loaded, for this runtimePath, we need to load whisper as well var whisperPath = GetLibraryPath(platform, "whisper", runtimePath); - var whisperLoaded = libraryLoader.OpenLibrary(whisperPath); + var whisperLoaded = libraryLoader.OpenLibrary(whisperPath, global: false); + Console.WriteLine($"Success loaded whisper: {whisperLoaded.IsSuccess} --- Error message: {whisperLoaded.ErrorMessage}"); if (whisperLoaded.IsSuccess) { diff --git a/Whisper.net/LibraryLoader/WindowsLibraryLoader.cs b/Whisper.net/LibraryLoader/WindowsLibraryLoader.cs index 0d346ee9..5f3e3853 100644 --- a/Whisper.net/LibraryLoader/WindowsLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/WindowsLibraryLoader.cs @@ -7,7 +7,7 @@ namespace Whisper.net.LibraryLoader; internal class WindowsLibraryLoader : ILibraryLoader { - public LoadResult OpenLibrary(string? fileName) + public LoadResult OpenLibrary(string? fileName, bool global) { var loadedLib = LoadLibrary(fileName); From efdd699558eb3be4c94ac14e217ad4837d3bc15a Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 21:53:04 +0200 Subject: [PATCH 16/79] Try again --- Whisper.net/LibraryLoader/LinuxLibraryLoader.cs | 2 +- Whisper.net/LibraryLoader/NativeLibraryLoader.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs b/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs index ea4160fe..fa210506 100644 --- a/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs @@ -23,7 +23,7 @@ public LoadResult OpenLibrary(string? fileName, bool global) IntPtr loadedLib; try { - // open with rtls lazy flag + // open with rtld now + (global if true) loadedLib = NativeOpenLibraryLibdl2(fileName, global ? 0x00102 : 0x00002); } catch (DllNotFoundException) diff --git a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs index 7e22ed00..10f6907c 100644 --- a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs @@ -63,7 +63,7 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", // Ggml was loaded, for this runtimePath, we need to load whisper as well var whisperPath = GetLibraryPath(platform, "whisper", runtimePath); - var whisperLoaded = libraryLoader.OpenLibrary(whisperPath, global: false); + var whisperLoaded = libraryLoader.OpenLibrary(whisperPath, global: true); Console.WriteLine($"Success loaded whisper: {whisperLoaded.IsSuccess} --- Error message: {whisperLoaded.ErrorMessage}"); if (whisperLoaded.IsSuccess) From 8fd057069d4dfc3217acf58c7879f048af2112b0 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 22:06:44 +0200 Subject: [PATCH 17/79] Again --- .github/workflows/dotnet.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 737d82c9..736b1be9 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -58,7 +58,10 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: 8.0.x - + + - name: Install strace + run: sudo apt-get install strace + - name: Download Artifacts id: download-artifact uses: actions/download-artifact@v4 @@ -72,12 +75,12 @@ jobs: - name: Check the runtime library run: | - ls -l Whisper.net.Tests/bin/Debug/net8.0 - ls -l Whisper.net.Tests/bin/Debug/net8.0/runtimes - ls -l Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64 + echo 'ldd whisper:' ldd Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libwhisper.so + echo 'ldd ggml:' ldd Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libggml.so - name: Test run: | - dotnet test ./Whisper.net.sln --no-build + strace -f -e trace=open,read,write,dlopen dotnet test ./Whisper.net.sln --no-build + From 3f52c545434058341a0f8cdb82e1ae1c38f8c6d9 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 22:12:27 +0200 Subject: [PATCH 18/79] Otra vez --- .github/workflows/dotnet.yml | 65 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 736b1be9..53dad86a 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -7,46 +7,46 @@ on: workflow_call: jobs: - dotnet-windows: + # dotnet-windows: - runs-on: windows-latest + # runs-on: windows-latest - steps: - - uses: actions/checkout@v3 + # steps: + # - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.0.x + # - name: Setup .NET + # uses: actions/setup-dotnet@v3 + # with: + # dotnet-version: 8.0.x - - name: Download Artifacts - id: download-artifact - uses: actions/download-artifact@v4 - with: - merge-multiple: true + # - name: Download Artifacts + # id: download-artifact + # uses: actions/download-artifact@v4 + # with: + # merge-multiple: true - - name: Install Java - uses: actions/setup-java@v2 - with: - distribution: 'microsoft' - java-version: '11' + # - name: Install Java + # uses: actions/setup-java@v2 + # with: + # distribution: 'microsoft' + # java-version: '11' - - name: Install .NET Workloads - run: | - dotnet workload install android --ignore-failed-sources - dotnet workload install ios --ignore-failed-sources - dotnet workload install tvos --ignore-failed-sources - dotnet workload install maccatalyst --ignore-failed-sources + # - name: Install .NET Workloads + # run: | + # dotnet workload install android --ignore-failed-sources + # dotnet workload install ios --ignore-failed-sources + # dotnet workload install tvos --ignore-failed-sources + # dotnet workload install maccatalyst --ignore-failed-sources - - name: Restore dependencies - run: dotnet restore ./Whisper.net.sln + # - name: Restore dependencies + # run: dotnet restore ./Whisper.net.sln - - name: Build - run: dotnet build ./Whisper.net.sln --no-restore -warnaserror + # - name: Build + # run: dotnet build ./Whisper.net.sln --no-restore -warnaserror - - name: Test - run: | - dotnet test ./Whisper.net.sln --no-build + # - name: Test + # run: | + # dotnet test ./Whisper.net.sln --no-build dotnet-linux: runs-on: ubuntu-latest @@ -82,5 +82,6 @@ jobs: - name: Test run: | - strace -f -e trace=open,read,write,dlopen dotnet test ./Whisper.net.sln --no-build + export LD_DEBUG=all + strace -f -e trace=all dotnet test ./Whisper.net.sln --no-build From 1385471c43b1c92789dd247b509dd34eb64bb6cf Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 22:26:37 +0200 Subject: [PATCH 19/79] Removed strace --- .github/workflows/dotnet.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 53dad86a..56b80ac6 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -72,16 +72,9 @@ jobs: - name: Build run: dotnet build ./Whisper.net.sln --no-restore -warnaserror - - - name: Check the runtime library - run: | - echo 'ldd whisper:' - ldd Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libwhisper.so - echo 'ldd ggml:' - ldd Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libggml.so - + - name: Test run: | export LD_DEBUG=all - strace -f -e trace=all dotnet test ./Whisper.net.sln --no-build + dotnet test ./Whisper.net.sln --no-build From 5658ff593395a845cb7cf88568cced5025499ef2 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 22:39:32 +0200 Subject: [PATCH 20/79] Tried to change the libraryName temp --- .github/workflows/dotnet.yml | 5 +---- Whisper.net/Internals/Native/GgmlNativeMethods.cs | 2 +- Whisper.net/Internals/Native/NativeMethods.cs | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 56b80ac6..64fd88ac 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -58,10 +58,7 @@ jobs: uses: actions/setup-dotnet@v3 with: dotnet-version: 8.0.x - - - name: Install strace - run: sudo apt-get install strace - + - name: Download Artifacts id: download-artifact uses: actions/download-artifact@v4 diff --git a/Whisper.net/Internals/Native/GgmlNativeMethods.cs b/Whisper.net/Internals/Native/GgmlNativeMethods.cs index d828bcc0..b119286b 100644 --- a/Whisper.net/Internals/Native/GgmlNativeMethods.cs +++ b/Whisper.net/Internals/Native/GgmlNativeMethods.cs @@ -9,7 +9,7 @@ internal static class GgmlNativeMethods #if IOS || MACCATALYST || TVOS const string libraryName = "__Internal"; #else - const string libraryName = "ggml"; + const string libraryName = "libggml.so"; #endif [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] diff --git a/Whisper.net/Internals/Native/NativeMethods.cs b/Whisper.net/Internals/Native/NativeMethods.cs index d54c95e5..45b3c7ec 100644 --- a/Whisper.net/Internals/Native/NativeMethods.cs +++ b/Whisper.net/Internals/Native/NativeMethods.cs @@ -10,7 +10,7 @@ internal static class NativeMethods #if IOS || MACCATALYST || TVOS const string libraryName = "__Internal"; #else - const string libraryName = "whisper"; + const string libraryName = "libwhisper.so"; #endif [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] From b5c93e2ffce40bc20ca30cbaac3fa50f8d2b46f8 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 22:49:38 +0200 Subject: [PATCH 21/79] Again --- .github/workflows/dotnet.yml | 1 - .github/workflows/linux-native-build.yml | 3 +++ Makefile | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 64fd88ac..a91c7cc2 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -72,6 +72,5 @@ jobs: - name: Test run: | - export LD_DEBUG=all dotnet test ./Whisper.net.sln --no-build diff --git a/.github/workflows/linux-native-build.yml b/.github/workflows/linux-native-build.yml index 32b112fd..d19d87e9 100644 --- a/.github/workflows/linux-native-build.yml +++ b/.github/workflows/linux-native-build.yml @@ -22,6 +22,9 @@ jobs: - name: Install gcc-arm-linux-gnueabihf run: sudo apt-get update && sudo apt-get install -y gcc-arm-linux-gnueabihf && sudo apt-get install -y g++-arm-linux-gnueabihf + - name: Install patchelf + run: sudo apt-get update && sudo apt-get install -y patchelf + - name: Run linux run: make linux diff --git a/Makefile b/Makefile index 7661c834..38741e55 100644 --- a/Makefile +++ b/Makefile @@ -58,6 +58,7 @@ linux_x64: cmake --build build/linux-x64 --config $(BUILD_TYPE) mkdir -p Whisper.net.Runtime/linux-x64 cp build/linux-x64/whisper.cpp/src/libwhisper.so ./Whisper.net.Runtime/linux-x64/libwhisper.so + patchelf --set-rpath '$ORIGIN' ./Whisper.net.Runtime/linux-x64/libwhisper.so' cp build/linux-x64/whisper.cpp/ggml/src/libggml.so ./Whisper.net.Runtime/linux-x64/libggml.so linux_arm64: From 69608707d7283d0d248b8d50bf0454e2163087b4 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 22:52:43 +0200 Subject: [PATCH 22/79] aaa --- .github/workflows/dotnet.yml | 9 ++++++++- Makefile | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index a91c7cc2..ad6109da 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -69,7 +69,14 @@ jobs: - name: Build run: dotnet build ./Whisper.net.sln --no-restore -warnaserror - + + - name: Check LDD for libwhisper + run: | + echo 'Checking ldd for libwhisper.so' + ldd ./Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libwhisper.so + echo 'Checking ldd for libggml.so' + ldd ./Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libggml.so + - name: Test run: | dotnet test ./Whisper.net.sln --no-build diff --git a/Makefile b/Makefile index 38741e55..a5c03846 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ linux_x64: cmake --build build/linux-x64 --config $(BUILD_TYPE) mkdir -p Whisper.net.Runtime/linux-x64 cp build/linux-x64/whisper.cpp/src/libwhisper.so ./Whisper.net.Runtime/linux-x64/libwhisper.so - patchelf --set-rpath '$ORIGIN' ./Whisper.net.Runtime/linux-x64/libwhisper.so' + patchelf --set-rpath '$$ORIGIN' ./Whisper.net.Runtime/linux-x64/libwhisper.so' cp build/linux-x64/whisper.cpp/ggml/src/libggml.so ./Whisper.net.Runtime/linux-x64/libggml.so linux_arm64: From 1f0e67e40b6ed6e48b2df12991804484f76488e2 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 22:54:54 +0200 Subject: [PATCH 23/79] ffs --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a5c03846..04ed03fb 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ linux_x64: cmake --build build/linux-x64 --config $(BUILD_TYPE) mkdir -p Whisper.net.Runtime/linux-x64 cp build/linux-x64/whisper.cpp/src/libwhisper.so ./Whisper.net.Runtime/linux-x64/libwhisper.so - patchelf --set-rpath '$$ORIGIN' ./Whisper.net.Runtime/linux-x64/libwhisper.so' + patchelf --set-rpath '$$ORIGIN' ./Whisper.net.Runtime/linux-x64/libwhisper.so cp build/linux-x64/whisper.cpp/ggml/src/libggml.so ./Whisper.net.Runtime/linux-x64/libggml.so linux_arm64: From bf95c44b1ef026eb282188a4904cc244bb2af99d Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 23:14:14 +0200 Subject: [PATCH 24/79] a --- Whisper.net/LibraryLoader/NativeLibraryLoader.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs index 10f6907c..54b5680b 100644 --- a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs @@ -14,11 +14,11 @@ internal static LoadResult LoadNativeLibrary() return LoadResult.Success; #else // If the user has handled loading the library themselves, we don't need to do anything. - if (RuntimeOptions.Instance.BypassLoading || RuntimeInformation.OSArchitecture.ToString().Equals("wasm", StringComparison.OrdinalIgnoreCase)) + if (RuntimeOptions.Instance.BypassLoading + || RuntimeInformation.OSArchitecture.ToString().Equals("wasm", StringComparison.OrdinalIgnoreCase)) { return LoadResult.Success; } - return LoadLibraryComponent(); } @@ -49,11 +49,10 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", { continue; } + var whisperPath = GetLibraryPath(platform, "whisper", runtimePath); +#if NETSTANDARD2_0 var ggmlLoadResult = libraryLoader.OpenLibrary(ggmlPath, global: true); - - Console.WriteLine($"Success loaded ggml: {ggmlLoadResult.IsSuccess} --- Error message: {ggmlLoadResult.ErrorMessage}" ); - // Maybe GPU is not available but we still have other runtime installed if (!ggmlLoadResult.IsSuccess) { @@ -62,8 +61,12 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", } // Ggml was loaded, for this runtimePath, we need to load whisper as well - var whisperPath = GetLibraryPath(platform, "whisper", runtimePath); var whisperLoaded = libraryLoader.OpenLibrary(whisperPath, global: true); +#else + var nativeLibraryLoaded = NativeLibrary.Load(whisperPath, typeof(NativeLibraryLoader).Assembly, DllImportSearchPath.UseDllDirectoryForDependencies); + var whisperLoaded = nativeLibraryLoaded != IntPtr.Zero ? LoadResult.Success : LoadResult.Failure("Cannot load the library"); +#endif + Console.WriteLine($"Success loaded whisper: {whisperLoaded.IsSuccess} --- Error message: {whisperLoaded.ErrorMessage}"); if (whisperLoaded.IsSuccess) From bdb1eb233ebe813557283bd0c2403862e5a99b4a Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 23:22:31 +0200 Subject: [PATCH 25/79] aaa --- .../LibraryLoader/NativeLibraryLoader.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs index 54b5680b..54087031 100644 --- a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs @@ -1,5 +1,6 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT #if !IOS && !MACCATALYST && !TVOS && !ANDROID +using System.Reflection; using System.Runtime.InteropServices; using Whisper.net.Native; #endif @@ -65,6 +66,22 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", #else var nativeLibraryLoaded = NativeLibrary.Load(whisperPath, typeof(NativeLibraryLoader).Assembly, DllImportSearchPath.UseDllDirectoryForDependencies); var whisperLoaded = nativeLibraryLoaded != IntPtr.Zero ? LoadResult.Success : LoadResult.Failure("Cannot load the library"); + Console.WriteLine("Whisper loaded: {0}", nativeLibraryLoaded); + if (whisperLoaded.IsSuccess) + { + NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, DllImportResolver); + IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) + { + Console.WriteLine("DllImportResolver: " + libraryName); + if (libraryName == "whisper") + { + // Load the main library + return NativeLibrary.Load(whisperPath, typeof(NativeLibraryLoader).Assembly, DllImportSearchPath.UseDllDirectoryForDependencies); + } + + return IntPtr.Zero; + } + } #endif Console.WriteLine($"Success loaded whisper: {whisperLoaded.IsSuccess} --- Error message: {whisperLoaded.ErrorMessage}"); From 2574676d2aa1d959b7bc29b277da9f4335a0a06b Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Thu, 10 Oct 2024 23:27:07 +0200 Subject: [PATCH 26/79] Again --- Whisper.net/LibraryLoader/NativeLibraryLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs index 54087031..c050c479 100644 --- a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs @@ -73,7 +73,7 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) { Console.WriteLine("DllImportResolver: " + libraryName); - if (libraryName == "whisper") + if (libraryName == "libwhisper.so") { // Load the main library return NativeLibrary.Load(whisperPath, typeof(NativeLibraryLoader).Assembly, DllImportSearchPath.UseDllDirectoryForDependencies); From 2ef453b4ba639d0692d26576964cdb2e9b486b1c Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Fri, 11 Oct 2024 19:12:22 +0200 Subject: [PATCH 27/79] Added UniversalLibraryLoader (for >net6 targets) --- Whisper.net.Tests/FactoryTests.cs | 9 + Whisper.net.Tests/Whisper.net.Tests.csproj | 13 +- Whisper.net/GlobalSuppressions.cs | 2 +- .../IWhisperProcessorModelLoader.cs | 4 +- .../WhisperProcessorModelBufferLoader.cs | 5 +- .../WhisperProcessorModelFileLoader.cs | 35 +-- .../Internals/Native/GgmlNativeMethods.cs | 18 -- .../Internals/Native/INativeWhisper.cs | 99 +++++++++ .../DllImportsInternalNativeWhisper.cs} | 207 +++++++++++------- .../DllImportsNativeWhisper.cs | 130 +++++++++++ .../Implementations/NativeLibraryWhisper.cs | 93 ++++++++ Whisper.net/LibraryLoader/ILibraryLoader.cs | 4 +- .../LibraryLoader/LinuxLibraryLoader.cs | 29 +-- Whisper.net/LibraryLoader/LoadResult.cs | 16 +- .../LibraryLoader/MacOsLibraryLoader.cs | 16 +- .../LibraryLoader/NativeLibraryLoader.cs | 60 ++--- .../LibraryLoader/UniversalLibraryLoader.cs | 19 ++ .../LibraryLoader/WindowsLibraryLoader.cs | 23 +- Whisper.net/Logger/LogProvider.cs | 19 +- Whisper.net/Wave/WaveParser.cs | 12 +- Whisper.net/Whisper.net.csproj | 2 +- Whisper.net/WhisperFactory.cs | 11 +- Whisper.net/WhisperProcessor.cs | 103 ++++----- Whisper.net/WhisperProcessorBuilder.cs | 7 +- 24 files changed, 660 insertions(+), 276 deletions(-) delete mode 100644 Whisper.net/Internals/Native/GgmlNativeMethods.cs create mode 100644 Whisper.net/Internals/Native/INativeWhisper.cs rename Whisper.net/Internals/Native/{NativeMethods.cs => Implementations/DllImportsInternalNativeWhisper.cs} (57%) create mode 100644 Whisper.net/Internals/Native/Implementations/DllImportsNativeWhisper.cs create mode 100644 Whisper.net/Internals/Native/Implementations/NativeLibraryWhisper.cs create mode 100644 Whisper.net/LibraryLoader/UniversalLibraryLoader.cs diff --git a/Whisper.net.Tests/FactoryTests.cs b/Whisper.net.Tests/FactoryTests.cs index 22f835d2..da5a2616 100644 --- a/Whisper.net.Tests/FactoryTests.cs +++ b/Whisper.net.Tests/FactoryTests.cs @@ -1,11 +1,20 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT using FluentAssertions; using NUnit.Framework; +using Whisper.net.Logger; namespace Whisper.net.Tests; public class FactoryTests { + public FactoryTests() + { + LogProvider.Instance.OnLog += (level, message) => + { + Console.WriteLine($"[{level}] {message}"); + }; + } + [Test] public void CreateBuilder_WithNoModel_ShouldThrow() { diff --git a/Whisper.net.Tests/Whisper.net.Tests.csproj b/Whisper.net.Tests/Whisper.net.Tests.csproj index 3e082149..891546a1 100644 --- a/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -1,13 +1,22 @@ - net8.0 enable enable - + 12 false + + net8.0 + + + + + net8.0;net6.0;net472 + + + diff --git a/Whisper.net/GlobalSuppressions.cs b/Whisper.net/GlobalSuppressions.cs index 0cd677a3..c0648ebb 100644 --- a/Whisper.net/GlobalSuppressions.cs +++ b/Whisper.net/GlobalSuppressions.cs @@ -2,4 +2,4 @@ using System.Diagnostics.CodeAnalysis; -[assembly: SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = "Not supported in netstandard, might need to use 2 versions", Scope = "member", Target = "~M:Whisper.net.Native.NativeMethods.whisper_init_state(System.IntPtr)~System.IntPtr")] +[assembly: SuppressMessage("Interoperability", "SYSLIB1054:Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time", Justification = "Not supported in netstandard, might need to use 2 versions", Scope = "member", Target = "~M:Whisper.net.Native.NativeMethodsDllImports.whisper_init_state(System.IntPtr)~System.IntPtr")] diff --git a/Whisper.net/Internals/ModelLoader/IWhisperProcessorModelLoader.cs b/Whisper.net/Internals/ModelLoader/IWhisperProcessorModelLoader.cs index f3d5b432..2e0580e6 100644 --- a/Whisper.net/Internals/ModelLoader/IWhisperProcessorModelLoader.cs +++ b/Whisper.net/Internals/ModelLoader/IWhisperProcessorModelLoader.cs @@ -1,8 +1,10 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT +using Whisper.net.Internals.Native; + namespace Whisper.net.Internals.ModelLoader; internal interface IWhisperProcessorModelLoader : IDisposable { - public IntPtr LoadNativeContext(); + public IntPtr LoadNativeContext(INativeWhisper nativeWhisper); } diff --git a/Whisper.net/Internals/ModelLoader/WhisperProcessorModelBufferLoader.cs b/Whisper.net/Internals/ModelLoader/WhisperProcessorModelBufferLoader.cs index 4a6a6366..e290da8a 100644 --- a/Whisper.net/Internals/ModelLoader/WhisperProcessorModelBufferLoader.cs +++ b/Whisper.net/Internals/ModelLoader/WhisperProcessorModelBufferLoader.cs @@ -1,6 +1,7 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT using System.Runtime.InteropServices; +using Whisper.net.Internals.Native; using Whisper.net.LibraryLoader; using Whisper.net.Native; @@ -15,10 +16,10 @@ public void Dispose() pinnedBuffer.Free(); } - public IntPtr LoadNativeContext() + public IntPtr LoadNativeContext(INativeWhisper nativeWhisper) { var bufferLength = new UIntPtr((uint)buffer.Length); - return NativeMethods.whisper_init_from_buffer_with_params_no_state(pinnedBuffer.AddrOfPinnedObject(), bufferLength, + return nativeWhisper.Whisper_Init_From_Buffer_With_Params_No_State(pinnedBuffer.AddrOfPinnedObject(), bufferLength, new WhisperContextParams() { UseGpu = RuntimeOptions.Instance.UseGpu ? (byte)1 : (byte)0, diff --git a/Whisper.net/Internals/ModelLoader/WhisperProcessorModelFileLoader.cs b/Whisper.net/Internals/ModelLoader/WhisperProcessorModelFileLoader.cs index e516a81c..7206540f 100644 --- a/Whisper.net/Internals/ModelLoader/WhisperProcessorModelFileLoader.cs +++ b/Whisper.net/Internals/ModelLoader/WhisperProcessorModelFileLoader.cs @@ -1,5 +1,6 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT +using Whisper.net.Internals.Native; using Whisper.net.LibraryLoader; using Whisper.net.Native; @@ -12,23 +13,23 @@ public void Dispose() } - public IntPtr LoadNativeContext() + public IntPtr LoadNativeContext(INativeWhisper nativeWhisper) { - return NativeMethods.whisper_init_from_file_with_params_no_state(pathModel, - new WhisperContextParams() - { - UseGpu = RuntimeOptions.Instance.UseGpu ? (byte)1 : (byte)0, - FlashAttention = 0, - GpuDevice = RuntimeOptions.Instance.GpuDevice, - DtwTokenLevelTimestamp = 0, - HeadsPreset = WhisperAlignmentHeadsPreset.WHISPER_AHEADS_NONE, - DtwNTop = -1, - WhisperAheads = new WhisperAheads() - { - NHeads = 0, - Heads = IntPtr.Zero - }, - Dtw_mem_size = 1024 * 1024 * 128, - }); + return nativeWhisper.Whisper_Init_From_File_With_Params_No_State(pathModel, + new WhisperContextParams() + { + UseGpu = RuntimeOptions.Instance.UseGpu ? (byte)1 : (byte)0, + FlashAttention = 0, + GpuDevice = RuntimeOptions.Instance.GpuDevice, + DtwTokenLevelTimestamp = 0, + HeadsPreset = WhisperAlignmentHeadsPreset.WHISPER_AHEADS_NONE, + DtwNTop = -1, + WhisperAheads = new WhisperAheads() + { + NHeads = 0, + Heads = IntPtr.Zero + }, + Dtw_mem_size = 1024 * 1024 * 128, + }); } } diff --git a/Whisper.net/Internals/Native/GgmlNativeMethods.cs b/Whisper.net/Internals/Native/GgmlNativeMethods.cs deleted file mode 100644 index b119286b..00000000 --- a/Whisper.net/Internals/Native/GgmlNativeMethods.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed under the MIT license: https://opensource.org/licenses/MIT - -using System.Runtime.InteropServices; - -namespace Whisper.net.Internals.Native; -internal static class GgmlNativeMethods -{ - // Needed for Apple apps when linking library. -#if IOS || MACCATALYST || TVOS - const string libraryName = "__Internal"; -#else - const string libraryName = "libggml.so"; -#endif - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern void ggml_log_set(IntPtr logCallback, IntPtr user_data); - -} diff --git a/Whisper.net/Internals/Native/INativeWhisper.cs b/Whisper.net/Internals/Native/INativeWhisper.cs new file mode 100644 index 00000000..11999d51 --- /dev/null +++ b/Whisper.net/Internals/Native/INativeWhisper.cs @@ -0,0 +1,99 @@ +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +using System.Runtime.InteropServices; +using Whisper.net.Native; + +namespace Whisper.net.Internals.Native; + +internal interface INativeWhisper : IDisposable +{ + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate IntPtr whisper_init_from_file_with_params_no_state(string path, WhisperContextParams whisperContextParams); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate IntPtr whisper_init_from_buffer_with_params_no_state(IntPtr buffer, nuint buffer_size, WhisperContextParams whisperContextParams); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate void whisper_free(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate void whisper_free_params(IntPtr paramsPtr); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate IntPtr whisper_full_default_params_by_ref(WhisperSamplingStrategy strategy); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate int whisper_full_with_state(IntPtr context, IntPtr state, WhisperFullParams parameters, IntPtr samples, int nSamples); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate int whisper_full_n_segments_from_state(IntPtr state); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate long whisper_full_get_segment_t0_from_state(IntPtr state, int index); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate long whisper_full_get_segment_t1_from_state(IntPtr state, int index); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate IntPtr whisper_full_get_segment_text_from_state(IntPtr state, int index); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate int whisper_full_n_tokens_from_state(IntPtr state, int index); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate float whisper_full_get_token_p_from_state(IntPtr state, int segmentIndex, int tokenIndex); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate int whisper_lang_max_id(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate int whisper_lang_auto_detect_with_state(IntPtr context, IntPtr state, int offset_ms, int n_threads, IntPtr lang_probs); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate int whisper_pcm_to_mel_with_state(IntPtr context, IntPtr state, IntPtr samples, int nSamples, int nThreads); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate IntPtr whisper_lang_str(int lang_id); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate IntPtr whisper_init_state(IntPtr context); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate void whisper_free_state(IntPtr state); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate int whisper_full_lang_id_from_state(IntPtr state); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate void whisper_log_set(IntPtr logCallback, IntPtr user_data); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate void whisper_ctx_init_openvino_encoder_with_state(IntPtr context, IntPtr state, IntPtr modelPath, IntPtr device, IntPtr cacheDir); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public delegate void ggml_log_set(IntPtr logCallback, IntPtr user_data); + + whisper_init_from_file_with_params_no_state Whisper_Init_From_File_With_Params_No_State { get; } + whisper_init_from_buffer_with_params_no_state Whisper_Init_From_Buffer_With_Params_No_State { get; } + whisper_free Whisper_Free { get; } + whisper_free_params Whisper_Free_Params { get; } + whisper_full_default_params_by_ref Whisper_Full_Default_Params_By_Ref { get; } + whisper_full_with_state Whisper_Full_With_State { get; } + whisper_full_n_segments_from_state Whisper_Full_N_Segments_From_State { get; } + whisper_full_get_segment_t0_from_state Whisper_Full_Get_Segment_T0_From_State { get; } + whisper_full_get_segment_t1_from_state Whisper_Full_Get_Segment_T1_From_State { get; } + whisper_full_get_segment_text_from_state Whisper_Full_Get_Segment_Text_From_State { get; } + whisper_full_n_tokens_from_state Whisper_Full_N_Tokens_From_State { get; } + whisper_full_get_token_p_from_state Whisper_Full_Get_Token_P_From_State { get; } + whisper_lang_max_id Whisper_Lang_Max_Id { get; } + whisper_lang_auto_detect_with_state Whisper_Lang_Auto_Detect_With_State { get; } + whisper_pcm_to_mel_with_state Whisper_PCM_To_Mel_With_State { get; } + whisper_lang_str Whisper_Lang_Str { get; } + whisper_init_state Whisper_Init_State { get; } + whisper_free_state Whisper_Free_State { get; } + whisper_full_lang_id_from_state Whisper_Full_Lang_Id_From_State { get; } + whisper_log_set Whisper_Log_Set { get; } + whisper_ctx_init_openvino_encoder_with_state Whisper_Ctx_Init_Openvino_Encoder_With_State { get; } + + ggml_log_set Ggml_log_set { get; } +} diff --git a/Whisper.net/Internals/Native/NativeMethods.cs b/Whisper.net/Internals/Native/Implementations/DllImportsInternalNativeWhisper.cs similarity index 57% rename from Whisper.net/Internals/Native/NativeMethods.cs rename to Whisper.net/Internals/Native/Implementations/DllImportsInternalNativeWhisper.cs index 45b3c7ec..f55f5dd7 100644 --- a/Whisper.net/Internals/Native/NativeMethods.cs +++ b/Whisper.net/Internals/Native/Implementations/DllImportsInternalNativeWhisper.cs @@ -1,78 +1,129 @@ -// Licensed under the MIT license: https://opensource.org/licenses/MIT - -using System.Runtime.InteropServices; - -namespace Whisper.net.Native; - -internal static class NativeMethods -{ - // Needed for Apple apps when linking library. -#if IOS || MACCATALYST || TVOS - const string libraryName = "__Internal"; -#else - const string libraryName = "libwhisper.so"; -#endif - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern IntPtr whisper_init_from_file_with_params_no_state(string path, WhisperContextParams whisperContextParams); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern IntPtr whisper_init_from_buffer_with_params_no_state(IntPtr buffer, nuint buffer_size, WhisperContextParams whisperContextParams); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern void whisper_free(IntPtr context); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern void whisper_free_params(IntPtr paramsPtr); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern IntPtr whisper_full_default_params_by_ref(WhisperSamplingStrategy strategy); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern int whisper_full_with_state(IntPtr context, IntPtr state, WhisperFullParams parameters, IntPtr samples, int nSamples); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern int whisper_full_n_segments_from_state(IntPtr state); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern long whisper_full_get_segment_t0_from_state(IntPtr state, int index); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern long whisper_full_get_segment_t1_from_state(IntPtr state, int index); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern IntPtr whisper_full_get_segment_text_from_state(IntPtr state, int index); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern int whisper_full_n_tokens_from_state(IntPtr state, int index); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern float whisper_full_get_token_p_from_state(IntPtr state, int segmentIndex, int tokenIndex); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern int whisper_lang_max_id(); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern int whisper_lang_auto_detect_with_state(IntPtr context, IntPtr state, int offset_ms, int n_threads, IntPtr lang_probs); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern int whisper_pcm_to_mel_with_state(IntPtr context, IntPtr state, IntPtr samples, int nSamples, int nThreads); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern IntPtr whisper_lang_str(int lang_id); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern IntPtr whisper_init_state(IntPtr context); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern void whisper_free_state(IntPtr state); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern int whisper_full_lang_id_from_state(IntPtr state); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern void whisper_log_set(IntPtr logCallback, IntPtr user_data); - - [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] - public static extern void whisper_ctx_init_openvino_encoder_with_state(IntPtr context, IntPtr state, IntPtr modelPath, IntPtr device, IntPtr cacheDir); -} +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +using System.Runtime.InteropServices; +using Whisper.net.Native; + +namespace Whisper.net.Internals.Native.Implementations; + +/// +/// This way of loading INativeWhisper is used on NetFramework + Wasm (as they doesn't support NativeLibrary) +/// +internal class DllImportsInternalNativeWhisper : INativeWhisper +{ + const string libraryName = "_Internal"; + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_init_from_file_with_params_no_state(string path, WhisperContextParams whisperContextParams); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_init_from_buffer_with_params_no_state(IntPtr buffer, nuint buffer_size, WhisperContextParams whisperContextParams); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_free(IntPtr context); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_free_params(IntPtr paramsPtr); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_full_default_params_by_ref(WhisperSamplingStrategy strategy); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_full_with_state(IntPtr context, IntPtr state, WhisperFullParams parameters, IntPtr samples, int nSamples); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_full_n_segments_from_state(IntPtr state); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern long whisper_full_get_segment_t0_from_state(IntPtr state, int index); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern long whisper_full_get_segment_t1_from_state(IntPtr state, int index); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_full_get_segment_text_from_state(IntPtr state, int index); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_full_n_tokens_from_state(IntPtr state, int index); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern float whisper_full_get_token_p_from_state(IntPtr state, int segmentIndex, int tokenIndex); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_lang_max_id(); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_lang_auto_detect_with_state(IntPtr context, IntPtr state, int offset_ms, int n_threads, IntPtr lang_probs); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_pcm_to_mel_with_state(IntPtr context, IntPtr state, IntPtr samples, int nSamples, int nThreads); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_lang_str(int lang_id); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_init_state(IntPtr context); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_free_state(IntPtr state); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_full_lang_id_from_state(IntPtr state); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_log_set(IntPtr logCallback, IntPtr user_data); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_ctx_init_openvino_encoder_with_state(IntPtr context, IntPtr state, IntPtr modelPath, IntPtr device, IntPtr cacheDir); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void ggml_log_set(IntPtr logCallback, IntPtr user_data); + + public INativeWhisper.whisper_init_from_file_with_params_no_state Whisper_Init_From_File_With_Params_No_State => whisper_init_from_file_with_params_no_state; + + public INativeWhisper.whisper_init_from_buffer_with_params_no_state Whisper_Init_From_Buffer_With_Params_No_State => whisper_init_from_buffer_with_params_no_state; + + public INativeWhisper.whisper_free Whisper_Free => whisper_free; + + public INativeWhisper.whisper_free_params Whisper_Free_Params => whisper_free_params; + + public INativeWhisper.whisper_full_default_params_by_ref Whisper_Full_Default_Params_By_Ref => whisper_full_default_params_by_ref; + + public INativeWhisper.whisper_full_with_state Whisper_Full_With_State => whisper_full_with_state; + + public INativeWhisper.whisper_full_n_segments_from_state Whisper_Full_N_Segments_From_State => whisper_full_n_segments_from_state; + + public INativeWhisper.whisper_full_get_segment_t0_from_state Whisper_Full_Get_Segment_T0_From_State => whisper_full_get_segment_t0_from_state; + + public INativeWhisper.whisper_full_get_segment_t1_from_state Whisper_Full_Get_Segment_T1_From_State => whisper_full_get_segment_t1_from_state; + + public INativeWhisper.whisper_full_get_segment_text_from_state Whisper_Full_Get_Segment_Text_From_State => whisper_full_get_segment_text_from_state; + + public INativeWhisper.whisper_full_n_tokens_from_state Whisper_Full_N_Tokens_From_State => whisper_full_n_tokens_from_state; + + public INativeWhisper.whisper_full_get_token_p_from_state Whisper_Full_Get_Token_P_From_State => whisper_full_get_token_p_from_state; + + public INativeWhisper.whisper_lang_max_id Whisper_Lang_Max_Id => whisper_lang_max_id; + + public INativeWhisper.whisper_lang_auto_detect_with_state Whisper_Lang_Auto_Detect_With_State => whisper_lang_auto_detect_with_state; + + public INativeWhisper.whisper_pcm_to_mel_with_state Whisper_PCM_To_Mel_With_State => whisper_pcm_to_mel_with_state; + + public INativeWhisper.whisper_lang_str Whisper_Lang_Str => whisper_lang_str; + + public INativeWhisper.whisper_init_state Whisper_Init_State => whisper_init_state; + + public INativeWhisper.whisper_free_state Whisper_Free_State => whisper_free_state; + + public INativeWhisper.whisper_full_lang_id_from_state Whisper_Full_Lang_Id_From_State => whisper_full_lang_id_from_state; + + public INativeWhisper.whisper_log_set Whisper_Log_Set => whisper_log_set; + + public INativeWhisper.whisper_ctx_init_openvino_encoder_with_state Whisper_Ctx_Init_Openvino_Encoder_With_State => whisper_ctx_init_openvino_encoder_with_state; + + public INativeWhisper.ggml_log_set Ggml_log_set => ggml_log_set; + + public void Dispose() + { + + } +} diff --git a/Whisper.net/Internals/Native/Implementations/DllImportsNativeWhisper.cs b/Whisper.net/Internals/Native/Implementations/DllImportsNativeWhisper.cs new file mode 100644 index 00000000..333a4508 --- /dev/null +++ b/Whisper.net/Internals/Native/Implementations/DllImportsNativeWhisper.cs @@ -0,0 +1,130 @@ +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +using System.Runtime.InteropServices; +using Whisper.net.Native; + +namespace Whisper.net.Internals.Native.Implementations; + +/// +/// This way of loading INativeWhisper is used on NetFramework + Wasm (as they doesn't support NativeLibrary) +/// +internal class DllImportsNativeWhisper : INativeWhisper +{ + const string libraryName = "whisper"; + const string ggmlLibraryName = "ggml"; + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_init_from_file_with_params_no_state(string path, WhisperContextParams whisperContextParams); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_init_from_buffer_with_params_no_state(IntPtr buffer, nuint buffer_size, WhisperContextParams whisperContextParams); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_free(IntPtr context); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_free_params(IntPtr paramsPtr); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_full_default_params_by_ref(WhisperSamplingStrategy strategy); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_full_with_state(IntPtr context, IntPtr state, WhisperFullParams parameters, IntPtr samples, int nSamples); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_full_n_segments_from_state(IntPtr state); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern long whisper_full_get_segment_t0_from_state(IntPtr state, int index); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern long whisper_full_get_segment_t1_from_state(IntPtr state, int index); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_full_get_segment_text_from_state(IntPtr state, int index); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_full_n_tokens_from_state(IntPtr state, int index); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern float whisper_full_get_token_p_from_state(IntPtr state, int segmentIndex, int tokenIndex); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_lang_max_id(); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_lang_auto_detect_with_state(IntPtr context, IntPtr state, int offset_ms, int n_threads, IntPtr lang_probs); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_pcm_to_mel_with_state(IntPtr context, IntPtr state, IntPtr samples, int nSamples, int nThreads); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_lang_str(int lang_id); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern IntPtr whisper_init_state(IntPtr context); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_free_state(IntPtr state); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern int whisper_full_lang_id_from_state(IntPtr state); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_log_set(IntPtr logCallback, IntPtr user_data); + + [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void whisper_ctx_init_openvino_encoder_with_state(IntPtr context, IntPtr state, IntPtr modelPath, IntPtr device, IntPtr cacheDir); + + [DllImport(ggmlLibraryName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] + public static extern void ggml_log_set(IntPtr logCallback, IntPtr user_data); + + public INativeWhisper.whisper_init_from_file_with_params_no_state Whisper_Init_From_File_With_Params_No_State => whisper_init_from_file_with_params_no_state; + + public INativeWhisper.whisper_init_from_buffer_with_params_no_state Whisper_Init_From_Buffer_With_Params_No_State => whisper_init_from_buffer_with_params_no_state; + + public INativeWhisper.whisper_free Whisper_Free => whisper_free; + + public INativeWhisper.whisper_free_params Whisper_Free_Params => whisper_free_params; + + public INativeWhisper.whisper_full_default_params_by_ref Whisper_Full_Default_Params_By_Ref => whisper_full_default_params_by_ref; + + public INativeWhisper.whisper_full_with_state Whisper_Full_With_State => whisper_full_with_state; + + public INativeWhisper.whisper_full_n_segments_from_state Whisper_Full_N_Segments_From_State => whisper_full_n_segments_from_state; + + public INativeWhisper.whisper_full_get_segment_t0_from_state Whisper_Full_Get_Segment_T0_From_State => whisper_full_get_segment_t0_from_state; + + public INativeWhisper.whisper_full_get_segment_t1_from_state Whisper_Full_Get_Segment_T1_From_State => whisper_full_get_segment_t1_from_state; + + public INativeWhisper.whisper_full_get_segment_text_from_state Whisper_Full_Get_Segment_Text_From_State => whisper_full_get_segment_text_from_state; + + public INativeWhisper.whisper_full_n_tokens_from_state Whisper_Full_N_Tokens_From_State => whisper_full_n_tokens_from_state; + + public INativeWhisper.whisper_full_get_token_p_from_state Whisper_Full_Get_Token_P_From_State => whisper_full_get_token_p_from_state; + + public INativeWhisper.whisper_lang_max_id Whisper_Lang_Max_Id => whisper_lang_max_id; + + public INativeWhisper.whisper_lang_auto_detect_with_state Whisper_Lang_Auto_Detect_With_State => whisper_lang_auto_detect_with_state; + + public INativeWhisper.whisper_pcm_to_mel_with_state Whisper_PCM_To_Mel_With_State => whisper_pcm_to_mel_with_state; + + public INativeWhisper.whisper_lang_str Whisper_Lang_Str => whisper_lang_str; + + public INativeWhisper.whisper_init_state Whisper_Init_State => whisper_init_state; + + public INativeWhisper.whisper_free_state Whisper_Free_State => whisper_free_state; + + public INativeWhisper.whisper_full_lang_id_from_state Whisper_Full_Lang_Id_From_State => whisper_full_lang_id_from_state; + + public INativeWhisper.whisper_log_set Whisper_Log_Set => whisper_log_set; + + public INativeWhisper.whisper_ctx_init_openvino_encoder_with_state Whisper_Ctx_Init_Openvino_Encoder_With_State => whisper_ctx_init_openvino_encoder_with_state; + + public INativeWhisper.ggml_log_set Ggml_log_set => ggml_log_set; + + public void Dispose() + { + + } +} diff --git a/Whisper.net/Internals/Native/Implementations/NativeLibraryWhisper.cs b/Whisper.net/Internals/Native/Implementations/NativeLibraryWhisper.cs new file mode 100644 index 00000000..6451c061 --- /dev/null +++ b/Whisper.net/Internals/Native/Implementations/NativeLibraryWhisper.cs @@ -0,0 +1,93 @@ +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +#if !NETSTANDARD +using System.Runtime.InteropServices; +using static Whisper.net.Internals.Native.INativeWhisper; + +namespace Whisper.net.Internals.Native.Implementations; + +internal class NativeLibraryWhisper : INativeWhisper +{ + private readonly IntPtr whisperLibraryHandle; + private readonly IntPtr ggmlLibraryHandle; + + public NativeLibraryWhisper(IntPtr whisperLibraryHandle, IntPtr ggmlLibraryHandle) + { + Whisper_Init_From_File_With_Params_No_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_init_from_file_with_params_no_state))); + Whisper_Init_From_Buffer_With_Params_No_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_init_from_buffer_with_params_no_state))); + Whisper_Free = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_free))); + Whisper_Free_Params = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_free_params))); + Whisper_Full_Default_Params_By_Ref = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_default_params_by_ref))); + Whisper_Full_With_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_with_state))); + Whisper_Full_N_Segments_From_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_n_segments_from_state))); + Whisper_Full_Get_Segment_T0_From_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_get_segment_t0_from_state))); + Whisper_Full_Get_Segment_T1_From_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_get_segment_t1_from_state))); + Whisper_Full_Get_Segment_Text_From_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_get_segment_text_from_state))); + Whisper_Full_N_Tokens_From_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_n_tokens_from_state))); + Whisper_Full_Get_Token_P_From_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_get_token_p_from_state))); + Whisper_Lang_Max_Id = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_lang_max_id))); + Whisper_Lang_Auto_Detect_With_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_lang_auto_detect_with_state))); + Whisper_PCM_To_Mel_With_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_pcm_to_mel_with_state))); + Whisper_Lang_Str = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_lang_str))); + Whisper_Init_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_init_state))); + Whisper_Free_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_free_state))); + Whisper_Full_Lang_Id_From_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_full_lang_id_from_state))); + Whisper_Log_Set = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_log_set))); + Whisper_Ctx_Init_Openvino_Encoder_With_State = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(whisperLibraryHandle, nameof(whisper_ctx_init_openvino_encoder_with_state))); + Ggml_log_set = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(ggmlLibraryHandle, nameof(ggml_log_set))); + + this.whisperLibraryHandle = whisperLibraryHandle; + this.ggmlLibraryHandle = ggmlLibraryHandle; + } + + public whisper_init_from_file_with_params_no_state Whisper_Init_From_File_With_Params_No_State { get; } + + public whisper_init_from_buffer_with_params_no_state Whisper_Init_From_Buffer_With_Params_No_State { get; } + + public whisper_free Whisper_Free { get; } + + public whisper_free_params Whisper_Free_Params { get; } + + public whisper_full_default_params_by_ref Whisper_Full_Default_Params_By_Ref { get; } + + public whisper_full_with_state Whisper_Full_With_State { get; } + + public whisper_full_n_segments_from_state Whisper_Full_N_Segments_From_State { get; } + + public whisper_full_get_segment_t0_from_state Whisper_Full_Get_Segment_T0_From_State { get; } + + public whisper_full_get_segment_t1_from_state Whisper_Full_Get_Segment_T1_From_State { get; } + + public whisper_full_get_segment_text_from_state Whisper_Full_Get_Segment_Text_From_State { get; } + + public whisper_full_n_tokens_from_state Whisper_Full_N_Tokens_From_State { get; } + + public whisper_full_get_token_p_from_state Whisper_Full_Get_Token_P_From_State { get; } + + public whisper_lang_max_id Whisper_Lang_Max_Id { get; } + + public whisper_lang_auto_detect_with_state Whisper_Lang_Auto_Detect_With_State { get; } + + public whisper_pcm_to_mel_with_state Whisper_PCM_To_Mel_With_State { get; } + + public whisper_lang_str Whisper_Lang_Str { get; } + + public whisper_init_state Whisper_Init_State { get; } + + public whisper_free_state Whisper_Free_State { get; } + + public whisper_full_lang_id_from_state Whisper_Full_Lang_Id_From_State { get; } + + public whisper_log_set Whisper_Log_Set { get; } + + public whisper_ctx_init_openvino_encoder_with_state Whisper_Ctx_Init_Openvino_Encoder_With_State { get; } + + public ggml_log_set Ggml_log_set { get; } + + public void Dispose() + { + NativeLibrary.Free(whisperLibraryHandle); + NativeLibrary.Free(ggmlLibraryHandle); + } +} +#endif diff --git a/Whisper.net/LibraryLoader/ILibraryLoader.cs b/Whisper.net/LibraryLoader/ILibraryLoader.cs index 894aee3b..efa12acf 100644 --- a/Whisper.net/LibraryLoader/ILibraryLoader.cs +++ b/Whisper.net/LibraryLoader/ILibraryLoader.cs @@ -4,5 +4,7 @@ namespace Whisper.net.LibraryLoader; internal interface ILibraryLoader { - LoadResult OpenLibrary(string? fileName, bool global); + IntPtr OpenLibrary(string fileName, bool global); + + string GetLastError(); } diff --git a/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs b/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs index fa210506..3a103755 100644 --- a/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/LinuxLibraryLoader.cs @@ -18,34 +18,29 @@ internal class LinuxLibraryLoader : ILibraryLoader [DllImport("libdl.so.2", ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = "dlerror")] public static extern IntPtr GetLoadError2(); - public LoadResult OpenLibrary(string? fileName, bool global) + public IntPtr OpenLibrary(string fileName, bool global) { - IntPtr loadedLib; try { // open with rtld now + (global if true) - loadedLib = NativeOpenLibraryLibdl2(fileName, global ? 0x00102 : 0x00002); + return NativeOpenLibraryLibdl2(fileName, global ? 0x00102 : 0x00002); } catch (DllNotFoundException) { - loadedLib = NativeOpenLibraryLibdl(fileName, global ? 0x00102 : 0x00002); + return NativeOpenLibraryLibdl(fileName, global ? 0x00102 : 0x00002); } + } - if (loadedLib == IntPtr.Zero) + public string GetLastError() + { + try + { + return Marshal.PtrToStringAnsi(GetLoadError2()) ?? "Unknown error"; + } + catch (DllNotFoundException) { - string errorMessage; - try - { - errorMessage = Marshal.PtrToStringAnsi(GetLoadError2()) ?? "Unknown error"; - } - catch (DllNotFoundException) - { - errorMessage = Marshal.PtrToStringAnsi(GetLoadError()) ?? "Unknown error"; - } - - return LoadResult.Failure(errorMessage); + return Marshal.PtrToStringAnsi(GetLoadError()) ?? "Unknown error"; } - return LoadResult.Success; } } diff --git a/Whisper.net/LibraryLoader/LoadResult.cs b/Whisper.net/LibraryLoader/LoadResult.cs index f731a6c1..953a53a3 100644 --- a/Whisper.net/LibraryLoader/LoadResult.cs +++ b/Whisper.net/LibraryLoader/LoadResult.cs @@ -1,22 +1,30 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT +using Whisper.net.Internals.Native; + namespace Whisper.net.LibraryLoader; -public class LoadResult +internal class LoadResult { - private LoadResult(bool isSuccess, string? errorMessage) + private LoadResult(bool isSuccess, string? errorMessage, INativeWhisper? nativeWhisper) { IsSuccess = isSuccess; ErrorMessage = errorMessage; + NativeWhisper = nativeWhisper; } - public static LoadResult Success { get; } = new(true, null); + public static LoadResult Success(INativeWhisper nativeWhisper) + { + return new(true, null, nativeWhisper); + } public static LoadResult Failure(string errorMessage) { - return new(false, errorMessage); + return new(false, errorMessage, null); } + public INativeWhisper? NativeWhisper; + public bool IsSuccess { get; } public string? ErrorMessage { get; } } diff --git a/Whisper.net/LibraryLoader/MacOsLibraryLoader.cs b/Whisper.net/LibraryLoader/MacOsLibraryLoader.cs index b6bfca41..aa39fff4 100644 --- a/Whisper.net/LibraryLoader/MacOsLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/MacOsLibraryLoader.cs @@ -12,17 +12,13 @@ internal class MacOsLibraryLoader : ILibraryLoader [DllImport("libdl.dylib", ExactSpelling = true, CharSet = CharSet.Auto, EntryPoint = "dlerror")] public static extern IntPtr GetLoadError(); - public LoadResult OpenLibrary(string? fileName, bool global) + public IntPtr OpenLibrary(string fileName, bool global) { - var loadedLib = NativeOpenLibraryLibdl(fileName, global ? 0x00102 : 0x00001); - - if (loadedLib == IntPtr.Zero) - { - var errorMessage = Marshal.PtrToStringAnsi(GetLoadError()) ?? "Unknown error"; - - return LoadResult.Failure(errorMessage); - } + return NativeOpenLibraryLibdl(fileName, global ? 0x00102 : 0x00001); + } - return LoadResult.Success; + public string GetLastError() + { + return Marshal.PtrToStringAnsi(GetLoadError()) ?? "Unknown error"; } } diff --git a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs index c050c479..d9fa7da4 100644 --- a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs @@ -1,8 +1,8 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT +using Whisper.net.Internals.Native.Implementations; + #if !IOS && !MACCATALYST && !TVOS && !ANDROID -using System.Reflection; using System.Runtime.InteropServices; -using Whisper.net.Native; #endif namespace Whisper.net.LibraryLoader; @@ -12,13 +12,13 @@ public static class NativeLibraryLoader internal static LoadResult LoadNativeLibrary() { #if IOS || MACCATALYST || TVOS || ANDROID - return LoadResult.Success; + return LoadResult.Success(new DllImportsInternalNativeWhisper()); #else // If the user has handled loading the library themselves, we don't need to do anything. if (RuntimeOptions.Instance.BypassLoading || RuntimeInformation.OSArchitecture.ToString().Equals("wasm", StringComparison.OrdinalIgnoreCase)) { - return LoadResult.Success; + return LoadResult.Success(new DllImportsNativeWhisper()); } return LoadLibraryComponent(); } @@ -33,6 +33,7 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", _ => throw new PlatformNotSupportedException($"Unsupported OS platform, architecture: {RuntimeInformation.OSArchitecture}") }; +#if NETSTANDARD ILibraryLoader libraryLoader = platform switch { "win" => new WindowsLibraryLoader(), @@ -40,8 +41,11 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", "linux" => new LinuxLibraryLoader(), _ => throw new PlatformNotSupportedException($"Currently {platform} platform is not supported") }; +#else + var libraryLoader = new UniversalLibraryLoader(); +#endif - LoadResult? lastError = null; + string? lastError = null; foreach (var (runtimePath, runtimeLibrary) in GetRuntimePaths(platform)) { @@ -52,44 +56,26 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", } var whisperPath = GetLibraryPath(platform, "whisper", runtimePath); -#if NETSTANDARD2_0 - var ggmlLoadResult = libraryLoader.OpenLibrary(ggmlPath, global: true); + var ggmlLibraryHandle = libraryLoader.OpenLibrary(ggmlPath, global: true); // Maybe GPU is not available but we still have other runtime installed - if (!ggmlLoadResult.IsSuccess) + if (ggmlLibraryHandle == IntPtr.Zero) { - lastError = ggmlLoadResult; + lastError = libraryLoader.GetLastError(); continue; } // Ggml was loaded, for this runtimePath, we need to load whisper as well - var whisperLoaded = libraryLoader.OpenLibrary(whisperPath, global: true); -#else - var nativeLibraryLoaded = NativeLibrary.Load(whisperPath, typeof(NativeLibraryLoader).Assembly, DllImportSearchPath.UseDllDirectoryForDependencies); - var whisperLoaded = nativeLibraryLoaded != IntPtr.Zero ? LoadResult.Success : LoadResult.Failure("Cannot load the library"); - Console.WriteLine("Whisper loaded: {0}", nativeLibraryLoaded); - if (whisperLoaded.IsSuccess) + var whisperHandle = libraryLoader.OpenLibrary(whisperPath, global: true); + if (whisperHandle != IntPtr.Zero) { - NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, DllImportResolver); - IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) - { - Console.WriteLine("DllImportResolver: " + libraryName); - if (libraryName == "libwhisper.so") - { - // Load the main library - return NativeLibrary.Load(whisperPath, typeof(NativeLibraryLoader).Assembly, DllImportSearchPath.UseDllDirectoryForDependencies); - } - - return IntPtr.Zero; - } - } + RuntimeOptions.Instance.SetLoadedLibrary(runtimeLibrary); +#if NETSTANDARD + var nativeWhisper = new DllImportsNativeWhisper(); +#else + var nativeWhisper = new NativeLibraryWhisper(whisperHandle, ggmlLibraryHandle); #endif - Console.WriteLine($"Success loaded whisper: {whisperLoaded.IsSuccess} --- Error message: {whisperLoaded.ErrorMessage}"); - - if (whisperLoaded.IsSuccess) - { - RuntimeOptions.Instance.SetLoadedLibrary(runtimeLibrary); - return whisperLoaded; + return LoadResult.Success(nativeWhisper); } } @@ -102,7 +88,7 @@ IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchP } // Runtime was found but couldn't be loaded. - return lastError; + return LoadResult.Failure(lastError); } private static string GetLibraryPath(string platform, string libraryName, string runtimePath) @@ -131,7 +117,7 @@ private static string GetLibraryPath(string platform, string libraryName, string var assemblySearchPath = new[] { AppDomain.CurrentDomain.RelativeSearchPath, - Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location), + Path.GetDirectoryName(typeof(NativeLibraryLoader).Assembly.Location), Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) }.Where(it => !string.IsNullOrEmpty(it)).FirstOrDefault(); @@ -158,6 +144,6 @@ private static string GetLibraryPath(string platform, string libraryName, string } #endif - } + } } diff --git a/Whisper.net/LibraryLoader/UniversalLibraryLoader.cs b/Whisper.net/LibraryLoader/UniversalLibraryLoader.cs new file mode 100644 index 00000000..941a9aa6 --- /dev/null +++ b/Whisper.net/LibraryLoader/UniversalLibraryLoader.cs @@ -0,0 +1,19 @@ +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +#if !NETSTANDARD +using System.Runtime.InteropServices; + +namespace Whisper.net.LibraryLoader; +internal class UniversalLibraryLoader : ILibraryLoader +{ + public string GetLastError() + { + return "Cannot load the library on this platform using NativeLibrary"; + } + + public IntPtr OpenLibrary(string fileName, bool global) + { + return NativeLibrary.Load(fileName); + } +} +#endif diff --git a/Whisper.net/LibraryLoader/WindowsLibraryLoader.cs b/Whisper.net/LibraryLoader/WindowsLibraryLoader.cs index 5f3e3853..08466079 100644 --- a/Whisper.net/LibraryLoader/WindowsLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/WindowsLibraryLoader.cs @@ -7,20 +7,17 @@ namespace Whisper.net.LibraryLoader; internal class WindowsLibraryLoader : ILibraryLoader { - public LoadResult OpenLibrary(string? fileName, bool global) - { - var loadedLib = LoadLibrary(fileName); - - if (loadedLib == IntPtr.Zero) - { - var errorCode = Marshal.GetLastWin32Error(); - var errorMessage = new Win32Exception(errorCode).Message; - return LoadResult.Failure(errorMessage); - } + [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Auto)] + private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPTStr)] string? lpFileName); - return LoadResult.Success; + public IntPtr OpenLibrary(string fileName, bool global) + { + return LoadLibrary(fileName); } - [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Auto)] - private static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPTStr)] string? lpFileName); + public string GetLastError() + { + var errorCode = Marshal.GetLastWin32Error(); + return new Win32Exception(errorCode).Message; + } } diff --git a/Whisper.net/Logger/LogProvider.cs b/Whisper.net/Logger/LogProvider.cs index 5d830b5f..7f09cf04 100644 --- a/Whisper.net/Logger/LogProvider.cs +++ b/Whisper.net/Logger/LogProvider.cs @@ -20,27 +20,26 @@ private LogProvider() public event Action? OnLog; - internal static void InitializeLogging() + internal static void InitializeLogging(INativeWhisper nativeWhisper) { IntPtr funcPointer; -#if NET6_0_OR_GREATER +#if NETSTANDARD + funcPointer = Marshal.GetFunctionPointerForDelegate(logCallback); +#else unsafe { delegate* unmanaged[Cdecl] onLogging = &LogUnmanaged; funcPointer = (IntPtr)onLogging; } -#else - funcPointer = Marshal.GetFunctionPointerForDelegate(logCallback); #endif - NativeMethods.whisper_log_set(funcPointer, IntPtr.Zero); - GgmlNativeMethods.ggml_log_set(funcPointer, IntPtr.Zero); + nativeWhisper.Whisper_Log_Set(funcPointer, IntPtr.Zero); + nativeWhisper.Ggml_log_set(funcPointer, IntPtr.Zero); } -#if NET6_0_OR_GREATER - [UnmanagedCallersOnly(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])] -# else - +#if NETSTANDARD private static readonly WhisperGgmlLogCallback logCallback = LogUnmanaged; +# else + [UnmanagedCallersOnly(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])] #endif internal static void LogUnmanaged(GgmlLogLevel level, IntPtr message, IntPtr user_data) { diff --git a/Whisper.net/Wave/WaveParser.cs b/Whisper.net/Wave/WaveParser.cs index 200fb4cf..a3c52137 100644 --- a/Whisper.net/Wave/WaveParser.cs +++ b/Whisper.net/Wave/WaveParser.cs @@ -221,11 +221,11 @@ private async IAsyncEnumerable InternalReadSamples(bool useAsync, [Enume var maxBytesToRead = (int)Math.Min(buffer.Length, (SamplesCount - sampleIndex) * FrameSize); if (useAsync) { -#if NET6_0_OR_GREATER +#if NETSTANDARD + bytesRead = await waveStream.ReadAsync(buffer, 0, maxBytesToRead, cancellationToken); +#else var memoryToUse = maxBytesToRead == buffer.Length ? memoryBuffer : memoryBuffer[..maxBytesToRead]; bytesRead = await waveStream.ReadAsync(memoryToUse, cancellationToken); -#else - bytesRead = await waveStream.ReadAsync(buffer, 0, maxBytesToRead, cancellationToken); #endif } else @@ -270,10 +270,10 @@ async Task ReadBytesAsync(byte[] buffer, int offset, int count) { if (useAsync) { -#if NET6_0_OR_GREATER - return await waveStream.ReadAsync(buffer.AsMemory(offset, count), cancellationToken); -#else +#if NETSTANDARD return await waveStream.ReadAsync(buffer, offset, count, cancellationToken); +#else + return await waveStream.ReadAsync(buffer.AsMemory(offset, count), cancellationToken); #endif } diff --git a/Whisper.net/Whisper.net.csproj b/Whisper.net/Whisper.net.csproj index d52d7396..a668c61c 100755 --- a/Whisper.net/Whisper.net.csproj +++ b/Whisper.net/Whisper.net.csproj @@ -1,4 +1,4 @@ - + enable diff --git a/Whisper.net/WhisperFactory.cs b/Whisper.net/WhisperFactory.cs index 400a1baa..8c659e7c 100644 --- a/Whisper.net/WhisperFactory.cs +++ b/Whisper.net/WhisperFactory.cs @@ -3,7 +3,6 @@ using Whisper.net.Internals.ModelLoader; using Whisper.net.LibraryLoader; using Whisper.net.Logger; -using Whisper.net.Native; namespace Whisper.net; @@ -24,7 +23,7 @@ public sealed class WhisperFactory : IDisposable var libraryLoaded = NativeLibraryLoader.LoadNativeLibrary(); if (libraryLoaded.IsSuccess) { - LogProvider.InitializeLogging(); + LogProvider.InitializeLogging(libraryLoaded.NativeWhisper!); } return libraryLoaded; }, true); @@ -39,12 +38,12 @@ private WhisperFactory(IWhisperProcessorModelLoader loader, bool delayInit) this.loader = loader; if (!delayInit) { - var nativeContext = loader.LoadNativeContext(); + var nativeContext = loader.LoadNativeContext(libraryLoaded.Value.NativeWhisper!); contextLazy = new Lazy(() => nativeContext); } else { - contextLazy = new Lazy(() => loader.LoadNativeContext(), isThreadSafe: false); + contextLazy = new Lazy(() => loader.LoadNativeContext(libraryLoaded.Value.NativeWhisper!), isThreadSafe: false); } } @@ -95,7 +94,7 @@ public WhisperProcessorBuilder CreateBuilder() throw new WhisperModelLoadException("Failed to load the whisper model."); } - return new WhisperProcessorBuilder(contextLazy.Value); + return new WhisperProcessorBuilder(contextLazy.Value, libraryLoaded.Value.NativeWhisper!); } public void Dispose() @@ -106,7 +105,7 @@ public void Dispose() } if (contextLazy.IsValueCreated && contextLazy.Value != IntPtr.Zero) { - NativeMethods.whisper_free(contextLazy.Value); + libraryLoaded.Value.NativeWhisper!.Whisper_Free(contextLazy.Value); } loader.Dispose(); wasDisposed = true; diff --git a/Whisper.net/WhisperProcessor.cs b/Whisper.net/WhisperProcessor.cs index fee3028b..c31171b8 100755 --- a/Whisper.net/WhisperProcessor.cs +++ b/Whisper.net/WhisperProcessor.cs @@ -4,6 +4,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Whisper.net.Internals; +using Whisper.net.Internals.Native; using Whisper.net.LibraryLoader; using Whisper.net.Native; using Whisper.net.SamplingStrategy; @@ -23,6 +24,7 @@ public sealed class WhisperProcessor : IAsyncDisposable, IDisposable private readonly IntPtr currentWhisperContext; private readonly WhisperProcessorOptions options; + private readonly INativeWhisper nativeWhisper; private readonly List gcHandles = []; private readonly SemaphoreSlim processingSemaphore; private WhisperFullParams whisperParams; @@ -36,9 +38,10 @@ public sealed class WhisperProcessor : IAsyncDisposable, IDisposable // Id is used to identify the current instance when calling the callbacks from C++ private readonly long myId; - internal WhisperProcessor(WhisperProcessorOptions options) + internal WhisperProcessor(WhisperProcessorOptions options, INativeWhisper nativeWhisper) { this.options = options; + this.nativeWhisper = nativeWhisper; myId = Interlocked.Increment(ref currentProcessorId); processorInstances[myId] = this; @@ -104,7 +107,7 @@ public void ChangeLanguage(string? newLanguage) /// public unsafe (string? language, float probability) DetectLanguageWithProbability(ReadOnlySpan samples) { - var probs = new float[NativeMethods.whisper_lang_max_id()]; + var probs = new float[nativeWhisper.Whisper_Lang_Max_Id()]; fixed (float* pData = probs) { @@ -113,20 +116,20 @@ public unsafe (string? language, float probability) DetectLanguageWithProbabilit { fixed (float* pSamples = samples) { - NativeMethods.whisper_pcm_to_mel_with_state(currentWhisperContext, state, (IntPtr)pSamples, samples.Length, whisperParams.Threads); + nativeWhisper.Whisper_PCM_To_Mel_With_State(currentWhisperContext, state, (IntPtr)pSamples, samples.Length, whisperParams.Threads); } - var langId = NativeMethods.whisper_lang_auto_detect_with_state(currentWhisperContext, state, 0, whisperParams.Threads, (IntPtr)pData); + var langId = nativeWhisper.Whisper_Lang_Auto_Detect_With_State(currentWhisperContext, state, 0, whisperParams.Threads, (IntPtr)pData); if (langId == -1) { return (null, 0f); } - var languagePtr = NativeMethods.whisper_lang_str(langId); + var languagePtr = nativeWhisper.Whisper_Lang_Str(langId); var language = Marshal.PtrToStringAnsi(languagePtr); return (language, probs[langId]); } finally { - NativeMethods.whisper_free_state(state); + nativeWhisper.Whisper_Free_State(state); } } } @@ -174,11 +177,11 @@ public unsafe void Process(ReadOnlySpan samples) processingSemaphore.Wait(); segmentIndex = 0; - NativeMethods.whisper_full_with_state(currentWhisperContext, state, whisperParams, (IntPtr)pData, samples.Length); + nativeWhisper.Whisper_Full_With_State(currentWhisperContext, state, whisperParams, (IntPtr)pData, samples.Length); } finally { - NativeMethods.whisper_free_state(state); + nativeWhisper.Whisper_Free_State(state); processingSemaphore.Release(); } } @@ -326,11 +329,11 @@ private unsafe Task ProcessInternalAsync(ReadOnlyMemory samples, Cancella try { - NativeMethods.whisper_full_with_state(currentWhisperContext, state, whisperParams, (IntPtr)pData, samples.Length); + nativeWhisper.Whisper_Full_With_State(currentWhisperContext, state, whisperParams, (IntPtr)pData, samples.Length); } finally { - NativeMethods.whisper_free_state(state); + nativeWhisper.Whisper_Free_State(state); processingSemaphore.Release(); } } @@ -339,13 +342,13 @@ private unsafe Task ProcessInternalAsync(ReadOnlyMemory samples, Cancella private IntPtr GetWhisperState() { - var state = NativeMethods.whisper_init_state(currentWhisperContext); + var state = nativeWhisper.Whisper_Init_State(currentWhisperContext); if (RuntimeOptions.Instance.LoadedLibrary == RuntimeLibrary.OpenVino) { var modelPath = Marshal.StringToHGlobalAnsi(options.OpenVinoModelPath); var device = Marshal.StringToHGlobalAnsi(options.OpenVinoDevice); var cachePath = Marshal.StringToHGlobalAnsi(options.OpenVinoCacheDir); - NativeMethods.whisper_ctx_init_openvino_encoder_with_state( + nativeWhisper.Whisper_Ctx_Init_Openvino_Encoder_With_State( options.ContextHandle, state, modelPath, @@ -358,9 +361,9 @@ private IntPtr GetWhisperState() private WhisperFullParams GetWhisperParams() { var strategy = options.SamplingStrategy.GetNativeStrategy(); - var whisperParamsRef = NativeMethods.whisper_full_default_params_by_ref(strategy); + var whisperParamsRef = nativeWhisper.Whisper_Full_Default_Params_By_Ref(strategy); var whisperParams = Marshal.PtrToStructure(whisperParamsRef); - NativeMethods.whisper_free_params(whisperParamsRef); + nativeWhisper.Whisper_Free_Params(whisperParamsRef); whisperParams.Strategy = strategy; if (options.Threads.HasValue) @@ -534,26 +537,7 @@ private WhisperFullParams GetWhisperParams() whisperParams.OnEncoderBeginUserData = myIntPtrId; whisperParams.OnAbortUserData = myIntPtrId; -#if NET6_0_OR_GREATER - unsafe - { - delegate* unmanaged[Cdecl] onNewSegmentDelegate = &OnNewSegmentStatic; - whisperParams.OnNewSegment = (IntPtr)onNewSegmentDelegate; - - delegate* unmanaged[Cdecl] onEncoderBeginDelegate = &OnEncoderBeginStatic; - whisperParams.OnEncoderBegin = (IntPtr)onEncoderBeginDelegate; - - delegate* unmanaged[Cdecl] onWhisperAbortDelegate = &OnWhisperAbortStatic; - whisperParams.OnAbort = (IntPtr)onWhisperAbortDelegate; - - if (options.OnProgressHandlers.Count > 0) - { - delegate* unmanaged[Cdecl] onProgressDelegate = &OnProgressStatic; - whisperParams.OnProgressCallback = (IntPtr)onProgressDelegate; - whisperParams.OnProgressCallbackUserData = myIntPtrId; - } - } -#else +#if NETSTANDARD // For netframework, we don't have `UnmanagedCallersOnlyAttribute` so we need to use a delegate wrapped with a GC handle var onNewSegmentDelegate = new WhisperNewSegmentCallback(OnNewSegmentStatic); var gcHandle = GCHandle.Alloc(onNewSegmentDelegate); @@ -578,12 +562,31 @@ private WhisperFullParams GetWhisperParams() whisperParams.OnProgressCallback = Marshal.GetFunctionPointerForDelegate(onProgressDelegate); whisperParams.OnProgressCallbackUserData = myIntPtrId; } +#else + unsafe + { + delegate* unmanaged[Cdecl] onNewSegmentDelegate = &OnNewSegmentStatic; + whisperParams.OnNewSegment = (IntPtr)onNewSegmentDelegate; + + delegate* unmanaged[Cdecl] onEncoderBeginDelegate = &OnEncoderBeginStatic; + whisperParams.OnEncoderBegin = (IntPtr)onEncoderBeginDelegate; + + delegate* unmanaged[Cdecl] onWhisperAbortDelegate = &OnWhisperAbortStatic; + whisperParams.OnAbort = (IntPtr)onWhisperAbortDelegate; + + if (options.OnProgressHandlers.Count > 0) + { + delegate* unmanaged[Cdecl] onProgressDelegate = &OnProgressStatic; + whisperParams.OnProgressCallback = (IntPtr)onProgressDelegate; + whisperParams.OnProgressCallbackUserData = myIntPtrId; + } + } #endif return whisperParams; } -#if NET6_0_OR_GREATER +#if !NETSTANDARD [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])] #endif private static byte OnWhisperAbortStatic(IntPtr userData) @@ -597,7 +600,7 @@ private static byte OnWhisperAbortStatic(IntPtr userData) return shouldCancel ? trueByte : falseByte; } -#if NET6_0_OR_GREATER +#if !NETSTANDARD [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])] #endif private static void OnNewSegmentStatic(IntPtr ctx, IntPtr state, int nNew, IntPtr userData) @@ -609,7 +612,7 @@ private static void OnNewSegmentStatic(IntPtr ctx, IntPtr state, int nNew, IntPt processor.OnNewSegment(state); } -#if NET6_0_OR_GREATER +#if !NETSTANDARD [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])] #endif private static byte OnEncoderBeginStatic(IntPtr ctx, IntPtr state, IntPtr userData) @@ -621,7 +624,7 @@ private static byte OnEncoderBeginStatic(IntPtr ctx, IntPtr state, IntPtr userDa return processor.OnEncoderBegin() ? trueByte : falseByte; } -#if NET6_0_OR_GREATER +#if !NETSTANDARD [UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])] #endif private static void OnProgressStatic(IntPtr ctx, IntPtr state, int progress, IntPtr userData) @@ -676,26 +679,26 @@ private void OnNewSegment(IntPtr state) return; } - var segments = NativeMethods.whisper_full_n_segments_from_state(state); + var segments = nativeWhisper.Whisper_Full_N_Segments_From_State(state); while (segmentIndex < segments) { - var t1 = TimeSpan.FromMilliseconds(NativeMethods.whisper_full_get_segment_t1_from_state(state, segmentIndex) * 10); - var t0 = TimeSpan.FromMilliseconds(NativeMethods.whisper_full_get_segment_t0_from_state(state, segmentIndex) * 10); - var textAnsi = StringFromNativeUtf8(NativeMethods.whisper_full_get_segment_text_from_state(state, segmentIndex)); + var t1 = TimeSpan.FromMilliseconds(nativeWhisper.Whisper_Full_Get_Segment_T1_From_State(state, segmentIndex) * 10); + var t0 = TimeSpan.FromMilliseconds(nativeWhisper.Whisper_Full_Get_Segment_T0_From_State(state, segmentIndex) * 10); + var textAnsi = StringFromNativeUtf8(nativeWhisper.Whisper_Full_Get_Segment_Text_From_State(state, segmentIndex)); float minimumProbability = 0; float maximumProbability = 0; double sumProbability = 0; - var numberOfTokens = NativeMethods.whisper_full_n_tokens_from_state(state, segmentIndex); - var languageId = NativeMethods.whisper_full_lang_id_from_state(state); - var language = Marshal.PtrToStringAnsi(NativeMethods.whisper_lang_str(languageId)); + var numberOfTokens = nativeWhisper.Whisper_Full_N_Tokens_From_State(state, segmentIndex); + var languageId = nativeWhisper.Whisper_Full_Lang_Id_From_State(state); + var language = Marshal.PtrToStringAnsi(nativeWhisper.Whisper_Lang_Str(languageId)); if (options.ComputeProbabilities) { for (var tokenIndex = 0; tokenIndex < numberOfTokens; tokenIndex++) { - var tokenProbability = NativeMethods.whisper_full_get_token_p_from_state(state, segmentIndex, tokenIndex); + var tokenProbability = nativeWhisper.Whisper_Full_Get_Token_P_From_State(state, segmentIndex, tokenIndex); sumProbability += tokenProbability; if (tokenIndex == 0) { @@ -733,12 +736,10 @@ private void OnNewSegment(IntPtr state) } } - private static string StringFromNativeUtf8(IntPtr nativeUtf8) + private static string? StringFromNativeUtf8(IntPtr nativeUtf8) { -#if NETSTANDARD2_1_OR_GREATER - return Marshal.PtrToStringUTF8(nativeUtf8); -#else +#if NETSTANDARD var len = 0; while (Marshal.ReadByte(nativeUtf8, len) != 0) @@ -749,6 +750,8 @@ private static string StringFromNativeUtf8(IntPtr nativeUtf8) var buffer = new byte[len]; Marshal.Copy(nativeUtf8, buffer, 0, buffer.Length); return System.Text.Encoding.UTF8.GetString(buffer); +#else + return Marshal.PtrToStringUTF8(nativeUtf8); #endif } diff --git a/Whisper.net/WhisperProcessorBuilder.cs b/Whisper.net/WhisperProcessorBuilder.cs index 287e7beb..3bcb1aa9 100755 --- a/Whisper.net/WhisperProcessorBuilder.cs +++ b/Whisper.net/WhisperProcessorBuilder.cs @@ -1,5 +1,6 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT +using Whisper.net.Internals.Native; using Whisper.net.SamplingStrategy; namespace Whisper.net; @@ -10,13 +11,15 @@ namespace Whisper.net; public class WhisperProcessorBuilder { private readonly WhisperProcessorOptions whisperProcessorOptions; + private readonly INativeWhisper nativeWhisper; - internal WhisperProcessorBuilder(IntPtr context) + internal WhisperProcessorBuilder(IntPtr context, INativeWhisper nativeWhisper) { whisperProcessorOptions = new WhisperProcessorOptions() { ContextHandle = context }; + this.nativeWhisper = nativeWhisper; } /// @@ -528,6 +531,6 @@ public WhisperProcessorBuilder WithOpenVinoEncoder(string? openVinoEncoderPath, /// The build with these configs. public WhisperProcessor Build() { - return new WhisperProcessor(whisperProcessorOptions); + return new WhisperProcessor(whisperProcessorOptions, nativeWhisper); } } From a8998a56df5f2a045dd3b8dc02ad3a675cd84b14 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Fri, 11 Oct 2024 19:23:36 +0200 Subject: [PATCH 28/79] Removed patchelf, added android, macos, ios, tvos, maccatalyst tests --- .github/workflows/dotnet.yml | 103 ++++++++++++++------- .github/workflows/linux-native-build.yml | 3 - Makefile | 1 - Whisper.net.Tests/Whisper.net.Tests.csproj | 17 +++- Whisper.net/Whisper.net.csproj | 4 +- Whisper.net/WhisperProcessor.cs | 4 +- 6 files changed, 87 insertions(+), 45 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index ad6109da..c327c768 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -7,46 +7,87 @@ on: workflow_call: jobs: - # dotnet-windows: + + dotnet-macos: + runs-on: macos-14 + + steps: + - uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + - name: Download Artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + merge-multiple: true + + - name: Install Java + uses: actions/setup-java@v2 + with: + distribution: 'microsoft' + java-version: '11' + + - name: Install .NET Workloads + run: | + dotnet workload install android --ignore-failed-sources + dotnet workload install ios --ignore-failed-sources + dotnet workload install tvos --ignore-failed-sources + dotnet workload install maccatalyst --ignore-failed-sources + + - name: Restore dependencies + run: dotnet restore ./Whisper.net.sln + + - name: Build + run: dotnet build ./Whisper.net.sln --no-restore -warnaserror + + - name: Test + run: | + dotnet test ./Whisper.net.sln --no-build + + dotnet-windows: - # runs-on: windows-latest + runs-on: windows-latest - # steps: - # - uses: actions/checkout@v3 + steps: + - uses: actions/checkout@v3 - # - name: Setup .NET - # uses: actions/setup-dotnet@v3 - # with: - # dotnet-version: 8.0.x + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x - # - name: Download Artifacts - # id: download-artifact - # uses: actions/download-artifact@v4 - # with: - # merge-multiple: true + - name: Download Artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + merge-multiple: true - # - name: Install Java - # uses: actions/setup-java@v2 - # with: - # distribution: 'microsoft' - # java-version: '11' + - name: Install Java + uses: actions/setup-java@v2 + with: + distribution: 'microsoft' + java-version: '11' - # - name: Install .NET Workloads - # run: | - # dotnet workload install android --ignore-failed-sources - # dotnet workload install ios --ignore-failed-sources - # dotnet workload install tvos --ignore-failed-sources - # dotnet workload install maccatalyst --ignore-failed-sources + - name: Install .NET Workloads + run: | + dotnet workload install android --ignore-failed-sources + dotnet workload install ios --ignore-failed-sources + dotnet workload install tvos --ignore-failed-sources + dotnet workload install maccatalyst --ignore-failed-sources - # - name: Restore dependencies - # run: dotnet restore ./Whisper.net.sln + - name: Restore dependencies + run: dotnet restore ./Whisper.net.sln - # - name: Build - # run: dotnet build ./Whisper.net.sln --no-restore -warnaserror + - name: Build + run: dotnet build ./Whisper.net.sln --no-restore -warnaserror - # - name: Test - # run: | - # dotnet test ./Whisper.net.sln --no-build + - name: Test + run: | + dotnet test ./Whisper.net.sln --no-build dotnet-linux: runs-on: ubuntu-latest diff --git a/.github/workflows/linux-native-build.yml b/.github/workflows/linux-native-build.yml index d19d87e9..32b112fd 100644 --- a/.github/workflows/linux-native-build.yml +++ b/.github/workflows/linux-native-build.yml @@ -22,9 +22,6 @@ jobs: - name: Install gcc-arm-linux-gnueabihf run: sudo apt-get update && sudo apt-get install -y gcc-arm-linux-gnueabihf && sudo apt-get install -y g++-arm-linux-gnueabihf - - name: Install patchelf - run: sudo apt-get update && sudo apt-get install -y patchelf - - name: Run linux run: make linux diff --git a/Makefile b/Makefile index 04ed03fb..7661c834 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,6 @@ linux_x64: cmake --build build/linux-x64 --config $(BUILD_TYPE) mkdir -p Whisper.net.Runtime/linux-x64 cp build/linux-x64/whisper.cpp/src/libwhisper.so ./Whisper.net.Runtime/linux-x64/libwhisper.so - patchelf --set-rpath '$$ORIGIN' ./Whisper.net.Runtime/linux-x64/libwhisper.so cp build/linux-x64/whisper.cpp/ggml/src/libggml.so ./Whisper.net.Runtime/linux-x64/libggml.so linux_arm64: diff --git a/Whisper.net.Tests/Whisper.net.Tests.csproj b/Whisper.net.Tests/Whisper.net.Tests.csproj index 891546a1..a0fde9d0 100644 --- a/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -8,21 +8,28 @@ - net8.0 + net8.0;net6.0 - net8.0;net6.0;net472 + net8.0;net6.0;net472;net8.0-android + + + net8.0;net6.0;net8.0-ios;net8.0-tvos;net8.0-maccatalyst + + + + - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -54,4 +61,4 @@ - + \ No newline at end of file diff --git a/Whisper.net/Whisper.net.csproj b/Whisper.net/Whisper.net.csproj index a668c61c..733d04f2 100755 --- a/Whisper.net/Whisper.net.csproj +++ b/Whisper.net/Whisper.net.csproj @@ -1,4 +1,4 @@ - + enable @@ -26,7 +26,7 @@ - net8.0;net6.0;netstandard2.0;net8.0-ios;net8.0-tvos;net8.0-maccatalyst + net8.0;net6.0;netstandard2.0;net8.0-ios;net8.0-tvos;net8.0-maccatalyst;net8.0-android diff --git a/Whisper.net/WhisperProcessor.cs b/Whisper.net/WhisperProcessor.cs index c31171b8..e02f5543 100755 --- a/Whisper.net/WhisperProcessor.cs +++ b/Whisper.net/WhisperProcessor.cs @@ -92,7 +92,6 @@ public void ChangeLanguage(string? newLanguage) /// For the given audio input, detects the most probable language and also returns the probability of this language to be correct. /// /// - /// /// public (string? language, float probability) DetectLanguageWithProbability(float[] samples) { @@ -103,7 +102,6 @@ public void ChangeLanguage(string? newLanguage) /// For the given audio input, detects the most probable language and also returns the probability of this language to be correct. /// /// - /// /// public unsafe (string? language, float probability) DetectLanguageWithProbability(ReadOnlySpan samples) { @@ -720,7 +718,7 @@ private void OnNewSegment(IntPtr state) if (!string.IsNullOrEmpty(textAnsi)) { - var eventHandlerArgs = new SegmentData(textAnsi, t0, t1, minimumProbability, maximumProbability, (float)(sumProbability / numberOfTokens), language!); + var eventHandlerArgs = new SegmentData(textAnsi!, t0, t1, minimumProbability, maximumProbability, (float)(sumProbability / numberOfTokens), language!); foreach (var handler in options.OnSegmentEventHandlers) { From 2f428e183a0f7a14db8939470285c2c51c1aab3d Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Fri, 11 Oct 2024 20:19:37 +0200 Subject: [PATCH 29/79] Try again --- .github/workflows/build-all.yml | 12 ++++- .github/workflows/dotnet.yml | 12 +++-- .github/workflows/pack-all.yml | 61 ++++++++++++++++++++++ Whisper.net.Tests/Whisper.net.Tests.csproj | 22 ++++++++ Whisper.net.sln | 8 +-- Whisper.net/Whisper.net.csproj | 2 +- 6 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/pack-all.yml diff --git a/.github/workflows/build-all.yml b/.github/workflows/build-all.yml index df7b9aca..8c4f746a 100644 --- a/.github/workflows/build-all.yml +++ b/.github/workflows/build-all.yml @@ -52,4 +52,14 @@ jobs: - wasm - linux uses: ./.github/workflows/dotnet.yml - + + pack-all: + needs: + - dotnet-build + # - windows-cuda + # - windows-vulkan + # - windows-openvino + # - linux-cuda + # - linux-vulkan + # - macos-coreml + uses: ./.github/workflows/pack-all.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index c327c768..eef77c5a 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -17,7 +17,9 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0.x + dotnet-version: | + 8.0.x + 6.0.x - name: Download Artifacts id: download-artifact @@ -58,7 +60,9 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0.x + dotnet-version: | + 8.0.x + 6.0.x - name: Download Artifacts id: download-artifact @@ -98,7 +102,9 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0.x + dotnet-version: | + 8.0.x + 6.0.x - name: Download Artifacts id: download-artifact diff --git a/.github/workflows/pack-all.yml b/.github/workflows/pack-all.yml new file mode 100644 index 00000000..aa8561b9 --- /dev/null +++ b/.github/workflows/pack-all.yml @@ -0,0 +1,61 @@ +# This workflow will pack all the nuget packages +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net + +name: Pack All + +on: + workflow_call: + +jobs: + + pack-all: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + - name: Download Artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + merge-multiple: true + + - name: Install Java + uses: actions/setup-java@v2 + with: + distribution: 'microsoft' + java-version: '11' + + - name: Install .NET Workloads + run: | + dotnet workload install android --ignore-failed-sources + dotnet workload install ios --ignore-failed-sources + dotnet workload install tvos --ignore-failed-sources + dotnet workload install maccatalyst --ignore-failed-sources + + - name: Restore dependencies + run: dotnet restore ./Whisper.net.sln + + - name: Pack all + run: | + $xml = [Xml] (Get-Content .\Whisper.net\Whisper.net.csproj) + $versionObject = $xml.Project.PropertyGroup.Version + $version = "$versionObject".Trim() + $runNumber = ${{ github.run_number }} + $previewVersion = "$version-$runNumber" + Import-Module ./windows-scripts.ps1 + PackAll -Version $previewVersion + shell: pwsh + + + + - name: Publish nupkgs + uses: actions/upload-artifact@v4 + with: + name: nupkgs + path: | + nupkgs/*.nupkg diff --git a/Whisper.net.Tests/Whisper.net.Tests.csproj b/Whisper.net.Tests/Whisper.net.Tests.csproj index a0fde9d0..433b311c 100644 --- a/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -5,6 +5,7 @@ enable 12 false + true @@ -23,6 +24,27 @@ + + + + + true + true + whisper.net.test.app + Whisper.net.Test + + 11.0 + 13.1 + 11.0 + 21 + + 1.0 + 1 + + + + manual + diff --git a/Whisper.net.sln b/Whisper.net.sln index c5a7e980..ec549d12 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitignore = .gitignore + Directory.Packages.props = Directory.Packages.props readme.md = readme.md EndProjectSection EndProject @@ -19,18 +20,19 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C865649-4AED-4BBF-A7CA-BD68D21EF48F}" ProjectSection(SolutionItems) = preProject .github\workflows\android-native-build.yml = .github\workflows\android-native-build.yml - .github\workflows\dotnet.yml = .github\workflows\dotnet.yml .github\workflows\build-all.yml = .github\workflows\build-all.yml + .github\workflows\dotnet.yml = .github\workflows\dotnet.yml .github\workflows\linux-cuda-native-build.yml = .github\workflows\linux-cuda-native-build.yml .github\workflows\linux-native-build.yml = .github\workflows\linux-native-build.yml - .github\workflows\macos-coreml-native-build.yml = .github\workflows\macos-coreml-native-build.yml .github\workflows\linux-openvino-native-build.yml = .github\workflows\linux-openvino-native-build.yml + .github\workflows\macos-coreml-native-build.yml = .github\workflows\macos-coreml-native-build.yml .github\workflows\macos-native-build.yml = .github\workflows\macos-native-build.yml + .github\workflows\pack-all.yml = .github\workflows\pack-all.yml .github\workflows\wasm-native-build.yml = .github\workflows\wasm-native-build.yml .github\workflows\windows-cuda-native-build.yml = .github\workflows\windows-cuda-native-build.yml .github\workflows\windows-native-build.yml = .github\workflows\windows-native-build.yml - .github\workflows\windows-vulkan-native-build.yml = .github\workflows\windows-vulkan-native-build.yml .github\workflows\windows-openvino-native-build.yml = .github\workflows\windows-openvino-native-build.yml + .github\workflows\windows-vulkan-native-build.yml = .github\workflows\windows-vulkan-native-build.yml EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{52C6C243-3BD7-41CF-A0B0-1DE31AC2C884}" diff --git a/Whisper.net/Whisper.net.csproj b/Whisper.net/Whisper.net.csproj index 733d04f2..80268798 100755 --- a/Whisper.net/Whisper.net.csproj +++ b/Whisper.net/Whisper.net.csproj @@ -21,7 +21,7 @@ - net8.0 + net8.0;net6.0 From 3c33dd2c632566a450450815d69c8b850f7a18a6 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Fri, 11 Oct 2024 20:24:15 +0200 Subject: [PATCH 30/79] Removed RuntimeIdentifier --- Whisper.net.Tests/Whisper.net.Tests.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Whisper.net.Tests/Whisper.net.Tests.csproj b/Whisper.net.Tests/Whisper.net.Tests.csproj index 433b311c..e19be645 100644 --- a/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -4,8 +4,7 @@ enable enable 12 - false - true + true From 5a6cc936fe246f008090fdbcd7d41d5e6e67afa4 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Fri, 11 Oct 2024 20:26:31 +0200 Subject: [PATCH 31/79] Removed usemaui, we want classical android, ios, not maui --- Whisper.net.Tests/Whisper.net.Tests.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Whisper.net.Tests/Whisper.net.Tests.csproj b/Whisper.net.Tests/Whisper.net.Tests.csproj index e19be645..35df88b2 100644 --- a/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -27,7 +27,6 @@ - true true whisper.net.test.app Whisper.net.Test From ada001fd6efa4d9a2ad9efacf6f0287af6e5c20b Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Fri, 11 Oct 2024 20:46:21 +0200 Subject: [PATCH 32/79] silenced XA0101 --- Whisper.net.Tests/Whisper.net.Tests.csproj | 148 +++++++++++---------- 1 file changed, 75 insertions(+), 73 deletions(-) diff --git a/Whisper.net.Tests/Whisper.net.Tests.csproj b/Whisper.net.Tests/Whisper.net.Tests.csproj index 35df88b2..68480e87 100644 --- a/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -1,84 +1,86 @@ - - - enable - enable - 12 - true - + + + enable + enable + 12 + true + + XA0101 + - - net8.0;net6.0 - + + net8.0;net6.0 + - - - net8.0;net6.0;net472;net8.0-android - - - - - - net8.0;net6.0;net8.0-ios;net8.0-tvos;net8.0-maccatalyst - - + + + net8.0;net6.0;net472;net8.0-android + + - + + + net8.0;net6.0;net8.0-ios;net8.0-tvos;net8.0-maccatalyst + + - - - true - whisper.net.test.app - Whisper.net.Test - - 11.0 - 13.1 - 11.0 - 21 - 1.0 - 1 - - - - manual - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + true + whisper.net.test.app + Whisper.net.Test - - - + 11.0 + 13.1 + 11.0 + 21 - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - + 1.0 + 1 + + + + manual + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + \ No newline at end of file From b864a92145cdbd738bb8d603f6476c0dc15b828d Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Fri, 11 Oct 2024 21:01:21 +0200 Subject: [PATCH 33/79] aaa --- .../Platforms/Android/AndroidManifest.xml | 7 ++++ .../Platforms/MacCatalyst/Info.plist | 30 +++++++++++++++++ Whisper.net.Tests/Platforms/iOS/Info.plist | 32 +++++++++++++++++++ Whisper.net.Tests/Whisper.net.Tests.csproj | 1 + 4 files changed, 70 insertions(+) create mode 100644 Whisper.net.Tests/Platforms/Android/AndroidManifest.xml create mode 100644 Whisper.net.Tests/Platforms/MacCatalyst/Info.plist create mode 100644 Whisper.net.Tests/Platforms/iOS/Info.plist diff --git a/Whisper.net.Tests/Platforms/Android/AndroidManifest.xml b/Whisper.net.Tests/Platforms/Android/AndroidManifest.xml new file mode 100644 index 00000000..a44c804c --- /dev/null +++ b/Whisper.net.Tests/Platforms/Android/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Whisper.net.Tests/Platforms/MacCatalyst/Info.plist b/Whisper.net.Tests/Platforms/MacCatalyst/Info.plist new file mode 100644 index 00000000..b7a04a77 --- /dev/null +++ b/Whisper.net.Tests/Platforms/MacCatalyst/Info.plist @@ -0,0 +1,30 @@ + + + + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + + \ No newline at end of file diff --git a/Whisper.net.Tests/Platforms/iOS/Info.plist b/Whisper.net.Tests/Platforms/iOS/Info.plist new file mode 100644 index 00000000..20733a08 --- /dev/null +++ b/Whisper.net.Tests/Platforms/iOS/Info.plist @@ -0,0 +1,32 @@ + + + + + LSRequiresIPhoneOS + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + + \ No newline at end of file diff --git a/Whisper.net.Tests/Whisper.net.Tests.csproj b/Whisper.net.Tests/Whisper.net.Tests.csproj index 68480e87..1b5683a9 100644 --- a/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -32,6 +32,7 @@ true whisper.net.test.app Whisper.net.Test + true 11.0 13.1 From 0447d2a76f92505b521a6f5a92093d24df9b7c00 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Sat, 12 Oct 2024 19:38:45 +0200 Subject: [PATCH 34/79] Added Android tests --- .github/workflows/dotnet.yml | 88 ++-- Directory.Packages.props | 20 +- Whisper.net.Maui.Tests.sln | 200 ++++++++ .../Whisper.net.Runtime.targets | 16 +- .../Platforms/Android/AndroidManifest.xml | 7 - .../Platforms/MacCatalyst/Info.plist | 30 -- Whisper.net.Tests/Platforms/iOS/Info.plist | 32 -- Whisper.net.Tests/TestModelProvider.cs | 39 -- Whisper.net.Tests/Whisper.net.Tests.csproj | 87 ---- Whisper.net.sln | 52 +-- .../LibraryLoader/NativeLibraryLoader.cs | 50 +- .../LibraryLoader/UniversalLibraryLoader.cs | 2 +- Whisper.net/Logger/LogProvider.cs | 2 +- Whisper.net/Whisper.net.csproj | 17 +- nuget.config | 13 + tests/Whisper.net.Maui.Tests/App.xaml | 14 + tests/Whisper.net.Maui.Tests/App.xaml.cs | 13 + tests/Whisper.net.Maui.Tests/AppShell.xaml | 15 + tests/Whisper.net.Maui.Tests/AppShell.xaml.cs | 11 + tests/Whisper.net.Maui.Tests/MainPage.xaml | 36 ++ tests/Whisper.net.Maui.Tests/MainPage.xaml.cs | 37 ++ tests/Whisper.net.Maui.Tests/MauiProgram.cs | 27 ++ .../Platforms/Android/AndroidManifest.xml | 6 + .../Platforms/Android/HeadlessTestRunner.cs | 80 ++++ .../Platforms/Android/MainActivity.cs | 10 + .../Platforms/Android/MainApplication.cs | 20 + .../Android/MauiTestInstrumentation.cs | 120 +++++ .../Android/Resources/values/colors.xml | 6 + .../Platforms/MacCatalyst/AppDelegate.cs | 13 + .../Platforms/MacCatalyst/Entitlements.plist | 14 + .../Platforms/MacCatalyst/Info.plist | 38 ++ .../Platforms/MacCatalyst/Program.cs | 15 + .../Platforms/Tizen/Main.cs | 18 + .../Platforms/Tizen/tizen-manifest.xml | 15 + .../Platforms/iOS/AppDelegate.cs | 13 + .../Platforms/iOS/Info.plist | 32 ++ .../Platforms/iOS/Program.cs | 14 + .../iOS/Resources/PrivacyInfo.xcprivacy | 51 +++ .../Properties/launchSettings.json | 8 + .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107276 bytes .../Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111180 bytes .../Resources/Images/dotnet_bot.png | Bin 0 -> 69811 bytes .../Resources/Raw/AboutAssets.txt | 15 + .../Resources/Splash/splash.svg | 8 + .../Resources/Styles/Colors.xaml | 45 ++ .../Resources/Styles/Styles.xaml | 427 ++++++++++++++++++ tests/Whisper.net.Maui.Tests/TestDevice.cs | 23 + .../Whisper.net.Maui.Tests.csproj | 67 +++ .../Whisper.net.Tests}/FactoryTests.cs | 25 +- tests/Whisper.net.Tests/ModelFixture.cs | 37 ++ .../ProcessAsyncFunctionalTests.cs | 24 +- .../ProcessFunctionalTests.cs | 24 +- .../ProcessQuantizedTests.cs | 74 +-- .../Whisper.net.Tests.csproj | 51 +++ .../Whisper.net.Tests}/bush.wav | Bin .../Whisper.net.Tests}/junkchunk16khz.wav | Bin .../Whisper.net.Tests}/kennedy.wav | Bin .../Whisper.net.Tests}/multichannel.wav | Bin .../Whisper.net.Tests}/romana.wav | Bin 61 files changed, 1743 insertions(+), 370 deletions(-) create mode 100644 Whisper.net.Maui.Tests.sln delete mode 100644 Whisper.net.Tests/Platforms/Android/AndroidManifest.xml delete mode 100644 Whisper.net.Tests/Platforms/MacCatalyst/Info.plist delete mode 100644 Whisper.net.Tests/Platforms/iOS/Info.plist delete mode 100644 Whisper.net.Tests/TestModelProvider.cs delete mode 100644 Whisper.net.Tests/Whisper.net.Tests.csproj create mode 100644 tests/Whisper.net.Maui.Tests/App.xaml create mode 100644 tests/Whisper.net.Maui.Tests/App.xaml.cs create mode 100644 tests/Whisper.net.Maui.Tests/AppShell.xaml create mode 100644 tests/Whisper.net.Maui.Tests/AppShell.xaml.cs create mode 100644 tests/Whisper.net.Maui.Tests/MainPage.xaml create mode 100644 tests/Whisper.net.Maui.Tests/MainPage.xaml.cs create mode 100644 tests/Whisper.net.Maui.Tests/MauiProgram.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/Android/AndroidManifest.xml create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/Android/HeadlessTestRunner.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/Android/MainActivity.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/Android/MainApplication.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/Android/MauiTestInstrumentation.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/Android/Resources/values/colors.xml create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/MacCatalyst/AppDelegate.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/MacCatalyst/Entitlements.plist create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/MacCatalyst/Info.plist create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/MacCatalyst/Program.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/Tizen/Main.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/Tizen/tizen-manifest.xml create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/iOS/AppDelegate.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/iOS/Info.plist create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/iOS/Program.cs create mode 100644 tests/Whisper.net.Maui.Tests/Platforms/iOS/Resources/PrivacyInfo.xcprivacy create mode 100644 tests/Whisper.net.Maui.Tests/Properties/launchSettings.json create mode 100644 tests/Whisper.net.Maui.Tests/Resources/AppIcon/appicon.svg create mode 100644 tests/Whisper.net.Maui.Tests/Resources/AppIcon/appiconfg.svg create mode 100644 tests/Whisper.net.Maui.Tests/Resources/Fonts/OpenSans-Regular.ttf create mode 100644 tests/Whisper.net.Maui.Tests/Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 tests/Whisper.net.Maui.Tests/Resources/Images/dotnet_bot.png create mode 100644 tests/Whisper.net.Maui.Tests/Resources/Raw/AboutAssets.txt create mode 100644 tests/Whisper.net.Maui.Tests/Resources/Splash/splash.svg create mode 100644 tests/Whisper.net.Maui.Tests/Resources/Styles/Colors.xaml create mode 100644 tests/Whisper.net.Maui.Tests/Resources/Styles/Styles.xaml create mode 100644 tests/Whisper.net.Maui.Tests/TestDevice.cs create mode 100644 tests/Whisper.net.Maui.Tests/Whisper.net.Maui.Tests.csproj rename {Whisper.net.Tests => tests/Whisper.net.Tests}/FactoryTests.cs (77%) create mode 100644 tests/Whisper.net.Tests/ModelFixture.cs rename {Whisper.net.Tests => tests/Whisper.net.Tests}/ProcessAsyncFunctionalTests.cs (90%) rename {Whisper.net.Tests => tests/Whisper.net.Tests}/ProcessFunctionalTests.cs (89%) rename {Whisper.net.Tests => tests/Whisper.net.Tests}/ProcessQuantizedTests.cs (85%) create mode 100644 tests/Whisper.net.Tests/Whisper.net.Tests.csproj rename {Whisper.net.Tests => tests/Whisper.net.Tests}/bush.wav (100%) rename {Whisper.net.Tests => tests/Whisper.net.Tests}/junkchunk16khz.wav (100%) rename {Whisper.net.Tests => tests/Whisper.net.Tests}/kennedy.wav (100%) rename {Whisper.net.Tests => tests/Whisper.net.Tests}/multichannel.wav (100%) rename {Whisper.net.Tests => tests/Whisper.net.Tests}/romana.wav (100%) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index eef77c5a..94f386b2 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -27,19 +27,6 @@ jobs: with: merge-multiple: true - - name: Install Java - uses: actions/setup-java@v2 - with: - distribution: 'microsoft' - java-version: '11' - - - name: Install .NET Workloads - run: | - dotnet workload install android --ignore-failed-sources - dotnet workload install ios --ignore-failed-sources - dotnet workload install tvos --ignore-failed-sources - dotnet workload install maccatalyst --ignore-failed-sources - - name: Restore dependencies run: dotnet restore ./Whisper.net.sln @@ -69,20 +56,7 @@ jobs: uses: actions/download-artifact@v4 with: merge-multiple: true - - - name: Install Java - uses: actions/setup-java@v2 - with: - distribution: 'microsoft' - java-version: '11' - - - name: Install .NET Workloads - run: | - dotnet workload install android --ignore-failed-sources - dotnet workload install ios --ignore-failed-sources - dotnet workload install tvos --ignore-failed-sources - dotnet workload install maccatalyst --ignore-failed-sources - + - name: Restore dependencies run: dotnet restore ./Whisper.net.sln @@ -111,20 +85,64 @@ jobs: uses: actions/download-artifact@v4 with: merge-multiple: true + - name: Restore dependencies run: dotnet restore ./Whisper.net.sln - name: Build run: dotnet build ./Whisper.net.sln --no-restore -warnaserror - - - name: Check LDD for libwhisper - run: | - echo 'Checking ldd for libwhisper.so' - ldd ./Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libwhisper.so - echo 'Checking ldd for libggml.so' - ldd ./Whisper.net.Tests/bin/Debug/net8.0/runtimes/linux-x64/libggml.so - + - name: Test run: | dotnet test ./Whisper.net.sln --no-build + dotnet-android: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 8.0.x + 6.0.x + + - name: Enable KVM + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=k + + - name: Download Artifacts + id: download-artifact + uses: actions/download-artifact@v4 + with: + merge-multiple: true + + - name: Install dotnet workloads + run: dotnet workload install maui + + - name: Install xharness + run: dotnet tool install Microsoft.DotNet.XHarness.CLI --global --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json -version "10.0.0-prerelease*" + + - name: Restore dependencies + run: dotnet restore ./Whisper.net.Maui.Tests.sln + + - name: Publish android build + run: dotnet publish .\tests\Whisper.net.Maui.Tests\Whisper.net.Maui.Tests.csproj -c Debug -f net8.0-android -p:EmbedAssembliesIntoApk=true + + + - name: Run tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 30 + script: xharness android test --app .\tests\Whisper.net.Maui.Tests\bin\Debug\net8.0-android\com.companyname.whisper.net.maui.tests-Signed.apk -p com.companyname.whisper.net.maui.tests -i com.companyname.whisper.net.maui.tests.AndroidMauiTestInstrumentation -o xharnessoutput + + - name: Upload output + uses: actions/upload-artifact@v4 + with: + name: android-test-results + path: | + xharnessoutput/*/* diff --git a/Directory.Packages.props b/Directory.Packages.props index 8f8b6618..971296dd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,11 +7,19 @@ - - - - - + + + + + + + + + + + + + - \ No newline at end of file + diff --git a/Whisper.net.Maui.Tests.sln b/Whisper.net.Maui.Tests.sln new file mode 100644 index 00000000..a0ff216e --- /dev/null +++ b/Whisper.net.Maui.Tests.sln @@ -0,0 +1,200 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33318.248 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whisper.net.Demo", "Whisper.net.Demo\Whisper.net.Demo.csproj", "{C1C29732-1BC2-477D-A116-C5003E1D0C85}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2C8F58A8-37D9-4E96-AE73-B3B37AEC10C1}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + .gitignore = .gitignore + Directory.Packages.props = Directory.Packages.props + nuget.config = nuget.config + readme.md = readme.md + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whisper.net", "Whisper.net\Whisper.net.csproj", "{5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C865649-4AED-4BBF-A7CA-BD68D21EF48F}" + ProjectSection(SolutionItems) = preProject + .github\workflows\android-native-build.yml = .github\workflows\android-native-build.yml + .github\workflows\build-all.yml = .github\workflows\build-all.yml + .github\workflows\dotnet.yml = .github\workflows\dotnet.yml + .github\workflows\linux-cuda-native-build.yml = .github\workflows\linux-cuda-native-build.yml + .github\workflows\linux-native-build.yml = .github\workflows\linux-native-build.yml + .github\workflows\linux-openvino-native-build.yml = .github\workflows\linux-openvino-native-build.yml + .github\workflows\macos-coreml-native-build.yml = .github\workflows\macos-coreml-native-build.yml + .github\workflows\macos-native-build.yml = .github\workflows\macos-native-build.yml + .github\workflows\pack-all.yml = .github\workflows\pack-all.yml + .github\workflows\wasm-native-build.yml = .github\workflows\wasm-native-build.yml + .github\workflows\windows-cuda-native-build.yml = .github\workflows\windows-cuda-native-build.yml + .github\workflows\windows-native-build.yml = .github\workflows\windows-native-build.yml + .github\workflows\windows-openvino-native-build.yml = .github\workflows\windows-openvino-native-build.yml + .github\workflows\windows-vulkan-native-build.yml = .github\workflows\windows-vulkan-native-build.yml + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{52C6C243-3BD7-41CF-A0B0-1DE31AC2C884}" + ProjectSection(SolutionItems) = preProject + Makefile = Makefile + windows-scripts.ps1 = windows-scripts.ps1 + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "runtimes", "runtimes", "{CC45AC94-3CD7-45D8-A847-2D9C06E1806A}" + ProjectSection(SolutionItems) = preProject + Whisper.net.Runtime.CoreML.nuspec = Whisper.net.Runtime.CoreML.nuspec + Whisper.net.Runtime.CoreML\Whisper.net.Runtime.CoreML.targets = Whisper.net.Runtime.CoreML\Whisper.net.Runtime.CoreML.targets + Whisper.net.Runtime.Cuda.Linux.nuspec = Whisper.net.Runtime.Cuda.Linux.nuspec + Whisper.net.Runtime.Cuda.Linux\Whisper.net.Runtime.Cuda.Linux.targets = Whisper.net.Runtime.Cuda.Linux\Whisper.net.Runtime.Cuda.Linux.targets + Whisper.net.Runtime.Cuda.nuspec = Whisper.net.Runtime.Cuda.nuspec + Whisper.net.Runtime.Cuda.Windows.nuspec = Whisper.net.Runtime.Cuda.Windows.nuspec + Whisper.net.Runtime.Cuda.Windows\Whisper.net.Runtime.Cuda.Windows.targets = Whisper.net.Runtime.Cuda.Windows\Whisper.net.Runtime.Cuda.Windows.targets + Whisper.net.Runtime.nuspec = Whisper.net.Runtime.nuspec + Whisper.net.Runtime.OpenVino.nuspec = Whisper.net.Runtime.OpenVino.nuspec + Whisper.net.Runtime.OpenVino\Whisper.net.Runtime.OpenVino.targets = Whisper.net.Runtime.OpenVino\Whisper.net.Runtime.OpenVino.targets + Whisper.net.Runtime\Whisper.net.Runtime.targets = Whisper.net.Runtime\Whisper.net.Runtime.targets + Whisper.net.Runtime.Vulkan.nuspec = Whisper.net.Runtime.Vulkan.nuspec + Whisper.net.Runtime.Vulkan\Whisper.net.Runtime.Vulkan.targets = Whisper.net.Runtime.Vulkan\Whisper.net.Runtime.Vulkan.targets + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Whisper.net.Maui.Tests", "tests\Whisper.net.Maui.Tests\Whisper.net.Maui.Tests.csproj", "{2D16B02C-55D6-4B9B-B99E-A0529C407A69}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Whisper.net.Tests", "tests\Whisper.net.Tests\Whisper.net.Tests.csproj", "{CE567791-96B8-4377-AF4F-49D75035348D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + MinSizeRel|Any CPU = MinSizeRel|Any CPU + MinSizeRel|x64 = MinSizeRel|x64 + MinSizeRel|x86 = MinSizeRel|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + RelWithDebInfo|Any CPU = RelWithDebInfo|Any CPU + RelWithDebInfo|x64 = RelWithDebInfo|x64 + RelWithDebInfo|x86 = RelWithDebInfo|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Debug|x64.ActiveCfg = Debug|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Debug|x64.Build.0 = Debug|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Debug|x86.ActiveCfg = Debug|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Debug|x86.Build.0 = Debug|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.MinSizeRel|Any CPU.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.MinSizeRel|Any CPU.Build.0 = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.MinSizeRel|x64.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.MinSizeRel|x64.Build.0 = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.MinSizeRel|x86.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.MinSizeRel|x86.Build.0 = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Release|Any CPU.Build.0 = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Release|x64.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Release|x64.Build.0 = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Release|x86.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.Release|x86.Build.0 = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {C1C29732-1BC2-477D-A116-C5003E1D0C85}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Debug|x64.ActiveCfg = Debug|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Debug|x64.Build.0 = Debug|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Debug|x86.ActiveCfg = Debug|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Debug|x86.Build.0 = Debug|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.MinSizeRel|Any CPU.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.MinSizeRel|Any CPU.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.MinSizeRel|x64.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.MinSizeRel|x64.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.MinSizeRel|x86.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.MinSizeRel|x86.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Release|Any CPU.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Release|x64.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Release|x64.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Release|x86.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.Release|x86.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|x64.ActiveCfg = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|x64.Build.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|x64.Deploy.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|x86.ActiveCfg = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|x86.Build.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Debug|x86.Deploy.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|Any CPU.Deploy.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|x64.Deploy.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|x86.Build.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.MinSizeRel|x86.Deploy.0 = Debug|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|Any CPU.Build.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|Any CPU.Deploy.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|x64.ActiveCfg = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|x64.Build.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|x64.Deploy.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|x86.ActiveCfg = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|x86.Build.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.Release|x86.Deploy.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|Any CPU.Deploy.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|x64.Deploy.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + {2D16B02C-55D6-4B9B-B99E-A0529C407A69}.RelWithDebInfo|x86.Deploy.0 = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Debug|x64.ActiveCfg = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Debug|x64.Build.0 = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Debug|x86.ActiveCfg = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Debug|x86.Build.0 = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.MinSizeRel|x86.Build.0 = Debug|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Release|Any CPU.Build.0 = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Release|x64.ActiveCfg = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Release|x64.Build.0 = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Release|x86.ActiveCfg = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.Release|x86.Build.0 = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {CE567791-96B8-4377-AF4F-49D75035348D}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {5C865649-4AED-4BBF-A7CA-BD68D21EF48F} = {2C8F58A8-37D9-4E96-AE73-B3B37AEC10C1} + {52C6C243-3BD7-41CF-A0B0-1DE31AC2C884} = {2C8F58A8-37D9-4E96-AE73-B3B37AEC10C1} + {CC45AC94-3CD7-45D8-A847-2D9C06E1806A} = {2C8F58A8-37D9-4E96-AE73-B3B37AEC10C1} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F5CAA926-1B7D-3A67-9130-E6EFE3E9DFD9} + EndGlobalSection +EndGlobal diff --git a/Whisper.net.Runtime/Whisper.net.Runtime.targets b/Whisper.net.Runtime/Whisper.net.Runtime.targets index 52d34158..47a9daaa 100644 --- a/Whisper.net.Runtime/Whisper.net.Runtime.targets +++ b/Whisper.net.Runtime/Whisper.net.Runtime.targets @@ -88,25 +88,25 @@ Condition="$(AndroidSupportedAbis.Contains('x86')) or $(RuntimeIdentifiers.Contains('android-x86'))"> - whisper-x86\libwhisper.so + lib\x86\libwhisper.so x86 - whisper-x86\libggml.so + lib\x86\libggml.so x86 - - whisper-x86_64\libwhisper.so + lib\x86_64\libwhisper.so x86_64 - - whisper-x86_64\libggml.so + lib\x86_64\libggml.so x86_64 @@ -114,12 +114,12 @@ Condition="$(AndroidSupportedAbis.Contains('arm64-v8a')) or $(RuntimeIdentifiers.Contains('android-arm64'))"> - whisper-armv8\libwhisper.so + lib\armv8\libwhisper.so arm64-v8a - whisper-armv8\libggml.so + lib\armv8\libggml.so arm64-v8a diff --git a/Whisper.net.Tests/Platforms/Android/AndroidManifest.xml b/Whisper.net.Tests/Platforms/Android/AndroidManifest.xml deleted file mode 100644 index a44c804c..00000000 --- a/Whisper.net.Tests/Platforms/Android/AndroidManifest.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/Whisper.net.Tests/Platforms/MacCatalyst/Info.plist b/Whisper.net.Tests/Platforms/MacCatalyst/Info.plist deleted file mode 100644 index b7a04a77..00000000 --- a/Whisper.net.Tests/Platforms/MacCatalyst/Info.plist +++ /dev/null @@ -1,30 +0,0 @@ - - - - - UIDeviceFamily - - 1 - 2 - - UIRequiredDeviceCapabilities - - arm64 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - XSAppIconAssets - Assets.xcassets/appicon.appiconset - - \ No newline at end of file diff --git a/Whisper.net.Tests/Platforms/iOS/Info.plist b/Whisper.net.Tests/Platforms/iOS/Info.plist deleted file mode 100644 index 20733a08..00000000 --- a/Whisper.net.Tests/Platforms/iOS/Info.plist +++ /dev/null @@ -1,32 +0,0 @@ - - - - - LSRequiresIPhoneOS - - UIDeviceFamily - - 1 - 2 - - UIRequiredDeviceCapabilities - - arm64 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - XSAppIconAssets - Assets.xcassets/appicon.appiconset - - \ No newline at end of file diff --git a/Whisper.net.Tests/TestModelProvider.cs b/Whisper.net.Tests/TestModelProvider.cs deleted file mode 100644 index 40f69c42..00000000 --- a/Whisper.net.Tests/TestModelProvider.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Licensed under the MIT license: https://opensource.org/licenses/MIT - -using NUnit.Framework; -using Whisper.net.Ggml; - -namespace Whisper.net.Tests; - -[SetUpFixture] -internal class TestModelProvider -{ - private static string ggmlModelTiny = string.Empty; - private static string ggmlModelTinyQ5 = string.Empty; - - [OneTimeSetUp] - public static async Task SetupAsync() - { - ggmlModelTiny = await DownloadModelAsync(GgmlType.Tiny); - ggmlModelTinyQ5 = await DownloadModelAsync(GgmlType.Tiny, QuantizationType.Q5_0); - } - - private static async Task DownloadModelAsync(GgmlType type, QuantizationType quantizationType = QuantizationType.NoQuantization) - { - var ggmlModelPath = Path.GetTempFileName(); - var model = await WhisperGgmlDownloader.GetGgmlModelAsync(type, quantizationType); - using var fileWriter = File.OpenWrite(ggmlModelPath); - await model.CopyToAsync(fileWriter); - return ggmlModelPath; - } - - [OneTimeTearDown] - public void TearDown() - { - File.Delete(ggmlModelTiny); - File.Delete(ggmlModelTinyQ5); - } - - public static string GgmlModelTiny => ggmlModelTiny; - public static string GgmlModelTinyQ5 => ggmlModelTinyQ5; -} diff --git a/Whisper.net.Tests/Whisper.net.Tests.csproj b/Whisper.net.Tests/Whisper.net.Tests.csproj deleted file mode 100644 index 1b5683a9..00000000 --- a/Whisper.net.Tests/Whisper.net.Tests.csproj +++ /dev/null @@ -1,87 +0,0 @@ - - - - enable - enable - 12 - true - - XA0101 - - - - net8.0;net6.0 - - - - - net8.0;net6.0;net472;net8.0-android - - - - - - net8.0;net6.0;net8.0-ios;net8.0-tvos;net8.0-maccatalyst - - - - - - - - true - whisper.net.test.app - Whisper.net.Test - true - - 11.0 - 13.1 - 11.0 - 21 - - 1.0 - 1 - - - - manual - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - \ No newline at end of file diff --git a/Whisper.net.sln b/Whisper.net.sln index ec549d12..1279d9f5 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -15,8 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whisper.net", "Whisper.net\Whisper.net.csproj", "{5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whisper.net.Tests", "Whisper.net.Tests\Whisper.net.Tests.csproj", "{333764F7-81DC-4425-AF5C-B438D973EE13}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C865649-4AED-4BBF-A7CA-BD68D21EF48F}" ProjectSection(SolutionItems) = preProject .github\workflows\android-native-build.yml = .github\workflows\android-native-build.yml @@ -58,6 +56,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "runtimes", "runtimes", "{CC Whisper.net.Runtime.Vulkan\Whisper.net.Runtime.Vulkan.targets = Whisper.net.Runtime.Vulkan\Whisper.net.Runtime.Vulkan.targets EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Whisper.net.Tests", "tests\Whisper.net.Tests\Whisper.net.Tests.csproj", "{308C8766-228B-4C72-9DA0-1F51B5CAEEDA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -122,30 +122,30 @@ Global {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|x64.Build.0 = Release|Any CPU {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU {5D1F57EB-AF79-419C-8DCB-E23F7BEC3E8C}.RelWithDebInfo|x86.Build.0 = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Debug|Any CPU.Build.0 = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Debug|x64.ActiveCfg = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Debug|x64.Build.0 = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Debug|x86.ActiveCfg = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Debug|x86.Build.0 = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.MinSizeRel|x64.Build.0 = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.MinSizeRel|x86.Build.0 = Debug|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Release|Any CPU.ActiveCfg = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Release|Any CPU.Build.0 = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Release|x64.ActiveCfg = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Release|x64.Build.0 = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Release|x86.ActiveCfg = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.Release|x86.Build.0 = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.RelWithDebInfo|x64.Build.0 = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU - {333764F7-81DC-4425-AF5C-B438D973EE13}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Debug|x64.ActiveCfg = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Debug|x64.Build.0 = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Debug|x86.ActiveCfg = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Debug|x86.Build.0 = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.MinSizeRel|x86.Build.0 = Debug|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Release|Any CPU.Build.0 = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Release|x64.ActiveCfg = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Release|x64.Build.0 = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Release|x86.ActiveCfg = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.Release|x86.Build.0 = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {308C8766-228B-4C72-9DA0-1F51B5CAEEDA}.RelWithDebInfo|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs index d9fa7da4..fc7ab1f1 100644 --- a/Whisper.net/LibraryLoader/NativeLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/NativeLibraryLoader.cs @@ -11,8 +11,10 @@ public static class NativeLibraryLoader { internal static LoadResult LoadNativeLibrary() { -#if IOS || MACCATALYST || TVOS || ANDROID - return LoadResult.Success(new DllImportsInternalNativeWhisper()); +#if IOS || MACCATALYST || TVOS + return LoadResult.Success(new DllImportsNativeWhisper()); +#elif ANDROID + return LoadResult.Success(new DllImportsNativeWhisper()); #else // If the user has handled loading the library themselves, we don't need to do anything. if (RuntimeOptions.Instance.BypassLoading @@ -82,7 +84,7 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", // We don't have any error, so we couldn't even find some library to load. if (lastError == null) { - throw new FileNotFoundException($"Native Library not found in default paths. " + + throw new FileNotFoundException($"Native Library not found in default paths." + $"Verify you have have included the native Whisper library in your application, " + $"or install the default libraries with the Whisper.net.Runtime NuGet."); } @@ -114,36 +116,40 @@ private static string GetLibraryPath(string platform, string libraryName, string _ => throw new PlatformNotSupportedException($"Unsupported OS platform, architecture: {RuntimeInformation.OSArchitecture}") }; - var assemblySearchPath = new[] + var assemblySearchPaths = new[] { AppDomain.CurrentDomain.RelativeSearchPath, + AppDomain.CurrentDomain.BaseDirectory, Path.GetDirectoryName(typeof(NativeLibraryLoader).Assembly.Location), Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) - }.Where(it => !string.IsNullOrEmpty(it)).FirstOrDefault(); - - var runtimesPath = string.IsNullOrEmpty(assemblySearchPath) - ? "runtimes" - : Path.Combine(assemblySearchPath, "runtimes"); + }.Where(it => !string.IsNullOrEmpty(it)); foreach (var library in RuntimeOptions.Instance.RuntimeLibraryOrder) { - var runtimePath = library switch - { - RuntimeLibrary.Cuda => Path.Combine(runtimesPath, "cuda", $"{platform}-{architecture}"), - RuntimeLibrary.Vulkan => Path.Combine(runtimesPath, "vulkan", $"{platform}-{architecture}"), - RuntimeLibrary.Cpu => Path.Combine(runtimesPath, $"{platform}-{architecture}"), - RuntimeLibrary.CoreML => Path.Combine(runtimesPath, "coreml", $"{platform}-{architecture}"), - RuntimeLibrary.OpenVino => Path.Combine(runtimesPath, "openvino", $"{platform}-{architecture}"), - _ => throw new InvalidOperationException("Unknown runtime library") - }; - - if (Directory.Exists(runtimePath)) + foreach (var assemblySearchPath in assemblySearchPaths) { - yield return (runtimePath, library); + var runtimesPath = string.IsNullOrEmpty(assemblySearchPath) + ? "runtimes" + : Path.Combine(assemblySearchPath, "runtimes"); + var runtimePath = library switch + { + RuntimeLibrary.Cuda => Path.Combine(runtimesPath, "cuda", $"{platform}-{architecture}"), + RuntimeLibrary.Vulkan => Path.Combine(runtimesPath, "vulkan", $"{platform}-{architecture}"), + RuntimeLibrary.Cpu => Path.Combine(runtimesPath, $"{platform}-{architecture}"), + RuntimeLibrary.CoreML => Path.Combine(runtimesPath, "coreml", $"{platform}-{architecture}"), + RuntimeLibrary.OpenVino => Path.Combine(runtimesPath, "openvino", $"{platform}-{architecture}"), + _ => throw new InvalidOperationException("Unknown runtime library") + }; + + if (Directory.Exists(runtimePath)) + { + yield return (runtimePath, library); + } } + } #endif - } + } } diff --git a/Whisper.net/LibraryLoader/UniversalLibraryLoader.cs b/Whisper.net/LibraryLoader/UniversalLibraryLoader.cs index 941a9aa6..c0719cc8 100644 --- a/Whisper.net/LibraryLoader/UniversalLibraryLoader.cs +++ b/Whisper.net/LibraryLoader/UniversalLibraryLoader.cs @@ -13,7 +13,7 @@ public string GetLastError() public IntPtr OpenLibrary(string fileName, bool global) { - return NativeLibrary.Load(fileName); + return NativeLibrary.Load(fileName, System.Reflection.Assembly.GetExecutingAssembly(), DllImportSearchPath.AssemblyDirectory); } } #endif diff --git a/Whisper.net/Logger/LogProvider.cs b/Whisper.net/Logger/LogProvider.cs index 7f09cf04..06a7f7b8 100644 --- a/Whisper.net/Logger/LogProvider.cs +++ b/Whisper.net/Logger/LogProvider.cs @@ -32,8 +32,8 @@ internal static void InitializeLogging(INativeWhisper nativeWhisper) funcPointer = (IntPtr)onLogging; } #endif - nativeWhisper.Whisper_Log_Set(funcPointer, IntPtr.Zero); nativeWhisper.Ggml_log_set(funcPointer, IntPtr.Zero); + nativeWhisper.Whisper_Log_Set(funcPointer, IntPtr.Zero); } #if NETSTANDARD diff --git a/Whisper.net/Whisper.net.csproj b/Whisper.net/Whisper.net.csproj index 80268798..457e919c 100755 --- a/Whisper.net/Whisper.net.csproj +++ b/Whisper.net/Whisper.net.csproj @@ -20,11 +20,15 @@ - - net8.0;net6.0 + + net8.0;net6.0;netstandard2.0 - + + TRUE + + + net8.0;net6.0;netstandard2.0;net8.0-ios;net8.0-tvos;net8.0-maccatalyst;net8.0-android @@ -36,5 +40,10 @@ + + + + + - \ No newline at end of file + diff --git a/nuget.config b/nuget.config index 70f6b824..0cede15d 100644 --- a/nuget.config +++ b/nuget.config @@ -3,6 +3,19 @@ + + + + + + + + + + + + + diff --git a/tests/Whisper.net.Maui.Tests/App.xaml b/tests/Whisper.net.Maui.Tests/App.xaml new file mode 100644 index 00000000..b3d10e16 --- /dev/null +++ b/tests/Whisper.net.Maui.Tests/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/tests/Whisper.net.Maui.Tests/App.xaml.cs b/tests/Whisper.net.Maui.Tests/App.xaml.cs new file mode 100644 index 00000000..a48d618a --- /dev/null +++ b/tests/Whisper.net.Maui.Tests/App.xaml.cs @@ -0,0 +1,13 @@ +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +namespace Whisper.net.Maui.Tests; + +public partial class App : Application +{ + public App() + { + InitializeComponent(); + + MainPage = new AppShell(); + } +} diff --git a/tests/Whisper.net.Maui.Tests/AppShell.xaml b/tests/Whisper.net.Maui.Tests/AppShell.xaml new file mode 100644 index 00000000..08632768 --- /dev/null +++ b/tests/Whisper.net.Maui.Tests/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/tests/Whisper.net.Maui.Tests/AppShell.xaml.cs b/tests/Whisper.net.Maui.Tests/AppShell.xaml.cs new file mode 100644 index 00000000..a5c1dc77 --- /dev/null +++ b/tests/Whisper.net.Maui.Tests/AppShell.xaml.cs @@ -0,0 +1,11 @@ +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +namespace Whisper.net.Maui.Tests; + +public partial class AppShell : Shell +{ + public AppShell() + { + InitializeComponent(); + } +} diff --git a/tests/Whisper.net.Maui.Tests/MainPage.xaml b/tests/Whisper.net.Maui.Tests/MainPage.xaml new file mode 100644 index 00000000..641aa0ae --- /dev/null +++ b/tests/Whisper.net.Maui.Tests/MainPage.xaml @@ -0,0 +1,36 @@ + + + + + + + +