Waveform Rendering to PNG with NAudio
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.
Comments
Hello Mark,
vishal agarwalI 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
there is nothing built-in to NAudio to do that I'm afraid
Mark Heathi 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 pattnaikHi 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