tryAGI.OpusSharp
1.0.2
Prefix Reserved
See the version list below for details.
dotnet add package tryAGI.OpusSharp --version 1.0.2
NuGet\Install-Package tryAGI.OpusSharp -Version 1.0.2
<PackageReference Include="tryAGI.OpusSharp" Version="1.0.2" />
<PackageVersion Include="tryAGI.OpusSharp" Version="1.0.2" />
<PackageReference Include="tryAGI.OpusSharp" />
paket add tryAGI.OpusSharp --version 1.0.2
#r "nuget: tryAGI.OpusSharp, 1.0.2"
#:package tryAGI.OpusSharp@1.0.2
#addin nuget:?package=tryAGI.OpusSharp&version=1.0.2
#tool nuget:?package=tryAGI.OpusSharp&version=1.0.2
OpusSharp
High-performance C# bindings for the Opus audio codec with bundled native runtime libraries.
The NuGet package id is tryAGI.OpusSharp. The public namespace remains OpusSharp.
Features
- Complete encoder and decoder API over libopus.
- PCM16 encode/decode with configurable sample rate, channel count, frame duration, application mode, bitrate, VBR, FEC, DTX, bandwidth, and complexity.
- Packet loss concealment, forward error correction, packet inspection, and repacketization helpers.
- Bundled native binaries for Windows x64, macOS universal x64/arm64, Linux x64, and Linux arm64.
- A small
opus_sharpnative shim for non-variadic encoder/decoder CTL calls. net10.0target with nullable reference types enabled.
Installation
dotnet add package tryAGI.OpusSharp
Basic Encoding
using OpusSharp;
var config = OpusConfig.VoiceMediumQualityMono(SampleRate.Hz16k);
using var encoder = new OpusEncoder(config);
var sampleRate = 16000;
var frameSize = config.SampleRate.FrameSize(config.FrameDuration);
var pcm = new short[frameSize];
for (var i = 0; i < frameSize; i++)
{
var t = (float)i / sampleRate;
pcm[i] = (short)(Math.Sin(2 * Math.PI * 440 * t) * short.MaxValue * 0.5f);
}
var encodedData = encoder.Encode(pcm, frameSize);
Console.WriteLine($"Encoded {frameSize} samples to {encodedData.Length} bytes");
Basic Decoding
using OpusSharp;
var config = OpusConfig.VoiceMediumQualityMono(SampleRate.Hz16k);
using var decoder = new OpusDecoder(config);
var decodedPcm = decoder.Decode(encodedData, config.FrameDuration);
Console.WriteLine($"Decoded {encodedData.Length} bytes to {decodedPcm.Length} samples");
Custom Configuration
var config = new OpusConfig
{
SampleRate = SampleRate.Hz48k,
Channels = Channels.Stereo,
FrameDuration = FrameDuration.Ms10,
Application = Application.Audio,
Complexity = 8,
Bitrate = 128000,
Fec = true,
};
using var encoder = new OpusEncoder(config);
using var decoder = new OpusDecoder(config);
Encoder Presets
using var voiceEncoder = new OpusEncoder(OpusConfig.VoiceMediumQualityMono(SampleRate.Hz16k));
using var musicEncoder = new OpusEncoder(OpusConfig.MusicStereo(SampleRate.Hz48k));
using var lowBandwidthEncoder = new OpusEncoder(OpusConfig.VoiceLowQualityMono(SampleRate.Hz16k));
Advanced Features
Forward Error Correction
var config = OpusConfig.VoiceMediumQualityMono(SampleRate.Hz48k);
config.Fec = true;
using var encoder = new OpusEncoder(config);
using var decoder = new OpusDecoder(config);
var decodedWithFEC = decoder.DecodeWithFEC(currentPacket, useFEC: true, config.FrameDuration);
Packet Loss Concealment
var concealedAudio = decoder.GeneratePLC(FrameDuration.Ms20);
Runtime Encoder Controls
using var encoder = new OpusEncoder(OpusConfig.VoiceMediumQualityMono(SampleRate.Hz48k));
encoder.SetBitrate(24000);
encoder.SetComplexity(8);
encoder.SetVbr(enabled: true, constrained: false);
encoder.SetFec(enabled: true);
Native Libraries
The package contains native runtime assets under NuGet runtimes/<rid>/native/:
runtimes/win-x64/native/opus.dllruntimes/win-x64/native/libopus-0.dllruntimes/win-x64/native/opus_sharp.dllruntimes/osx-x64/native/libopus.dylibruntimes/osx-x64/native/libopus_sharp.dylibruntimes/osx-arm64/native/libopus.dylibruntimes/osx-arm64/native/libopus_sharp.dylibruntimes/linux-x64/native/libopus.soruntimes/linux-x64/native/libopus.so.0runtimes/linux-x64/native/libopus_sharp.soruntimes/linux-arm64/native/libopus.soruntimes/linux-arm64/native/libopus.so.0runtimes/linux-arm64/native/libopus_sharp.so
The native binaries are committed in natives/ so consumers do not need a system libopus installation.
Rebuilding Native Binaries
Vendored Opus 1.5.2 source lives in third_party/opus/opus-1.5.2/, with the .NET CTL shim in third_party/opus/shim/opus_shim.c.
Run the rebuild script from the repository root:
third_party/opus/build-opussharp.sh
The script writes refreshed binaries into natives/. macOS builds require Xcode command line tools. Linux builds use Docker. Windows x64 builds require x86_64-w64-mingw32-gcc.
Build And Test
dotnet build OpusSharp.slnx
dotnet test src/tests/OpusSharp.Tests/OpusSharp.Tests.csproj
dotnet pack src/libs/OpusSharp/OpusSharp.csproj -c Release
License
OpusSharp is licensed under MIT. Vendored Opus source and derived native binaries retain the Opus license; see THIRD-PARTY-NOTICES.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.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.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.3-dev.7 | 23 | 9/25/2026 |
| 1.0.3-dev.6 | 37 | 9/25/2026 |
| 1.0.3-dev.5 | 59 | 9/17/2026 |
| 1.0.3-dev.4 | 53 | 9/11/2026 |
| 1.0.3-dev.3 | 65 | 9/11/2026 |
| 1.0.3-dev.2 | 65 | 8/30/2026 |
| 1.0.3-dev.1 | 61 | 8/30/2026 |
| 1.0.2 | 986 | 6/26/2026 |
| 1.0.2-dev.1 | 79 | 6/26/2026 |
| 1.0.1 | 124 | 6/26/2026 |
| 1.0.1-dev.1 | 74 | 6/26/2026 |
| 1.0.0 | 134 | 6/25/2026 |