Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working With MediaRecorder API #68

Open
Deveosys opened this issue Nov 6, 2019 · 1 comment
Open

Working With MediaRecorder API #68

Deveosys opened this issue Nov 6, 2019 · 1 comment

Comments

@Deveosys
Copy link

Deveosys commented Nov 6, 2019

Hi,

I'm trying to encode the webm audio result from MediaRecorder API in Chrome into mp3.
But all I got is a short noisy audio.

Without encoding, the given webm audio is good. I can write it to file or play in a audio element.

this.mediaRecorder.ondataavailable = e => {
    this.chunks.push(e.data);
};
let fileReader = new FileReader();
fileReader.onload = () => {
    let mp3Data = [];
    let samples = new Int16Array(fileReader.result as ArrayBuffer);
    let mp3encoder = new lamejs.Mp3Encoder(1, 48000, 128);
    let mp3Buffer = mp3encoder.encodeBuffer(samples);
    if (mp3Buffer.length > 0) mp3Data.push(mp3Buffer);
    mp3Buffer = mp3encoder.flush();
    if (mp3Buffer.length > 0) mp3Data.push(mp3Buffer);
    // mp3Data should be ready here ? 
};
fileReader.readAsArrayBuffer(new Blob(this.chunks, { type: "audio/webm" }));

Could you help me figuring out where I am wrong ?
Thanks !

@geeee
Copy link
Collaborator

geeee commented Nov 6, 2019

Encoder accepts PCM audio only. You need to decode webm first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants