diff --git a/.github/workflows/main.ci.yml b/.github/workflows/main.ci.yml
index 36fd017..c7b1975 100644
--- a/.github/workflows/main.ci.yml
+++ b/.github/workflows/main.ci.yml
@@ -129,56 +129,53 @@ jobs:
needs: build
runs-on: ubuntu-latest
-
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- - name: Install apt packages
- uses: awalsh128/cache-apt-pkgs-action@v1.2.4
- with:
- packages: mono-mcs nuget
-
- name: Download Linux aprilasr
uses: actions/download-artifact@master
with:
name: libaprilasr.so
- path: ${{github.workspace}}/bindings/csharp/nuget/build/lib/linux-x64/
+ path: ${{github.workspace}}/bindings/csharp/AprilAsr/build/lib/linux-x64/
- name: Download Linux onnxruntime
uses: actions/download-artifact@master
with:
name: libonnxruntime.so
- path: ${{github.workspace}}/bindings/csharp/nuget/build/lib/linux-x64/
+ path: ${{github.workspace}}/bindings/csharp/AprilAsr/build/lib/linux-x64/
- name: Download Windows aprilasr
uses: actions/download-artifact@master
with:
name: libaprilasr.dll
- path: ${{github.workspace}}/bindings/csharp/nuget/build/lib/win-x64/
+ path: ${{github.workspace}}/bindings/csharp/AprilAsr/build/lib/win-x64/
- name: Download Windows onnxruntime
uses: actions/download-artifact@master
with:
name: onnxruntime.dll
- path: ${{github.workspace}}/bindings/csharp/nuget/build/lib/win-x64/
+ path: ${{github.workspace}}/bindings/csharp/AprilAsr/build/lib/win-x64/
- name: Display structure of downloaded files
run: ls -R
- working-directory: ${{github.workspace}}/bindings/csharp/nuget/build/lib
+ working-directory: ${{github.workspace}}/bindings/csharp/AprilAsr/build/lib
+
+ - name: Setup .NET SDK
+ uses: actions/setup-dotnet@v1
- name: Build C# bindings
- working-directory: ${{github.workspace}}/bindings/csharp/nuget
- run: mcs -out:lib/netstandard2.0/AprilAsr.dll -target:library src/*.cs
+ working-directory: ${{github.workspace}}/bindings/csharp/AprilAsr
+ run: dotnet build -c Release
- name: Run nuget pack
- working-directory: ${{github.workspace}}/bindings/csharp/nuget
- run: mkdir out && nuget pack -Verbosity detailed -OutputDirectory out
+ working-directory: ${{github.workspace}}/bindings/csharp/AprilAsr
+ run: mkdir out && dotnet pack -c Release --no-build --output out
- name: Upload nupkg
uses: actions/upload-artifact@v3.1.0
with:
name: nupkg
- path: ${{github.workspace}}/bindings/csharp/nuget/out
\ No newline at end of file
+ path: ${{github.workspace}}/bindings/csharp/AprilAsr/out
diff --git a/.gitignore b/.gitignore
index dc153dd..4e17248 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,9 +11,7 @@
*.dll
*.exp
*.exe
-*.nupkg
-bindings/csharp/AprilAsrDemo/bin
-bindings/csharp/AprilAsrDemo/obj
+
bindings/python/build
bindings/python/dist
april-docs/src/csharp/html
diff --git a/april-docs/src/csharp/Doxyfile b/april-docs/src/csharp/Doxyfile
index c668662..5ea42fa 100644
--- a/april-docs/src/csharp/Doxyfile
+++ b/april-docs/src/csharp/Doxyfile
@@ -864,7 +864,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.
-INPUT = ../../../bindings/csharp/nuget/src
+INPUT = ../../../bindings/csharp/AprilAsr
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
diff --git a/bindings/csharp/.gitignore b/bindings/csharp/.gitignore
new file mode 100644
index 0000000..fba8e47
--- /dev/null
+++ b/bindings/csharp/.gitignore
@@ -0,0 +1,402 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+[Ll]ogs/
+
+[Oo]utput/
+
+
+!.devcontainer/bin
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.tlog
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio 6 auto-generated project file (contains which files were open etc.)
+*.vbp
+
+# Visual Studio 6 workspace and project file (working project files containing files to include in project)
+*.dsw
+*.dsp
+
+# Visual Studio 6 technical files
+*.ncb
+*.aps
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# Visual Studio History (VSHistory) files
+.vshistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
+
+# VS Code files for those working on multiple tools
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+*.code-workspace
+
+# Local History for Visual Studio Code
+.history/
+
+# Windows Installer files from build outputs
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# JetBrains Rider
+*.sln.iml
diff --git a/bindings/csharp/AprilAsr/AprilAsr.csproj b/bindings/csharp/AprilAsr/AprilAsr.csproj
new file mode 100644
index 0000000..a17eefc
--- /dev/null
+++ b/bindings/csharp/AprilAsr/AprilAsr.csproj
@@ -0,0 +1,47 @@
+
+
+
+ netstandard2.0;netstandard2.1
+ true
+ AprilAsr
+ 0.0.1.6
+ abb128
+ GPL-3.0-only
+ https://abb128.github.io/april-asr/
+ April Speech Recognition
+ Offline realtime speech recognition
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bindings/csharp/nuget/src/AprilAsrPINVOKE.cs b/bindings/csharp/AprilAsr/AprilAsrPINVOKE.cs
similarity index 76%
rename from bindings/csharp/nuget/src/AprilAsrPINVOKE.cs
rename to bindings/csharp/AprilAsr/AprilAsrPINVOKE.cs
index 5b26cc7..297c4d8 100644
--- a/bindings/csharp/nuget/src/AprilAsrPINVOKE.cs
+++ b/bindings/csharp/AprilAsr/AprilAsrPINVOKE.cs
@@ -1,4 +1,5 @@
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using AprilAsr;
@@ -33,41 +34,55 @@ internal struct AprilConfig
public int flags;
}
+
internal class AprilAsrPINVOKE
{
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aam_api_init", CallingConvention = CallingConvention.Cdecl)]
internal static extern void aam_api_init(int version);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aam_create_model", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr aam_create_model(string path);
+
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aam_get_name", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr aam_get_name(IntPtr handle);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aam_get_description", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr aam_get_description(IntPtr handle);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aam_get_language", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr aam_get_language(IntPtr handle);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aam_get_sample_rate", CallingConvention = CallingConvention.Cdecl)]
internal static extern int aam_get_sample_rate(IntPtr handle);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aam_free", CallingConvention = CallingConvention.Cdecl)]
internal static extern void aam_free(IntPtr handle);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aas_create_session", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr aas_create_session(IntPtr model, AprilConfig config);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aas_feed_pcm16", CallingConvention = CallingConvention.Cdecl)]
internal static extern void aas_feed_pcm16(IntPtr session, short[] samples, int num_samples);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aas_flush", CallingConvention = CallingConvention.Cdecl)]
internal static extern void aas_flush(IntPtr session);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aas_realtime_get_speedup", CallingConvention = CallingConvention.Cdecl)]
internal static extern float aas_realtime_get_speedup(IntPtr session);
+ [DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
[DllImport("libaprilasr", EntryPoint="aas_free", CallingConvention=CallingConvention.Cdecl)]
internal static extern void aas_free(IntPtr session);
@@ -76,14 +91,22 @@ static AprilAsrPINVOKE()
aam_api_init(1);
}
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static string PtrToStringUTF8(System.IntPtr ptr)
{
+#if NETSTANDARD2_0
int len = 0;
while (System.Runtime.InteropServices.Marshal.ReadByte(ptr, len) != 0)
len++;
byte[] array = new byte[len];
System.Runtime.InteropServices.Marshal.Copy(ptr, array, 0, len);
return System.Text.Encoding.UTF8.GetString(array);
+#endif
+#if NETSTANDARD2_1_OR_GREATER
+ return Marshal.PtrToStringUTF8(ptr);
+#endif
+
}
}
}
diff --git a/bindings/csharp/nuget/src/AprilModel.cs b/bindings/csharp/AprilAsr/AprilModel.cs
similarity index 100%
rename from bindings/csharp/nuget/src/AprilModel.cs
rename to bindings/csharp/AprilAsr/AprilModel.cs
diff --git a/bindings/csharp/nuget/src/AprilSession.cs b/bindings/csharp/AprilAsr/AprilSession.cs
similarity index 98%
rename from bindings/csharp/nuget/src/AprilSession.cs
rename to bindings/csharp/AprilAsr/AprilSession.cs
index f01559c..5e2bf68 100644
--- a/bindings/csharp/nuget/src/AprilSession.cs
+++ b/bindings/csharp/AprilAsr/AprilSession.cs
@@ -89,7 +89,8 @@ public AprilSession(AprilModel model, SessionCallback callback, bool async = fal
else if(async) config.flags = 1;
else config.flags = 0;
- if(speakerName.Length > 0){
+ if(string.IsNullOrWhiteSpace(speakerName))
+ {
int hash = speakerName.GetHashCode();
config.speaker.data[0] = (byte)(hash >> 24);
diff --git a/bindings/csharp/nuget/src/AprilToken.cs b/bindings/csharp/AprilAsr/AprilToken.cs
similarity index 100%
rename from bindings/csharp/nuget/src/AprilToken.cs
rename to bindings/csharp/AprilAsr/AprilToken.cs
diff --git a/bindings/csharp/nuget/build/lib/linux-x64/.keep-me b/bindings/csharp/AprilAsr/build/lib/linux-x64/.keep-me
similarity index 100%
rename from bindings/csharp/nuget/build/lib/linux-x64/.keep-me
rename to bindings/csharp/AprilAsr/build/lib/linux-x64/.keep-me
diff --git a/bindings/csharp/nuget/build/lib/win-x64/.keep-me b/bindings/csharp/AprilAsr/build/lib/win-x64/.keep-me
similarity index 100%
rename from bindings/csharp/nuget/build/lib/win-x64/.keep-me
rename to bindings/csharp/AprilAsr/build/lib/win-x64/.keep-me
diff --git a/bindings/csharp/AprilAsrDemo/AprilAsrDemo.csproj b/bindings/csharp/AprilAsrDemo/AprilAsrDemo.csproj
index 48b8fce..ed8233b 100644
--- a/bindings/csharp/AprilAsrDemo/AprilAsrDemo.csproj
+++ b/bindings/csharp/AprilAsrDemo/AprilAsrDemo.csproj
@@ -8,7 +8,7 @@
- $(RestoreSources);../nuget
+ $(RestoreSources);../AprilAsr/bin/Debug
diff --git a/bindings/csharp/nuget/AprilAsr.nuspec b/bindings/csharp/nuget/AprilAsr.nuspec
deleted file mode 100644
index d4d80a0..0000000
--- a/bindings/csharp/nuget/AprilAsr.nuspec
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
- AprilAsr
- 0.0.1.6
- abb128
- GPL-3.0-only
- https://abb128.github.io/april-asr/
- April Speech Recognition
- Offline realtime speech recognition
-
-
-
-
-
-
-
-
diff --git a/bindings/csharp/nuget/build.bat b/bindings/csharp/nuget/build.bat
deleted file mode 100644
index 5428cfa..0000000
--- a/bindings/csharp/nuget/build.bat
+++ /dev/null
@@ -1,4 +0,0 @@
-cp ..\..\..\build\Release\libaprilasr.dll .\build\lib\win-x64\
-cp ..\..\..\lib\lib\onnxruntime.dll .\build\lib\win-x64\
-csc /t:library /out:lib/netstandard2.0/AprilAsr.dll src/*.cs
-nuget pack
diff --git a/bindings/csharp/nuget/build.sh b/bindings/csharp/nuget/build.sh
deleted file mode 100755
index 60af04f..0000000
--- a/bindings/csharp/nuget/build.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/bash
-set -e
-
-while getopts "s" opt; do
- case $opt in
- s)
- static=true
- ;;
- \?)
- echo "Invalid option: -$OPTARG" >&2
- exit 1
- ;;
- esac
-done
-
-
-rm ./build/lib/linux-x64/*.so
-if [ "$static" = true ]; then
- cp ../../../build/libaprilasr.so ./build/lib/linux-x64/
-else
- cp ../../../build/libaprilasr.so ./build/lib/linux-x64/
- cp ../../../lib/lib/*.so ./build/lib/linux-x64/
-fi
-mcs -out:lib/netstandard2.0/AprilAsr.dll -target:library src/*.cs
-nuget pack
\ No newline at end of file
diff --git a/bindings/csharp/nuget/build/AprilAsr.targets b/bindings/csharp/nuget/build/AprilAsr.targets
deleted file mode 100644
index 20644c3..0000000
--- a/bindings/csharp/nuget/build/AprilAsr.targets
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
- %(FileName)%(Extension)
- PreserveNewest
-
-
-
\ No newline at end of file
diff --git a/bindings/csharp/nuget/lib/netstandard2.0/.keep-me b/bindings/csharp/nuget/lib/netstandard2.0/.keep-me
deleted file mode 100644
index e69de29..0000000