繁体   English   中英

更改音频速度,然后另存为新文件

[英]Change audio speed then save as new file

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

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

您可以使用离线音频上下文 (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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM