Monthly Archives: February 2013

TypeScript declarations for the Web Audio API

After having done some work on porting Patchwork to Javascript last year using the Web Audio API, a project I departed because of some unsolvable problems (mainly, but not limited to, the custom AudioNodes adding a delay in the audio chain), I recently picked up a small experiment again using said API. Working with TypeScript this time, a declarations file for the Web Audio API was needed and after some searching without any result, I decided to make one myself.

There are some minor issues with it, although they don’t prevent regular use afaik:

  • I coulnd’t get readonly attributes in there using getters without Visual Studio complaining about my syntax. For now, I’ve just made them into regular properties and marked them with a comment so I (or someone else) can change them later on. (Using them as setters will be allowed by Visual Studio, but will logically give an error during runtime).
  • I don’t know how to implement constants (there are two sets of uppercase consts in there), so I also made them into regular attributes.
  • The MediaStreamAudioDestinationNode has an attribute of type MediaStream, which isn’t a part of the Web Audio API (it appears to be defined here). It doesn’t really belong in this file, but since I am not planning on using it, I just added an empty interface to prevent any errors. You should remove it if you have a declaration for the MediaStream API.

Apart from that, it works fine so if you want to do some Web Audio API programming using TypeScript yourself, you may find it useful and you can download the declarations file here.