SilkCodec.NET
1.2.2
dotnet add package SilkCodec.NET --version 1.2.2
NuGet\Install-Package SilkCodec.NET -Version 1.2.2
<PackageReference Include="SilkCodec.NET" Version="1.2.2" />
<PackageVersion Include="SilkCodec.NET" Version="1.2.2" />
<PackageReference Include="SilkCodec.NET" />
paket add SilkCodec.NET --version 1.2.2
#r "nuget: SilkCodec.NET, 1.2.2"
#:package SilkCodec.NET@1.2.2
#addin nuget:?package=SilkCodec.NET&version=1.2.2
#tool nuget:?package=SilkCodec.NET&version=1.2.2
SilkCodec.NET
Pure C# legacy SILK v3 encoding for .NET 8 and .NET 10.
Usage
using SilkCodec.NET;
short[] monoPcm = GetMonoPcm16();
var encoder = new SilkEncoder(new SilkEncoderOptions
{
SampleRate = 24_000,
MaxInternalSampleRate = 24_000,
BitRate = 25_000,
PacketLengthMilliseconds = 20,
Complexity = 2,
Tencent = true
});
byte[] silk = encoder.Encode(monoPcm);
File.WriteAllBytes("voice.silk", silk);
or directly MP3 files:
var encoder = new SilkEncoder(new SilkEncoderOptions
{
SampleRate = 24_000,
MaxInternalSampleRate = 24_000,
BitRate = 100_000,
Complexity = 2,
Tencent = true
});
encoder.EncodeMp3("input.mp3", "output.silk", SilkMp3AudioProfile.Flat);
The MP3 API also accepts streams and leaves caller-owned streams open:
using var mp3 = File.OpenRead("input.mp3");
using var silk = File.Create("output.silk");
encoder.EncodeMp3(mp3, silk, SilkMp3AudioProfile.Music);
MP3 conversion requires SampleRate and MaxInternalSampleRate to both be 24 kHz. Caller-owned streams remain open. The stream-to-stream overload uses fixed-size decode, resampling, and PCM buffers independent of track duration. The byte-array overload additionally retains the encoded output. Music filter state and resampling phase are preserved across frames.
EncodePcm16LittleEndian accepts raw mono signed 16-bit little-endian PCM bytes. Incomplete final 20 ms frames are discarded, matching the reference silk-codec/test/Encoder.c behavior.
Standard output starts with #!SILK_V3, stores each packet as a little-endian signed 16-bit length followed by payload, and ends with -1. Tencent output adds a leading 0x02 and omits the terminator.
MP3 Conversion Demo
Run the console demo and enter an MP3 path when prompted:
dotnet run --project SilkCodec.NET.Demo
The demo decodes MP3 with the managed NLayer decoder, downmixes it to mono PCM16, and exports Tencent SILK v3 by default. Sources above 24 kHz are converted to 24 kHz with a managed band-limited resampler before encoding. The demo also prompts for the output path, bitrate, and container format so different quality settings can be compared. The default bitrate is 100 kbps for maximum quality; music should use at least 32 kbps to avoid the encoder switching from 24 kHz super-wideband mode to 16 kHz wideband mode.
It can also run non-interactively:
dotnet run --project SilkCodec.NET.Demo -- input.mp3 output.silk 100000 tencent flat
Use standard as the final argument for a standard #!SILK_V3 stream. Use tencent for the common WeChat/QQ-compatible stream with the leading 0x02 byte.
The optional fifth argument is flat or music. flat is the default and applies only mono downmixing, band-limited resampling, and PCM16 conversion. The optional music profile adds an 80 Hz high-pass filter, an approximately 11 kHz low-pass filter, gentle dynamic compression, and a -1 dBFS soft sample-peak limiter. The processing is implemented entirely in managed C# and does not require FFmpeg.
Legacy SILK is a mono speech codec with a maximum 24 kHz internal sample rate (approximately 12 kHz audio bandwidth). Even at high bitrates it cannot preserve stereo or CD-quality music bandwidth; use Opus/AAC when the playback system permits it.
Upstream Reference
The managed SILK codec implementation in this project is based on the SILK implementation from Jitsi/libjitsi, licensed under the Apache License 2.0. Warped noise shaping and related encoder behavior were adapted from the SILK SDK 1.0.9 reference implementation, licensed under the BSD 3-Clause Clear License. See THIRD-PARTY-NOTICES for details.
Mono PCM16 little-endian can also be encoded directly from a stream without loading the complete audio:
using var pcm = File.OpenRead("input.pcm");
using var silk = File.Create("output.silk");
encoder.EncodePcm16LittleEndian(pcm, silk, cancellationToken);
For cancellable MP3 conversion use EncodeMp3(mp3, silk, profile, cancellationToken). Incomplete final 20 ms frames are discarded, matching the span-based encoder. Caller-owned streams remain open; cancellation or I/O failure can leave partial output in a caller-owned output stream.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. 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 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. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.