Posts

  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
  • Magic Cauldron: Harry Potter Themed Gender Reveal Party - #Aurdino

    Earlier this year, we had a very fun filled Harry Potter themed gender reveal party. For the reveal, I built a Magic Cauldron which would reveal the gender. Check it out for yourself! For this I needed: A Cauldron. WS2812B LED array. Aurdino UNO. Bread board and jumper wires. Dry ice. Kasa Smart bulbs I will go over in the following sections The Mist.

  • Kakashi: The Copycat Robot - #Aurdino #image processing

    In this post, I want to share about "Kakashi: The Copycat Robot"—a fun side project I built a few years ago. The name is inspired by the famous character from Naruto, Kakashi Hatake, also known as the Copycat Ninja.The goal of this robot was to mimic Kakashi's ability to copy movements—though, of course, in a more limited way. Check it out for yourself!Here are the things I used to build this:

  • Neural network inference pipeline for videos in Tensorflow - #Deeplearning #Tensorflow

    Just as we saw a huge influx of images in the past decade or so, we are now seeing a lot of videos being produced on social media. The need to understand and moderate videos using machine learning has never been greater. In this post, I will show you how to build an efficient pipeline to processes videos in Tensorflow.  For simplicity, let us consider a Resnet50 model pre-trained on

  • Finding Where's Waldo using Mask R-CNN - #Deeplearning #ML

    When I was a kid, I really loved solving Where's Waldo. There were few books (it used to be called Where's Wally) in our school library on which I spent hours finding Waldo. For people who do not know what it is, basically Waldo - a unique character is hidden among hundreds of other characters and you have to find him in all the chaos in the image. Now that I am too old to be solving it and

  • Higher level ops for building neural network layers with deeplearn.js - #Deeplearning #javascript #ML

    I have been meddling with google's deeplearn.js lately for fun. It is surprisingly good given how new the project is and it seems to have a sold roadmap. However it still lacks something like tf.layers and tf.contrib.layers which have many higher level functions that has made using tensorflow so easy. It looks like they will be added to Graphlayers in future but their priorities as of now is to

Friday, 8 January 2016

Parsing wav file in node.js

I have worked with wav audio data in python before. Scipy provides a very nice way to do this using scipy.io.wavfile


I wanted to do exactly the same in node.js. There is a module called wav which sort of does it. However I faced several problems.

1. The Reader() method reads the file stream and converts into chunks of Buffer. This is very good while building web apps as you can send chunks of data separately and combine it later. However, I was just writing a script that'd run offline, So I had to put all the buffers to an array and then use the concat method of Buffer.


2. The wav module doesn't do much processing and just throws the raw binary information at us. So, we have to take care of

  • Combining hex data to get amplitudes - One frame can be represented using several blocks of 8-bit hex. The number of blocks per frame is got using blockAlign parameter in the format.
  • Endianness - Data may or may not be  in little endian format. So, while reading the blocks of hex data, we have to take care of this.
  • Handling negative amplitudes - Frames spanning several blocks when negative can be little challenging to handle as they are just stored as their two's complement.
  • Separating channels - The raw binary contains data of all the channels together. Fortunately, they are mentioned one after the other. Using channels parameter in the format, channels can be separated easily.
So, let's see how I handled all the above cases. First, we need to capture the "format" of the audio file that contains information about the file.


Then, on "end" event i.e after all the chunks have been combined, we will handle all the cases mentioned above as follows


Concluding, in this article I showed you how to handle and parse wav files in node.js by resolving several problems such as merging chunks of Buffer, combining hex data to get amplitudes, endianness, handling negative amplitudes and separating channels.