简体   繁体   English

Chrome扩展程序捕获选项卡音频

[英]Chrome Extension Capture Tab Audio

I'm trying to create a Chrome extension that captures the audio from the active tab and either sends it to another server or makes it accessible via a URL. 我正在尝试创建一个Chrome扩展程序,该扩展程序可以捕获活动选项卡中的音频并将其发送到另一台服务器,或者使其可以通过URL进行访问。

I'm using the chrome.tabCapture.capture API and can successfully get a MediaStream of the tab's audio, but I don't know what to do after that. 我正在使用chrome.tabCapture.capture API ,可以成功获取选项卡音频的MediaStream ,但是在此之后我不知道该怎么办。

The Chrome docs have nothing about MediaStreams so I've looked through some documentation here and played with the JS debugger to see what methods are available, but can't find a way to send the MediaStream somewhere. Chrome文档与MediaStreams无关,因此我在这里浏览了一些文档并与JS调试器一起使用,以查看可用的方法,但找不到将MediaStream发送到某处的方法。

It's now possible to record a stream locally in JS using MediaRecorder . 现在可以使用MediaRecorder在JS中本地记录流。 There is a demo here and the w3c spec is here 有一个演示在这里和W3C规范是这里

The method startRecording in the demo requires window.stream to be set to the MediaStream instance. 演示中的startRecording方法要求将window.stream设置为MediaStream实例。

// The nested try blocks will be simplified when Chrome 47 moves to Stable
var mediaRecorder;
var recordedBlobs;
window.stream = myMediaStreamInstance;
function startRecording() {
  var options = {mimeType: 'video/webm', bitsPerSecond: 100000};
  recordedBlobs = [];
  try {
    mediaRecorder = new MediaRecorder(window.stream, options);
  } catch (e0) {
    console.log('Unable to create MediaRecorder with options Object: ', e0);
    try {
      options = {mimeType: 'video/webm,codecs=vp9', bitsPerSecond: 100000};
      mediaRecorder = new MediaRecorder(window.stream, options);
    } catch (e1) {
      console.log('Unable to create MediaRecorder with options Object: ', e1);
      try {
        options = 'video/vp8'; // Chrome 47
        mediaRecorder = new MediaRecorder(window.stream, options);
      } catch (e2) {
        alert('MediaRecorder is not supported by this browser.\n\n' +
            'Try Firefox 29 or later, or Chrome 47 or later, with Enable experimental Web Platform features enabled from chrome://flags.');
        console.error('Exception while creating MediaRecorder:', e2);
        return;
      }
    }
  }
  console.log('Created MediaRecorder', mediaRecorder, 'with options', options);

  // do UI cleanup here
  mediaRecorder.onstop = function() {/** stop */};
  mediaRecorder.ondataavailable = function() {/** data avail */};
  mediaRecorder.start(10); // collect 10ms of data
  console.log('MediaRecorder started', mediaRecorder);
}
  1. https://www.w3.org/TR/mediastream-recording/ https://www.w3.org/TR/mediastream-recording/
  2. https://simpl.info/mediarecorder/ https://simpl.info/mediarecorder/

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

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