<commit_before>
/**
 * 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 <code>miclevelchanged</code> on listeners registered to the MediaManager.
 *
 * In addition, if the mic-levels-audio plugin starts its own audio-stream, an <code>webaudioinputstarted</code>
 * event is trigger, when the plugin starts.
 *
 * @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){
 *
 * });
 *
 * @class
 * @public
 * @name  MicLevelsAnalysis
 * @memberOf mmir.env.media
 *
 * @see {@link mmir.env.media.WebspeechAudioInput} for an example on integrating the mic-levels-analysis plugin into an audio-input plugin
 *
 * @requires HTML5 AudioContext
 * @requires HTML5 getUserMedia (audio)
 */

newMediaPlugin = {
	/**  @memberOf MicLevelsAnalysis.module# */
	initialize: function(callBack, mediaManager){//, ctxId, moduleConfig){//DISABLED this argument is currently un-used -> disabled

		/**
		 * @type navigator
		 * @memberOf MicLevelsAnalysis#
		 */
		var html5Navigator = navigator;
		/**
		 * @type AudioContext
		 * @memberOf MicLevelsAnalysis#
		 */
		var _audioContext;
		/**  @memberOf MicLevelsAnalysis# */
		var createAudioContext = function(){

			if(typeof AudioContext !== 'undefined'){
				_audioContext = new AudioContext;
			}
			else {//if(typeof webkitAudioContext !== 'undefined'){
				_audioContext = new webkitAudioContext;
			}
		};
		var nonFunctional = false;

		try {
	        // unify the different kinds of HTML5 implementations
			//window.AudioContext = window.AudioContext || window.webkitAudioContext;
			/**  @memberOf MicLevelsAnalysis.navigator# */
			html5Navigator.__getUserMedia = html5Navigator.getUserMedia || html5Navigator.webkitGetUserMedia || html5Navigator.mozGetUserMedia;
			//window.URL = window.URL || window.webkitURL;
	//    	_audioContext = new webkitAudioContext;

			createAudioContext();
		}
		catch (e) {
			console.error('No web audio support in this browser! Error: '+(e.stack? e.stack : e));
			nonFunctional = true;
		}
<commit_msg>FIX avoid unnecessary creation of AudioContext on initialization which might trigger a warning from browsers due to missing user interaction<commit_after>
/**
 * 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 <code>miclevelchanged</code> on listeners registered to the MediaManager.
 *
 * In addition, if the mic-levels-audio plugin starts its own audio-stream, an <code>webaudioinputstarted</code>
 * event is trigger, when the plugin starts.
 *
 * @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){
 *
 * });
 *
 * @class
 * @public
 * @name  MicLevelsAnalysis
 * @memberOf mmir.env.media
 *
 * @see {@link mmir.env.media.WebspeechAudioInput} for an example on integrating the mic-levels-analysis plugin into an audio-input plugin
 *
 * @requires HTML5 AudioContext
 * @requires HTML5 getUserMedia (audio)
 */

newMediaPlugin = {
	/**  @memberOf MicLevelsAnalysis.module# */
	initialize: function(callBack, mediaManager){//, ctxId, moduleConfig){//DISABLED this argument is currently un-used -> disabled

		/**
		 * @type navigator
		 * @memberOf MicLevelsAnalysis#
		 */
		var html5Navigator = navigator;
		/**
		 * @type AudioContext
		 * @memberOf MicLevelsAnalysis#
		 */
		var _audioContext;
		/**  @memberOf MicLevelsAnalysis# */
		var createAudioContext = function(){

			if(typeof AudioContext !== 'undefined'){
				_audioContext = new AudioContext;
			}
			else {//if(typeof webkitAudioContext !== 'undefined'){
				_audioContext = new webkitAudioContext;
			}
		};
		var nonFunctional = false;

		try {
	        // unify the different kinds of HTML5 implementations
			//window.AudioContext = window.AudioContext || window.webkitAudioContext;
			/**  @memberOf MicLevelsAnalysis.navigator# */
			html5Navigator.__getUserMedia = html5Navigator.getUserMedia || html5Navigator.webkitGetUserMedia || html5Navigator.mozGetUserMedia;
			//window.URL = window.URL || window.webkitURL;
			// _audioContext = new webkitAudioContext;
			// createAudioContext();
		}
		catch (e) {
			console.error('No web audio support in this browser! Error: '+(e.stack? e.stack : e));
			nonFunctional = true;
		}

{'fraction_non_alphanumeric': 0.15471916618413434, 'fraction_numerical': 0.0018529241459177765, 'mean_word_length': 3.013011152416357, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1327612', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2527, 'n_words': 689}