如何使用 tabCapture API 录制浏览器选项卡音频

问题描述

作为练习,我正在学习如何从浏览器选项卡记录流。在 Chrome 中调用 MediaRecorder API 之后,我有这段代码调用 tabCapture API。我如何使用 stream 提供的 tabCapture 对象并将其保存为音频?我在这里搜索过,但找不到任何类似的问题。目前这是我的代码,我正在编写一个类来录制音频

class TabAudioRecorder {

  #recorder;
  #stream = null;
  #chunks = [];

  startRecord(stream) {
    
    this.#recorder = new MediaRecorder(stream,{audioBitsPerSecond: 128000});
    this.#recorder.start();
    this.#recorder.ondataavailable = (e) => {  
      console.log('Data available');
      this.#chunks.push(e);  
    }
  }

  stopRecord() {
    this.#recorder.stop();
    let blob = new Blob(this.#chunks,{type: 'audio/mpeg'});
    let url = URL.createObjectURL(blob);
    console.log(blob,url);
    chrome.downloads.download({
      url: url,saveAs: true
    },(downloadId) => { 
      console.log(downloadId);
    });
  }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)