Giter Site home page Giter Site logo

Comments (6)

pradu14 avatar pradu14 commented on August 20, 2024

I suspect is has something to do with the way libmp3lame.js encodes the WAV files and somehow along the way the buffer gets doubled, but I havenโ€™t found any solution for this as of now.

from recordmp3js.

adamthehutt avatar adamthehutt commented on August 20, 2024

I'm experiencing this issue as well. Anyone have ideas?

from recordmp3js.

hussion avatar hussion commented on August 20, 2024

I'm also experiencing this issue as well. i hope it will be solved

from recordmp3js.

roparz avatar roparz commented on August 20, 2024

My solution:

First, in the file recordmp3.js, function encode64, divide len by 2.

function encode64(buffer) {
    var binary = '',
        bytes = new Uint8Array( buffer ),
        len = bytes.byteLength / 2;     // <======= here
    for (var i = 0; i < len; i++) {
        binary += String.fromCharCode( bytes[ i ] );
    }
    return window.btoa( binary );
}

With that code, the MP3 preview is fixed.

Second, add the following function in recordmp3.js

// inspired from the interleave function in recorderWorker.js
function getHalfBuffer(buffer) {
    var length = buffer.length / 2,
        result = new Float32Array(length),
        index = 0,
        bufIndex = 0,
    while (index < length) {
        result[index++] = buffer[bufIndex];
        bufIndex++;
    }
    return result;
}

And use it line 107:

var mp3Blob = new Blob([new Uint8Array(getHalfBuffer(e.data.buf))], {type: 'audio/mp3'});

With that code, the MP3 upload is fixed.

from recordmp3js.

espiritudelvino avatar espiritudelvino commented on August 20, 2024

This solution worked for me, thank you!

Only needed a minor change: missing semicolon, no big deal

function getHalfBuffer(buffer) {
    var length = buffer.length / 2,
        result = new Float32Array(length),
        index = 0,
        bufIndex = 0;
    while (index < length) {
        result[index++] = buffer[bufIndex];
        bufIndex++;
    }
    return result;
}

from recordmp3js.

roparz avatar roparz commented on August 20, 2024

Hi everyone,

I made a fork here: https://github.com/roparz/Recordmp3js

I made some changes in the code:

  • the old version was creating the mp3 file in three steps: capturing audio input, encoding input to wav and then transform the wav file to mp3. This new version bypass the wav encoding and transform directly the audio input to mp3. I didn't make performance tests but I can guess that the encoding is a little bit faster now.
  • I also fixed the problem with the audio capture, the microphone input is not anymore sent to the speakers.

Hope this will help some of you.

from recordmp3js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.