Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get Web Audio API to work with iOS 11 Safari

So iOS 11 Safari was supposed to add support for the Web Audio API, but it still doesn't seem to work with this javascript code:

//called on page load
get_user_media = get_user_media || navigator.webkitGetUserMedia;  
get_user_media = get_user_media || navigator.mozGetUserMedia;
get_user_media.call(navigator, { "audio": true }, use_stream, function () { });
function use_stream(stream){
    var audio_context = new AudioContext();
    var microphone = audio_context.createMediaStreamSource(stream);
    window.source = microphone; // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=934512
    var script_processor = audio_context.createScriptProcessor(1024, 1, 1);
    script_processor.connect(audio_context.destination);
    microphone.connect(script_processor);
    //do more stuff which involves processing the data from user's microphone...
}

I copy pasted most of this code, so I only have a cursory understanding of it. I know that it's supposed to (and does, on other browsers) capture the user's microphone for further processing. I know that the code breaks on the var audio_context = new AudioContext(); line (as in, no code after that is run), but don't have any error messages cause I don't have a mac which is required to debug iOS Safari (apple die already >_<) Anyone know what's going on and/or how to fix it?

e: forgot to mention that I looked it up and apparently I need the keyword "webkit" before using Web Audio API in Safari, but making it var audio_context = new webkitAudioContext(); doesn't work either

like image 683
Artikash-Reinstate Monica Avatar asked Dec 18 '22 04:12

Artikash-Reinstate Monica


2 Answers

@TomW was on the right track - basically the webkitAudioContext is suspended unless it's created in direct response to the user's tap (before you get the stream).

See my answer at https://stackoverflow.com/a/46534088/933879 for more details and a working example.

like image 109
Nathan Friedly Avatar answered Dec 24 '22 01:12

Nathan Friedly


Nothing works on mobile save to home screen apps. I issued a bug report to Apple developer. Got a response that it was a duplicate ( which means they know..no clue if or when they will actually fix it).

like image 45
Kerry Davis Avatar answered Dec 24 '22 00:12

Kerry Davis