GithubHelp home page GithubHelp logo

audio-stream-meter's Introduction

audio-stream-meter

Simple meter for showing audio stream volume.

npm version License: MIT

Installation

$ npm install audio-stream-meter

Quick start

var AudioStreamMeter = require('audio-stream-meter');

navigator.mediaDevices.getUserMedia({audio:true})
.then(stream => {
    var audioContext = new AudioContext();
				
    var mediaStream = audioContext.createMediaStreamSource(stream);
    var volume = document.getElementById('volume');

    var meter = AudioStreamMeter.audioStreamProcessor(audioContext, function() {
        volume.style.width = meter.volume * 100 + '%';
    });
      
    mediaStream.connect(meter);
    stream.onended = meter.close.bind(meter);
});

<!-- html volume -->
<div style="width:300px;height:30px;background-color:#FF00FF">
	<div id="volume" style="height:30px;background-color:#00FFFF"></div>
</div>

Configuration

var config = {
	bufferSize: 1024, // default: 1024, interval: {0, 256, 512, 1024, 2048, 4096, 8192, 16384} 
	inputChannels: 1, // default: 1, interval: [1, 32]
	volumeFall: 0.95, // default: 0.95, interval: (0,1)
	throttle: 1, // default: 1, interval: [1, 10]
};

var meter = AudioStreamMeter.audioStreamProcessor(audioContext, callbackFn, config);
  • bufferSize - more value create higher latency of audio sample-frames
  • inputChannels - how many input channels should be handling, passing more channels then exists in stream will flatten volume
  • volumeFall - more means volume wave will be fall slower
  • throttle - sets step for which will be take samples for calculations, see percent of calculated samples by means of formula f(x) = 100 / x

Controls

  • callbackFn() - function is invoke after each processing audio samples and can use within data from 'Output data' paragraph. For example: callbackFn(){ console.log(meter.volume)}
  • meter.close() - close and disconnect audio processing

Output data

  • meter.volume - gives info about volume of the last package of samples - intervals [0, 1]

Licence

MIT

audio-stream-meter's People

Contributors

krzaku281 avatar

Stargazers

Kévin Painchaud avatar goodjun avatar Danilo Joksimovic avatar Ruben van der Leun avatar Craig Spaeth avatar Tomasz Rybicki avatar Horace avatar Jordan Baucke avatar  avatar

Watchers

 avatar

Forkers

tak0002

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.