KPB.VoskWrapper 1.1.0

dotnet add package KPB.VoskWrapper --version 1.1.0                
NuGet\Install-Package KPB.VoskWrapper -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KPB.VoskWrapper" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KPB.VoskWrapper --version 1.1.0                
#r "nuget: KPB.VoskWrapper, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install KPB.VoskWrapper as a Cake Addin
#addin nuget:?package=KPB.VoskWrapper&version=1.1.0

// Install KPB.VoskWrapper as a Cake Tool
#tool nuget:?package=KPB.VoskWrapper&version=1.1.0                

VoskWrapper

License NuGet version (KPB.VoskWrapper)

This library is intended for people that want to quickly get startet with the Vosk speech recognition toolkit in a .NET environment and find the official examples insufficient or too complicated for live processing workloads. It should be thread safe, but I don't want to advertise it as such since I am not completely certain that deadlocks and race conditions are impossible.

For live speech to text processing, NAudio is used. This means that although this is a .NET Standard 2.0 library, it depends on Windows specific features for this functionality.

I hope that the code itself and the documentation comments prove to be helpful in understanding and working with the Vosk library, since I find some behavior of it very unintuitive or badly documented and I have either addressed or explained these things in this library.

Changelog

Usage

Enumerate available input devices

using KPB.VoskWrapper;

foreach (var device in VoskWrapper.InputDevices)
{
    Console.WriteLine(device);
}

(0, Mikrofon (Realtek High Definiti, 2, 00000000-0000-0000-0000-000000000000, e36dc311-6d9a-11d1-a21a-00a0c9223196, d5a47fa8-6d98-11d1-a21a-00a0c9223196)

Start live speech to text processing

using var model = await VoskModel.CreateAsync(@"models\vosk-model-en-us-0.22-lgraph");
using var vw = await VoskWrapper.CreateAsync(model, sampleRate: 8000, maxAlternatives: 0, returnWords: false, grammar: new[] { "toast", "test", "[unk]" });

vw.ResultAvailable += res =>
{
    foreach (var result in res)
    {
        Console.WriteLine(result.Text);
    }
};

Console.WriteLine(vw.IsProcessing);
vw.StartLiveProcessing(inputDevice: 0);
Console.WriteLine(vw.IsProcessing);

False

True

[unk] toast test [unk] [unk]

Process a WAV file (output assuming no grammar has been specified)

var res = await vw.ProcessFileAsync(@"samples\male_8khz.wav");

Console.WriteLine(res[0].Text);

but what if somebody decides to break it be careful that you keep adequate coverage but look for places to save money ...

Support & Contributing

If you have any issues with this library or want to make a suggestion for an improvement, feel free to create an issue. If you want to take things into your own hands, feel free to create a merge request. Just try to keep the code style similar to mine.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 342 9/30/2023
1.0.1 133 9/30/2023
1.0.0 387 8/5/2022

1.1.0 (2023-09-30)

Added
- Runtime checks for Windows specific methods

Changed
- IsProcessing now throws an ObjectDisposedException instead of returning false after disposal
- Sealed VoskResult, VoskWordResult and VoskAlternatives
- Improved efficiency of invalid result removal

1.0.1 (2023-09-30)

Fixed
- Vosk logs being displayed if VoskModel was used before VoskWrapper

1.0.0 (2022-08-05)

- Initial release