Posted in:

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

Test Harness App

It comes with a built-in test harness app makes it easy to experiment with the various rendering options and save the results as a PNG. Test Harness UI

Example Waveforms

Basic solid colour waveform Basic solid color

Gradient vertical bars (old SoundCloud style) Gradient vertical bars

Blocks (SoundCloud style) Blocks

Orange Blocks

Transparent Backgrounds Transparent Background

Transparent Background

You can check out all the source code on GitHub

Want to get up to speed with the the fundamentals principles of digital audio and how to got about writing audio applications with NAudio? Be sure to check out my Pluralsight courses, Digital Audio Fundamentals, and Audio Programming with NAudio.

Comments

Comment by vishal agarwal

Hello Mark,
I wish to plot the words (utterances) alongwith the waveform. Would that be possible with NAudio?
If not, would you be able to point in the direction as to how can i do it?
Thanks,
Vishal

vishal agarwal
Comment by Mark Heath

there is nothing built-in to NAudio to do that I'm afraid

Mark Heath
Comment by prem pattnaik

i want to visualize the entire waveform for the audio file. It is about 20 minutes long audio in wav format. How can i visualize the waveform with timeline

prem pattnaik
Comment by Misha

Hi Mark. Is it possible to render an image of a subset of an audio file, in which one specifies the starting time and duration to plot? Please and thank you.

Misha