[英]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. 如果您或该用户有权访问媒体,请尝试使用
Audio
和File
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.