javascript - Web Audio Api - Download edited MP3 -
i'm editing mp3 file multiple effects so
var mainverse = document.getelementbyid('audio1'); var s = source; source.disconnect(audioctx.destination); (var in filters1) { s.connect(filters1[i]); s = filters1[i]; } s.connect(audioctx.destination);
the mp3 plays accordingly on web filters on it. possible create , download new mp3 file these new effects, using web audio api or writing mp3 container javascript library ? if not whats best solve on web ?
update - using offlineaudiocontext
using sample code https://developer.mozilla.org/en-us/docs/web/api/offlineaudiocontext/oncomplete
i've tried using offline node so;
var audioctx = new audiocontext(); var offlinectx = new offlineaudiocontext(2,44100*40,44100); osource = offlinectx.createbuffersource(); function getdata() { request = new xmlhttprequest(); request.open('get', 'song1.mp3', true); request.responsetype = 'arraybuffer'; request.onload = function() { var audiodata = request.response; audioctx.decodeaudiodata(audiodata, function(buffer) { mybuffer = buffer; osource.buffer = mybuffer; osource.connect(offlinectx.destination); osource.start(); //source.loop = true; offlinectx.startrendering().then(function(renderedbuffer) { console.log('rendering completed successfully'); var audioctx = new (window.audiocontext || window.webkitaudiocontext)(); var song = audioctx.createbuffersource(); song.buffer = renderedbuffer; song.connect(audioctx.destination); song.start(); rec = new recorder(song, { workerpath: 'recorderjs/recorderworker.js' }); rec.exportwav(function(e){ rec.clear(); recorder.forcedownload(e, "filename.wav"); }); }).catch(function(err) { console.log('rendering failed: ' + err); // note: promise should reject when startrendering called second time on offlineaudiocontext }); }); } request.send(); } // run getdata start process off getdata();
still getting recorder download empty file, i'm using song source source recorder. song plays , code recorder doesn't download it
use https://github.com/mattdiamond/recorderjs record .wav file. use https://github.com/akrennmair/libmp3lame-js encode .mp3.
there's nifty guide here, if need hand: http://audior.ec/blog/recording-mp3-using-only-html5-and-javascript-recordmp3-js/
update
try moving
rec = new recorder(song, { workerpath: 'recorderjs/recorderworker.js' });
so located above call start rendering, , connect osource instead, so:
rec = new recorder(osource, { workerpath: 'recorderjs/recorderworker.js' }); osource.connect(offlinectx.destination); osource.start(); offlinectx.startrendering().then(function(renderedbuffer) { .....
Comments
Post a Comment