Coder Social home page Coder Social logo

microphone's Introduction

microphone

Tiny coffeescript/javascript library to process live audio input in the browser. Right now, this only works in Chrome.

I created this to make it easy to perform arbitrary computations using raw, streaming audio data.

A Microphone object takes two parameters- settings and a callback.

  • settings:
    • unit: the length (in seconds) of audio to return in each callback (default: 1)
    • overlap: the amount of overlap in the audio data between successive callbacks (For example, overlap of .25 means the last 25% of the audio data from one callback will be the first 25% of the data in the next callback). (default: 0. Must be between 0 and 1, inclusive)
    • channels: 1 (mono) or 2 (stereo) (default: 1)
  • callback: A function that takes an array with dimensions 2x(unit * recording sample rate) if stereo, and just (unit * recording sample rate) if mono. The callback will be called every (unit * (1 - overlap)) seconds.

Usage

Example: compute the RMS energy every half second with 50% overlap

Coffeescript:

mic = new Microphone unit: .5, overlap: .5, (data) ->
    v = (d * d for d in data).reduce (t, s) -> t + s
    v = Math.sqrt(v / data.length)
    console.log v

Javascript:

mic = new Microphone({
    unit: .5,
    overlap: .5
}, function (data) {
    v = data.map(function (d) { return d * d; });
    v = v.reduce(function (t, s) { return t + s; });
    v = Math.sqrt(v / data.length);
    console.log(v);
})

microphone's People

Contributors

srubin avatar ddcast avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.