ai / audio-recorder-polyfill

MediaRecorder polyfill to record audio in Edge and Safari

Home Page:https://ai.github.io/audio-recorder-polyfill/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught SyntaxError: Unexpected end of input

ammoradi opened this issue · comments

I'm using this library with create-react-app's latest version and I'm using this lib for audio recording on iOS safari devices.
I created src/polyfills.js and imported this into my src/index.js

the content of src/polyfills.js:

import AudioRecorder from 'audio-recorder-polyfill'
window.MediaRecorder = AudioRecorder

my src/index.js:

...
import './polyfills'
...

my recorder is same as your example:

navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
  recorder = new MediaRecorder(stream)
  recorder.addEventListener('dataavailable', e => {
    audio.src = URL.createObjectURL(e.data)
  })
  recorder.start()
})

but it gives me the error:
Uncaught SyntaxError: Unexpected end of input at line 74 (EOF).

I also get this error after transpiling with webpack 4.

There's a blob request and there's syntax error in it. I look through the file and it's missing a } at the end.

content of blob:null/2996b54f-d87f-4a01-8c54-4147e2efa710

()=>{let e=[];onmessage=t=>{"encode"===t.data[0]?function(t){let n=t.length,r=new Uint8Array(2*n);for(let e=0;e<n;e++){let n=2*e,i=t[e];i>1?i=1:i<-1&&(i=-1),i*=32768,r[n]=i,r[n+1]=i>>8}e.push(r)}(t.data[1]):function(t){let n=e.length?e[0].length:0,r=e.length*n,i=new Uint8Array(44+r),s=new DataView(i.buffer);s.setUint32(0,1380533830,!1),s.setUint32(4,36+r,!0),s.setUint32(8,1463899717,!1),s.setUint32(12,1718449184,!1),s.setUint32(16,16,!0),s.setUint16(20,1,!0),s.setUint16(22,1,!0),s.setUint32(24,t,!0),s.setUint32(28,2*t,!0),s.setUint16(32,2,!0),s.setUint16(34,16,!0),s.setUint32(36,1684108385,!1),s.setUint32(40,r,!0);for(let t=0;t<e.length;t++)i.set(e[t],t*n+44);e=[],postMessage(i.buffer,[i.buffer])}(t.data[1])}

I recently fixed similar issue a906e7d

Can you check that you are using 0.3.3 with that fix?

This is part of my package-lock.json.

"audio-recorder-polyfill": {
      "version": "0.3.3",
      "resolved": "https://registry.npmjs.org/audio-recorder-polyfill/-/audio-recorder-polyfill-0.3.3.tgz",
      "integrity": "sha512-3ccwoYhAQtbkyaURMUXFj9wlEwVwU61zotYShR+474lXad42h0/jGFp/XGVfR/E+7ZhlfoQihw9NOIzH6Rg/8Q=="
    },

Yet still has blob issue.

The fix should be related with this code

https://github.com/ai/audio-recorder-polyfill/blob/master/index.js#L6-L9
https://github.com/ai/audio-recorder-polyfill/blob/master/index.js#L277

Can I ask you to help me and send PR? These few days I will work on another open-source project.

#51

I've send PR just now. It works on my local machine after making changes in node_modules/audio-recorder-polyfill/index.js.

Thanks to @jiyonghong. The fix was released at 0.3.4.