I get quite a lot of questions about how to render audio waveforms with NAudio and although there are a few examples of doing exactly this in the NAudio demo projects, I didn’t have a demo that takes an audio file and creates a PNG of the waveform. This can be especially useful if you are wanting to create server-side waveforms in a web application.
So I’ve decided to open source a little utility I created a while ago for doing just that. You give it the path of the file, and it uses NAudio’s
AudioFileReader class to read out the samples so it can support a wide range of input formats. Then there are lots of customization options for how the peaks are generated and what the waveform will look like.
Customization options include:
- Supports several peak calculation strategies (max, average, sampled, RMS, decibels)
- Supports different colours or gradients for the top and bottom half
- Supports different sizes for top and bottom half
- Overall image size and background can be customized
- Transparent backgrounds
- Support for SoundCloud style bars
- Several built-in rendering styles