Alternative AudioContext.createMediaStreamSource for iOS?

I developed an application using Cordova and a web audio API that allows the user to plug in headphones, press the phone on their heart and hear their own heartbeat.

He does this using audio filter nodes.

//Setup userMedia context = new (window.AudioContext||window.webkitAudioContext); navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia); navigator.getUserMedia( {audio:true}, userMediaSuccess, function(e) { alert("error2 " + e.message); }); function userMediaSuccess(stream) { //set microphone as input input = context.createMediaStreamSource(stream); //amplify the incoming sounds volume = context.createGain(); volume.gain.value = 10; //filter out sounds below 25Hz lowPass = context.createBiquadFilter(); lowPass.type = 'lowpass'; lowPass.frequency.value = 25; //filter out sounds above 425Hz highPass = context.createBiquadFilter(); highPass.type = 'highpass'; highPass.frequency.value = 425; //apply the filters and amplification to microphone input input.connect(lowPass); input.connect(highPass); input.connect(volume); //send the result of these filters to the phones speakers highPass.connect(context.destination); lowPass.connect(context.destination); volume.connect(context.destination); } 

It works great when deployed to Android, but it seems most of these features are not available in iOS mobile browsers.

I managed to create the getUserMedia function using the iosRTC plugin , but createMediaStreamSource is still โ€œnot a functionโ€.

So, I'm looking for an alternative to the web audio API that can filter out frequencies, or if there are plugins that I could use, that would be great.

+5
source share
3 answers

There is no way to do this on ios web. You will need a native application, since Apple does not support audio input in safari.

+1
source

You tried to use

 document.addEventListener('deviceready', function () { // Just for iOS devices. if (window.device.platform === 'iOS') { cordova.plugins.iosrtc.registerGlobals(); } }); 
0
source

You asked this question recently, but unfortunately createMediaStreamSource is still not supported on Safari Mobile (will it ever be?).

As mentioned earlier, a plugin is the only way to achieve this, and in fact there is a Cordova / Phonegap plugin that does just that. cordova-plugin-audioinput gives you access to sound from a microphone using either the web audio API or callbacks that delivers raw audio data fragments, and this supports iOS as well as Android.

Since I don't want to post the same answer twice, I will instead point you to the following answer here on stackoverflow, where you will also find sample code: fooobar.com/questions/1235536 / ...

I am the creator of the plugin and any feedback is appreciated.

0
source

Source: https://habr.com/ru/post/1235534/


All Articles