使用lamejs https://github.com/zhuker/lamejs,我想将webm blob转换为mp3 blob ...虽然它确实会产生mp3 blob,但声音只是短暂的静态声音。
如果lamejs在这种情况下不适用,谁能给我其他任何可行的工具吗?
var blob_data = get_audio_fn(); //get_audio_fn returns a webm or mp3 blob
if(blob_data == 'audio/webm'){
var fileReader = new FileReader();
var arrayBuffer;
fileReader.onloadend = () => {
arrayBuffer = fileReader.result;
var mp3Data = [];
var mp3encoder = new lamejs.Mp3Encoder(1, 44100, 128);
var samples = new Int16Array(arrayBuffer);
var mp3Tmp = mp3encoder.encodeBuffer(samples);
mp3Data.push(mp3Tmp);
mp3Tmp = mp3encoder.flush();
mp3Data.push(mp3Tmp);
var newblob = new Blob(mp3Data, {
type: 'audio/mp3',
name: '{{token_hash}}'+'.mp3',
}); //this newblob is just static
}
}
fileReader.readAsArrayBuffer(blob_data)