edimuj / cordova-plugin-audioinput

This iOS/Android Cordova/PhoneGap plugin enables audio capture from the device microphone, by in near real-time forwarding audio to the web layer of your application. A typical usage scenario for this plugin would be to use the captured audio as source for a web audio node chain, where it then can be analyzed, manipulated and/or played.

Home Page:https://github.com/edimuj/app-audioinput-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

audioinput.stop() - Not firing in iOS

nayaenndu opened this issue · comments

I have tried all the possible methods but failed. No way it is stopping the recording.
audioinput.start() is firing but it is not stopping. so the next task is not calling in iOS.
For android this working fine.
Starting recording
function startRecord(){

	console.log("Starting recording...");
	audioRecord = "temp.wav";
	
	 

	// Get access to the file system
	window.requestFileSystem(window.TEMPORARY, 5*1024*1024, function(fs) {
		console.log("Got file system: " + fs.name);
		fileSystem = fs;
		gotFS(fileSystem);
		// Now you can initialize audio, telling it about the file system you want to use.
		var captureCfg = {
			sampleRate: 16000,
			bufferSize: 8192,
			channels: 1,
			format: audioinput.FORMAT.PCM_16BIT,
			audioSourceType: audioinput.AUDIOSOURCE_TYPE.DEFAULT,
			fileUrl: cordova.file.cacheDirectory
		};
		
		// Initialize the audioinput plugin.
		window.audioinput.initialize(captureCfg, function() {	
			// Now check whether we already have permission to access the microphone.
			window.audioinput.checkMicrophonePermission(function(hasPermission) {
				if (hasPermission) {
					console.log("Already have permission to record.");
				} 
				else {	        
					// Ask the user for permission to access the microphone
					window.audioinput.getMicrophonePermission(function(hasPermission, message) {
						if (hasPermission) {
							console.log("User granted permission to record.");
						} else {
							console.warn("User denied permission to record.");
						}
					});
				}
			});
		});
	}, function (e) {
		console.log("Couldn't access file system: " + e.message)
	});

	// Later, when we want to record to a file...
	var captureCfg = {
		fileUrl : cordova.file.cacheDirectory + "temp.wav"
	}

//starting recording
	// Start the capture.
	audioinput.start(captureCfg);
	$('.rc1').hide();
	$('.rc2').show();
	var recTime = 0;
	var sec=0;
	var minute=0;
     recInterval = setInterval(function() {
		recTime = recTime + 1;
		if(recTime<60){
			sec=recTime;
		}else if(recTime==60){
			minute=1;
		}else if(recTime>60){
			sec = ( recTime - 60 );
		} //console.log("second length: "+sec.toString().length);
		if(sec.toString().length==1){
			var new_time_format = '0'+minute+':0'+sec;
		}else{
			var new_time_format = '0'+minute+':'+sec;
		}
		$('.rcTimr').text(new_time_format);
		//setAudioPosition(recTime);
        if (recTime >= 120) {
            clearInterval(recInterval);
			audioinput.stop(function(url) {
				console.log("File URL "+url);
				$('.loader1').show();
				uploadAudio();
			});
        }
	}, 1000);

}

function gotFS(fileSystem) {
fileSystem.root.getFile(audioRecord, {
create: true,
exclusive: false
}, gotFileEntry, function(){ console.log("failed");});
}

function gotFileEntry(fileEntry) {
    fileURL = fileEntry.toURL();
}

STOP Recording (Problem area)
stopQuestRecord:()=>{
clearInterval(recInterval);

            console.log("before stopping...");
            if(audioinput.isCapturing()){
                console.log("it is captureing"); 
                audioinput.disconnect();
                
                if(audioinput){
                audioinput.stop(function(url){
                    setTimeout(function(){
                        console.log("File URL "+url);
                        $('.loader1').show();
                        uploadAudio();
                    },3000);
                },function(er){
                    console.log("unable to stop "+er);
                }); 
            }else{
                console.log("No audio input");
            }
                   
                
            }else{
                console.log("Not capturing");
                //window.audioinput.stop();
            }

}

Any solution ? so far?

In my case the recording is stopping but the callback function is not triggered on ios.

Same problem here. The callback functions are not called at stop(). I am using iOS 13.3. The same code is working on Android.
This applies to version 1.0.2 and 1.0.1.

I'm experiencing the same problem in ios - are there any updates or workarounds for this?