Share on Facebook0Tweet about this on TwitterShare on Reddit0Share on Google+1Share on LinkedIn0Share on StumbleUpon0Buffer this pageEmail this to someonePrint this page

birdsong_spectrogram As part of Xeiam’s Datasets open source project, we’ve built a basic WAV audio file explorer which displays the spectrogram and waveform of ten second audio clips of birdsong from the HJA Birdsong machine learning dataset. Since this project is open source and licensed under the Apache 2.0 license anyone is free to use the code to build their own audio file explorer in Java. In fact, this project was built with components from the musicg project, also licenced under the Apache license. Spectrogram and waveform analysis can be used in machine learning as a preprocessing step in designing feature encoders for downstream neural networks.

How to read a WAV file in Java

According to this wave soundfile format description, a wav file is a binary file, where the first 44 bytes contain meta data and formatting type for the actual audio data. The audio data follows the meta data. In our Wave class, we pass an InputStream to the constructor and the header and data are parsed as follows.

The header meta data can be printed out by calling System.out.println(wave.toString());, and the result looks like this:

How to Create a Spectrogram in Java

For each input audio file, a Hamming window is first applied to each frame. A FFT is then applied using org.apache.commons.math3.transform.FastFourierTransformer with a window size of 512, transforming the signal into a time-frequency spectrogram. A filter is subsequently applied to the spectrogram, to normalize the levels of the signal. The resulting frequency range of the FFT analysis is from 0 to 8 kHz given the sampling frequency of 16 kHz of these particular audio files. The following code is an excerpt from the class Spectrogram.java and shows the steps for the spectrogram creation.

Exploring the HJA Birdsong Dataset

The HJA Birdsong dataset from Oregon State University contains 548 ten-second audio clips of birdsong from 13 different bird species. To create a classifier for this machine learning dataset, we first parsed the audio data and built a visual explorer for each WAV file using the above code in order to get a sense of what the data look like.

birdsong_explorer

Each birdsong recording clearly displays the bird songs and each species clearly has its own spectrogram “fingerprint”.

Closing Remarks

Feel free to use the HJA Birdsong spectrogram explorer yourself as a way to learn how to parse WAV files in Java and/or to create a spectrogram. You can also use our hja-birdsong module to jump start your own bird song classifer. All you need to do is donwload or build the jar your self and start playing around with the data. More information can be found in the module’s README file.

Share on Facebook0Tweet about this on TwitterShare on Reddit0Share on Google+1Share on LinkedIn0Share on StumbleUpon0Buffer this pageEmail this to someonePrint this page

Related Posts

Subscribe To Our Newsletter

Join our low volume mailing list to receive the latest news and updates from our team.

Leave a Comment

Newsletter

Subscribe to our low-volume mailing list to receive important updates and announcements directly in your inbox.