假设我使用Recorder.js从麦克风录制音频。然后如何修剪/裁剪/ slice /剪切录音?意思是说我录制了3.5秒,而我只想要前3秒。有任何想法吗?

最佳答案

您可以在3秒后停止原始记录,或者使用<audio>元素,HTMLMediaElement.captureStream()MediaRecorder记录原始记录回放的3秒。

const audio = new Audio(/* Blob URL or URL of recording */);
const chunks = [];
audio.oncanplay = e => {
  audio.play();
  const stream = audio.captureStream();
  const recorder = new MediaRecorder(stream);
  recorder.ondataavailable = e => {
    if (recorder.state === "recording") {
      recorder.stop()
    };
    chunks.push(e.data)
  }
  recorder.onstop = e => {
    console.log(chunks)
  }
  recorder.start(3000);
}

关于javascript - 如何在JavaScript中剪切录音,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45662302/

10-09 16:55