Web Audio API - record to MP3?

前端 未结 6 1088
感情败类
感情败类 2021-02-01 06:06

I am asking because I couldn\'t find the answer anywhere. I have successfully implemented RecorderJS in order to record microphone input in JS. However, the recorded file is WAV

相关标签:
6条回答
  • 2021-02-01 06:32

    Encoding into smaller formats is currently only supported by Firefox:

    • http://w3c.github.io/mediacapture-record/MediaRecorder.html
    • https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder

    Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit) Not supported 25.0 (25.0) Not supported Not supported Not supported

    AFAIK only OGG is supported. But better OGG than WAV.

    0 讨论(0)
  • 2021-02-01 06:32

    To record mp3 using javascript without any other framework using a web worker, you can use this project: https://github.com/nusofthq/Recordmp3js which is also very well explained here:

    http://audior.ec/blog/recording-mp3-using-only-html5-and-javascript-recordmp3-js/

    With this, it's also possible to write to a .mp3 file and to make it downloadable.

    0 讨论(0)
  • 2021-02-01 06:34

    I have found a nice library with live demos: MediaStreamRecorder

    One of demos is here: Audio Recording

    RecordRTC is also can be useful but MSR it seems is easier to start with.

    0 讨论(0)
  • 2021-02-01 06:41

    I was frustrated with this problem, and existing solutions, so I came up with something simpler:

    https://github.com/sb2702/audioRecord.js

    Usage

    Create a recorder object (async because requires user permission)

        Recorder.new(function(recorder){ 
    
        }); 
    

    Start recording

             recorder.start();        
    

    Stops recording

             recorder.stop();    
    

    Export as mp3

             recorder.exportMP3(function(mp3Blob){ 
    
                console.log("Here is your blob: " + URL.createObjectURL(mp3Blob));
    
              });
    

    Mostly based on RecorderJS, but changed some things around to export to mp3 files, and to not have to muck around with AudioContext / navigator.getUs

    0 讨论(0)
  • 2021-02-01 06:43

    The only Javascript MP3 encoder I've seen is https://github.com/akrennmair/libmp3lame-js, which is a port using emscripten. It's supposed to be slow, and I've never used it.

    I don't know of any natively-written Javascript MP3 encoders, and encoding is not covered by the Web Audio API.

    0 讨论(0)
  • 2021-02-01 06:46

    There's a library written in pure javascript, called lamejs. To encode mp3s from raw audio. It is much faster than emscripten compile of libmp3lame. https://github.com/zhuker/lamejs

    Example usage:

    lib = new lamejs();
    mp3encoder = new lib.Mp3Encoder(1, 44100, 128); //mono 44.1khz encode to 128kbps
    samples = new Int16Array(44100); //one second of silence
    var mp3 = mp3encoder.encodeBuffer(samples); //encode mp3
    
    0 讨论(0)
提交回复
热议问题