Spectrogram 1.6.1

.NET Standard 2.0
Install-Package Spectrogram -Version 1.6.1
dotnet add package Spectrogram --version 1.6.1
<PackageReference Include="Spectrogram" Version="1.6.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Spectrogram --version 1.6.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Spectrogram, 1.6.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Spectrogram as a Cake Addin
#addin nuget:?package=Spectrogram&version=1.6.1

// Install Spectrogram as a Cake Tool
#tool nuget:?package=Spectrogram&version=1.6.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Spectrogram is a .NET library for creating frequency spectrograms from pre-recorded signals, streaming data, or microphone audio from the sound card. Spectrogram uses FFT algorithms and window functions provided by the FftSharp project, and it targets .NET Standard so it can be used in .NET Framework and .NET Core projects.

Quickstart

(double[] audio, int sampleRate) = ReadWavMono("hal.wav");
var sg = new SpectrogramGenerator(sampleRate, fftSize: 4096, stepSize: 500, maxFreq: 3000);
sg.Add(audio);
sg.SaveImage("hal.png");

This example generates the image at the top of the page.

How to Read a WAV File

There are many excellent libraries that read audio files. Consult the documentation for those libraries to learn how to do this well. Here's an example method I use to read audio values from mono WAV files using the NAudio package:

(double[] audio, int sampleRate) ReadWavMono(string filePath, double multiplier = 16_000)
{
    using var afr = new NAudio.Wave.AudioFileReader(filePath);
    int sampleRate = afr.WaveFormat.SampleRate;
    int bytesPerSample = afr.WaveFormat.BitsPerSample / 8;
    int sampleCount = (int)(afr.Length / bytesPerSample);
    int channelCount = afr.WaveFormat.Channels;
    var audio = new List<double>(sampleCount);
    var buffer = new float[sampleRate * channelCount];
    int samplesRead = 0;
    while ((samplesRead = afr.Read(buffer, 0, buffer.Length)) > 0)
        audio.AddRange(buffer.Take(samplesRead).Select(x => x * multiplier));
    return (audio.ToArray(), sampleRate);
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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.6.1 112 7/10/2022
1.6.0 49 7/10/2022
1.5.0 134 6/16/2022
1.4.4 400 3/22/2022
1.4.3 493 10/27/2021
1.4.2 225 10/8/2021
1.4.1 240 9/5/2021
1.4.0 157 9/5/2021
1.3.0 685 1/4/2021
1.2.6 2,700 11/1/2020
1.2.5 470 8/6/2020
1.2.4 362 7/26/2020
1.2.3 614 7/4/2020
1.2.2 291 6/23/2020
1.2.1 288 6/18/2020
1.2.0 301 6/18/2020
1.0.1 725 8/26/2019
1.0.0 342 8/25/2019
0.0.1 320 8/16/2019