Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
445 views
in Technique[技术] by (71.8m points)

javascript - How to record browser tab audio using tabCapture API

As an exercise I'm learning how to record stream from browser tabs. I've this code that will call the MediaRecorder API after that the tabCapture API is called in chrome. How I can use the stream object that will be provided from the tabCapture and save it as audio? I've searched around here but I was not able to find any similar question. At the moment this is the code I have, I'm writing a class to record the audio

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);
    });
  }

}
question from:https://stackoverflow.com/questions/65869745/how-to-record-browser-tab-audio-using-tabcapture-api

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...