The goal

The goal is simple: Get live audio input from the user via the webkitGetUserMedia command and analyze its volume. This could be used as a nice input method – for example to control (parts of) a game.

The problem

On my Windows 8 machine none of the demos out there worked at all. I updated Chrome to the latest version but still no luck. Finally I thought the Media Capture API must have changed recently.

The analyser node connects just fine to the input stream and receives values. But the whole buffer defaults to -100 values without ever changing. Strangely, changing the live input with some loaded mp3 makes the analyser node work again as expected.

A simple (should be) working example can be found at github.

The solution

There seems to be an issue with the Media Capture API and my Windows system. If the input device (microphone) and output devices (speakers) use different sample rates the API does not work as expected without throwing any error message at all.

So to make most of the demos and examples out there work make sure your system is using the same sample rate for microphones and speakers. After that you need to restart your Browser and should be able to use audioContext.createAnalyser() to analyze the live audio data.

I will look into this issue and see if it’s possible to at least detect this error.

 

Update 1

This behavior seems to be a known bug as you can see at the chromium bug tracker (scroll down to read about the sample rate problems). The devs there are already working on this issue.