2016-04-14 335 views
8

與使用AudioContext的JavaScript音頻混合已達到和導出音頻混合我使用OfflineAudioContext和n,跛腳js編碼解碼音頻,現在的expoort工作正常,但它是非常慢,我期待一個有效的方式來做到這一點比現在更快。上述如何將arrayBuffer轉換爲mp3音頻?

+2

目前沒有更好的跨瀏覽器方式來做到這一點。您可以考慮使用OGG([Firefox可以本地錄製到OGG](https://www.webrtc-experiment.com/RecordRTC/AudioVideo-on-Firefox.html)),Chrome將需要[JS OGG編碼器]( https://github.com/astroza/chrome_ogg_encoder))。編碼MP3的最快方法是使用[PNACL](http://www.chromium.org/nativeclient/pnacl/introduction-to-portable-native-client)和[NACLPorts Lame](https://github.com) /anvio/naclports/tree/master/libraries/lame-3.99-5),但它僅限於Chrome和非平凡! – CodingIntrigue

+0

沒有自己測試,但根據LameJS項目,它應該運行「比實時快20倍」。查看代碼,它似乎利用JavaScript的「Float32Array」。我會檢查您的瀏覽器是否支持該技術,以及它是否支持基於GPU的基於矩陣乘法的WebGL(它可能會)。如果沒有,我會嘗試使用瀏覽器,然後檢查速度。 –

+0

你可以看看使用emscripten並編譯跛腳編碼器源。不知道如何解決你的問題,這可能比它對你更有價值。 – Goblinlord

回答

2

檢查此[線程] [1]

document.querySelector('input').onchange = function(){ 
 
     var fileReader = new FileReader; 
 
     fileReader.onload = function(){ 
 
     var arrayBuffer = this.result; 
 
     snippet.log(arrayBuffer); 
 
     snippet.log(arrayBuffer.byteLength); 
 
     } 
 
     fileReader.readAsArrayBuffer(this.files[0]); 
 

 
     var url = URL.createObjectURL(this.files[0]); 
 
     audio_player.src = url; 
 
     audio_player.play(); 
 
    };
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 --> 
 
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script> 
 
<input id="audio_file" type="file" accept="audio/*" /> 
 
<audio id="audio_player" />