Class: MicLevelsAnalysis

MicLevelsAnalysis

new mmir.env.media.MicLevelsAnalysis()

MicLevelsAnalysis is a plugin/module for generating "microphone input levels changed events" for ASR (speech recognition) modules based on Web Audio Input (i.e. analyze audio from getUserMedia) The plugin triggers events miclevelchanged on listeners registered to the MediaManager. In addition, if the mic-levels-audio plugin starts its own audio-stream, an webaudioinputstarted event is trigger, when the plugin starts.
See:
  • mmir.env.media.WebspeechAudioInput for an example on integrating the mic-levels-analysis plugin into an audio-input plugin
Example
////////////////////////////////  within media plugin: load analyzer //////////////////////////////////
//within audio-input plugin that uses Web Audio: load mic-levels-analyzer plugin

//first: check, if the analyzer plugin is already loaded (should be loaded only once)
if(!mediaManager.micLevelsAnalysis){
	
	//set marker so that other plugins may know that the analyzer will be loaded:
	mediaManager.micLevelsAnalysis = true;
	
	//load the analyzer
	mediaManager.loadFile(micLevelsImplFile, function success(){

		//... finish the audio-plugin initialization, e.g. invoke initializer-callback

	}, function error(err){

	  	// ... in case the analyzer could not be loaded:
		// do some error handling ...
	  	
		//... and supply a stub-implementation for the analyzer module:
	  	mediaManager.micLevelsAnalysis = {
	  		_active: false,
	  		start: function(){
	  			console.info('STUB::micLevelsAnalysis.start()');
	  		},
	  		stop: function(){
	  			console.info('STUB::micLevelsAnalysis.stop()');
	  		},
	  		enable: function(enable){
	  			console.info('STUB::micLevelsAnalysis.enable('+(typeof enable === 'undefined'? '': enable)+') -> false');
	  			return false;//<- the stub can never be enabled
	  		},
	  		active: function(active){
	  			this._active = typeof active === 'undefined'? this._active: active;
	  			console.info('STUB::micLevelsAnalysis.active('+(typeof active === 'undefined'? '': active)+') -> ' + this._active);
	  			return active;//<- must always return the input-argument's value
	  		}
	  	};
	  	
	  	//... finish the audio-plugin initialization without the mic-levels-analyzer, e.g. invoke initializer-callback
	  	
	  });
} else {
	
	//if analyzer is already loaded/loading: just finish the audio-plugin initialization,
	//										 e.g. invoke initializer-callback

}


////////////////////////////////  use of mic-levels-analysis events //////////////////////////////////
//in application code: listen for mic-level-changes

mmir.MediaManager.on('miclevelchange', function(micValue){

});

Requires

  • module:HTML5
  • module:HTML5