使用javascript修剪音频文件(前3秒) [英] Trim an audio file using javascript (first 3 seconds)

查看:58
本文介绍了使用javascript修剪音频文件(前3秒)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我可以修剪通过javascript录制的音频文件.我想修剪一下它的前3秒钟,您能帮我吗?我使用p5.j录制了音频文件,并使用AudioContext()合并了已录制的文件和真实的karaoke文件,由于开始时发出的令人不愉快的声音使合并错误,因此必须对其进行修剪.

I have a question that can i trim my audio file that is recorded via javascript. I want to trim the first 3 seconds of it can you help me please? I recorded the audio file using p5.j and merged the recorded file and a real karaoke file with AudioContext() and I have to trim it because of unpleasant sound at starting that makes merging wrong.

推荐答案

您可能需要使用诸如 AudioBufferSourceNode.start() 并记录生成的输出流.

You will probably need to read the audio into an AudioBuffer using something like AudioContext.decodeAudioData(), plug the AudioBuffer into a AudioBufferSourceNode. Then you can skip the first 3 seconds using the offset parameter of AudioBufferSourceNode.start() and record the resulting output stream.

示例代码:

var source = audioCtx.createBufferSource();
var dest = audioCtx.createMediaStreamDestination();
var mediaRecorder = new MediaRecorder(dest.stream);

var request = new XMLHttpRequest();
request.open('GET', 'your.ogg', true);
request.responseType = 'arraybuffer';

request.onload = function() {
  var audioData = request.response;
  audioCtx.decodeAudioData(
    audioData,
    function(buffer) {
      source.buffer = buffer;
      source.connect(dest);
      mediaRecorder.start();
      source.start(audioCtx.currentTime, 3);
      // etc...
    },
    function(e){ 
      console.log("Error with decoding audio data" + e.err);
    }
  );

}

request.send();

这篇关于使用javascript修剪音频文件(前3秒)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆