简体   繁体   English

有没有办法使用Javascript或任何其他网络语言捕获浏览器的音频?

[英]Is there a way to capture a browser's audio using Javascript or any other web language?

I want to make a simple website that displays interactive visuals and I would like for some of them to be audio-driven. 我想创建一个显示交互式视觉效果的简单网站,我希望其中一些是音频驱动的。 I want the visitors to be able to drive the visuals with their own choice of music. 我希望访客能够用他们自己选择的音乐来驱动视觉效果。 I've had difficulty finding much documentation on anything other than getting audio input from microphones. 除了从麦克风输入音频输入之外,我很难找到其他任何文档。

For example, my webpage (in tab 1) is running javascript code X that allows me to process the audio stream playing in another tab of the web browser. 例如,我的网页(在标签1中)运行javascript代码X,允许我处理在Web浏览器的另一个选项卡中播放的音频流。 Is this possible? 这可能吗?

If I understand your question correctly you want to capture audio from sources outside of the current tab. 如果我正确理解您的问题,您希望从当前选项卡之外的来源捕获音频。

There is no such api as part of the W3C the spec , probably due to the problems concerning user integrity that would arise if there was. 作为W3C规范的一部分,没有这样的api,可能是由于存在与用户完整性有关的问题。 As the browser is essentially executing foreign code browsers tend to be strictly sandboxed and requiring consent to prevent any violations of the users privacy. 由于浏览器基本上是在执行外部代码,因此浏览器往往是严格的沙盒并且需要同意以防止任何违反用户隐私的行为。

If you or the user has access to the media try using the Audio and File APIs. 如果您或该用户有权访问媒体,请尝试使用AudioFile API。 If neither that nor using input audio capturing APIs as you mentioned is sufficient you'll either have to turn to creating a browser extension or to another platform altogether. 如果你提到的那个既不是也不使用输入音频捕获API就足够了,你要么必须转向创建浏览器扩展,要么完全转向另一个平台。

You can take microphone stream with WebRtc API 您可以使用WebRtc API获取麦克风流

if (!navigator.getUserMedia)
  navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
  navigator.mozGetUserMedia || navigator.msGetUserMedia;

if (navigator.getUserMedia) {
    navigator.getUserMedia({audio:true}, success, function(e) {
    });
}  

............... ...............

 function success(e) {
      audioContext = window.AudioContext || window.webkitAudioContext;
      context = new audioContext();

      // the sample rate is in context.sampleRate
      audioInput = context.createMediaStreamSource(e);

      var bufferSize = 2048;
      recorder = context.createScriptProcessor(bufferSize, 1, 1);
      recorder.onaudioprocess = function(e){

        console.log ('recording');
        var left = e.inputBuffer.getChannelData(0);
    // stream
        window.Stream.write(convertoFloat32ToInt16(left));
  }
  audioInput.connect(recorder)
  recorder.connect(context.destination); 


function convertoFloat32ToInt16(buffer) {
  var l = buffer.length;
  var buf = new Int16Array(l)
  while (l--) {
    buf[l] = buffer[l]*0xFFFF;    //convert to 16 bit
  }
  return buf.buffer
} 

If you like only visualization of audio stream you can use javascript plugins like enter link description here 如果您只想要音频流的可视化,您可以使用javascript插件,例如在此处输入链接描述

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

相关问题 浏览器/选项卡使用javascript(或任何其他语言)关闭检测 - Browser/tab close detection using javascript (or any other language) 使用Javascript的Live Calendar(不是任何其他语言) - Live Calendar using Javascript ( not any other language) 使用javascript的网页无法工作如果用户的浏览器有javascript禁用...那么有没有办法像没有javascript的onclick运行命令? - web pages using javascript cant work if user's browser has javascript disable…so is there any way to run command like onclick without javascript? 使用javascript捕获视频和音频 - Capture video and audio using javascript 使用Java或任何其他语言加载和执行jquery和javascript脚本 - Loading and Executing the jquery and javascript scripts using Java or any other language 在JavaScript / Web浏览器中捕获2个或更多键盘的事件 - Capture the events of 2 or more keyboards in JavaScript/Web Browser 带有JavaScript的HTML5音频无法使用除chrome之外的任何浏览器 - Html5 Audio with JavaScript won't work any browser other than chrome 通过使用javascript自身在Web浏览器中模拟运行javascript的方法 - Way to simulate running javascript in web browser through using javascript itself 如何通过JavaScript捕获浏览器的事件 - How to capture browser's event by javascript 有没有办法使用网络音频 api 来跟踪音量 - Is there any way to track volume with the web audio api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM