Supertoys.PocketSphinx
1.2.2
dotnet add package Supertoys.PocketSphinx --version 1.2.2
NuGet\Install-Package Supertoys.PocketSphinx -Version 1.2.2
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="Supertoys.PocketSphinx" Version="1.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Supertoys.PocketSphinx" Version="1.2.2" />
<PackageReference Include="Supertoys.PocketSphinx" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Supertoys.PocketSphinx --version 1.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Supertoys.PocketSphinx, 1.2.2"
#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.
#:package Supertoys.PocketSphinx@1.2.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Supertoys.PocketSphinx&version=1.2.2
#tool nuget:?package=Supertoys.PocketSphinx&version=1.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Supertoys.PocketSphinx
PocketSphinx 5 integration package for .NET:
- Parses PocketSphinx output lines (
PocketSphinxOutputParser) - Locates bundled runtime/model assets (
PocketSphinxRuntimePaths) - Runs PocketSphinx end-to-end (
PocketSphinxRunner)
What Is Bundled
- Runtime targets shipped now:
linux-arm64,linux-x64 - Bundled executables:
runtimes/linux-arm64/native/pocketsphinxruntimes/linux-arm64/native/pocketsphinx_batchruntimes/linux-x64/native/pocketsphinxruntimes/linux-x64/native/pocketsphinx_batch- Bundled English model set:
models/en-us/en-us(acoustic model directory)models/en-us/cmudict-en-us.dictmodels/en-us/en-us.lm.bin
Requirements
- .NET 9 (
TargetFramework: net9.0) - For end-to-end recognition, run on a supported RID that has bundled runtime assets (
linux-arm64orlinux-x64)
Install
dotnet add package Supertoys.PocketSphinx
Quickstart (End-to-End)
using Supertoys.PocketSphinx;
var result = await PocketSphinxRunner.RecognizeFileAsync(new PocketSphinxRunnerOptions
{
InputPath = "/absolute/path/to/audio.raw", // or .wav supported by PocketSphinx CLI
RuntimeIdentifier = "linux-x64"
});
Console.WriteLine(result.Hypothesis);
Console.WriteLine(result.Confidence);
Default runner model paths:
models/en-us/en-usfor-hmmmodels/en-us/cmudict-en-us.dictfor-dictmodels/en-us/en-us.lm.binfor-lm
Minimal Parser-Only Usage
using Supertoys.PocketSphinx;
var line = "{\"t\":\"hello henry\",\"p\":0.83}";
var text = PocketSphinxOutputParser.ExtractHypothesis(line);
var confidence = PocketSphinxOutputParser.ExtractConfidence(line);
API Reference
string PocketSphinxOutputParser.ExtractHypothesis(string line)double PocketSphinxOutputParser.ExtractConfidence(string line)string PocketSphinxRuntimePaths.GetModelsDirectory()string PocketSphinxRuntimePaths.GetNativeRuntimeDirectory()string PocketSphinxRuntimePaths.GetPocketsphinxExecutablePath()string PocketSphinxRuntimePaths.GetDefaultRuntimeIdentifier()Task<PocketSphinxRunnerResult> PocketSphinxRunner.RecognizeFileAsync(PocketSphinxRunnerOptions options, CancellationToken cancellationToken = default)
Runner option highlights:
InputPathrequiredRuntimeIdentifieroptional but recommended for deterministic behaviorExecutablePath,AcousticModelPath,DictionaryPath,LanguageModelPathoptional overridesModedefaults tosingleAdditionalArgumentsappends raw PocketSphinx CLI args
Build/Copy Behavior In Consumer Projects
The package includes buildTransitive/Supertoys.PocketSphinx.targets, which:
- Copies bundled runtime files into consuming app output under
runtimes/<rid>/native - Copies bundled models into consuming app output under
models/ - Applies
chmod +xon Unix for bundled PocketSphinx executables
Implementation Checklist (Human Or Agent)
- Add the package to your app.
- Build with
-r linux-x64or-r linux-arm64(matching your deployment target). - Call
PocketSphinxRunner.RecognizeFileAsync(...)with an input audio path. - Read
result.Hypothesisandresult.Confidence. - If needed, pass custom model/runtime paths in options.
Troubleshooting
PocketSphinx executable not found:- Ensure app was built/published with
RuntimeIdentifier=linux-x64orRuntimeIdentifier=linux-arm64. - Ensure output contains
runtimes/<rid>/native/pocketsphinx. Dictionary file not foundorLanguage model file not found:- Ensure output contains
models/en-us/.... - Recognition returns empty text:
- Check
result.StandardErrorandresult.StandardOutputfor CLI diagnostics.
Publishing
This repo is configured for NuGet Trusted Publishing via GitHub Actions OIDC in .github/workflows/publish.yml.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.