【问题标题】:Change audio speed then save as new file更改音频速度然后另存为新文件
【发布时间】:2016-04-29 22:24:57
【问题描述】:

无论如何,我可以通过 javascript 以编程方式更改音频文件的播放速度并将其保存为新文件吗?

我能想到的唯一解决方案是通过网络音频 api 节点传输音频文件,更改播放速率,并将输出记录为 wav 文件。这并不理想,因为我必须一直播放文件才能录制新版本。

【问题讨论】:

    标签: javascript audio


    【解决方案1】:

    您可以使用offline audio context (Web Audio API) 来处理音频。 这会处理音频,而无需等待实时播放。

    //will hold the sped up audio
    var spedUpBuffer;
    
    //Create the context 
    var offlineCtx = new OfflineAudioContext(2,44100*40,44100);//(channels,length,Sample rate);
    
    //create source node and load buffer
    var source = offlineCtx.createBufferSource();
    source.buffer = yourBuffer;
    
    //speed the playback up
    source.playbackRate.value = 1.25;
    
    //lines the audio for rendering
    source.start(0);
    
    //renders everything you lined up
    offlineCtx.startRendering();
    offlineCtx.oncomplete = function(e) {
    //copies the rendered buffer into your variable.
    spedUpBuffer = e.renderedBuffer;
    }
    

    【讨论】:

    • 你知道如何让音高正常吗?当我们更改 AudioBufferSourceNode.playbackRate 时,音频音高没有被纠正
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 2021-08-16
    相关资源
    最近更新 更多