mmig / libflac.js

FLAC encoder and decoder in JavaScript
Other
92 stars 22 forks source link

on iPad (v11.1.1) doesn't work #6

Closed Alexter-progs closed 6 years ago

Alexter-progs commented 6 years ago

Hi, i'm trying to use libflac and demo you provided to record audio from mic and send it to google speech api. Everything works on desktop, but on ipad with v11.1.1 it doesn't work. It works on iphone 5s and 6 with v11.3. Resulted buffer(blob) returns size of 86 always. I'm using code from demo to capture audio

getUserMedia -> createMediaSourceStream from mediaStream -> create scriptProcessor -> link audio node with script processor and listen for onaudioprocess -> then pass inputBuffer.getChannelData(0) to encoder from demo. Basically i use everything from demo to encode audio except i set encoding to flac only.

And i have no clue what can cause that

russaa commented 6 years ago

could it be, that the browser doesn't actually allow access to the microphone?

the file size looks suspiciously as if it only contains the FLAC header and no audio data at all ...

Alexter-progs commented 6 years ago

Kinda, i've read this thread https://github.com/ai/audio-recorder-polyfill/issues/4 this guy (alecglassford) says that ios suspends audio context if it's not being created inside handler that was fired by user click. And indeed, i was getting access to media stream, though there was no red mic icon blinking and all data i was getting is banch of 0. After creating context from handler of click event fired by user click audio context was no longer suspended and data would flow normally. Safari is so painful sometimes