我正在学习 html5,想尝试在扬声器上播放我在麦克风上所说的内容。于是我写了如下js代码:
navigator.getUserMedia = navigator.getUserMedia ||navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
var aCtx;
var analyser;
var microphone;
if (navigator.getUserMedia) {
navigator.getUserMedia(
{audio: true},
function(stream) {
aCtx = new AudioContext();
analyser = aCtx.createAnalyser();
microphone = aCtx.createMediaStreamSource(stream);
microphone.connect(analyser);
var destination=aCtx.destination;
analyser.connect(destination);
},
function(){ console.log("Error 003.")}
);
}
我在 Firefox 47 和 ubuntu 14 上进行了测试。我看到面板共享我的麦克风,我选择共享,但什么也没听到。如何解决?
编辑: 然而,它可以在windows7中的firefox 47上运行。但在 ubuntu 中,我安装了所有驱动程序,并且使用 skype、youtube 等,除了这个 js 脚本之外,一切都正常。
最佳答案
它适用于我的 Firefox 和 Chrome(我使用的是 Macbook Pro OSX 10.11)
https://jsfiddle.net/greggman/g88v7p8c/
请注意,它不能在 stackoverflow 上运行,因为使用麦克风需要 HTTPS(至少在 Chrome 上,没有检查 firefox)。如果页面不是 HTTPS,那么我会得到
getUserMedia()
no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See httpsgoo.gl/rStTGz for more details.`
愚蠢的 stackoverflow 不会让我发布来自 chrome 的实际消息,因为 stackoverflow 禁止 goo.gl
关于javascript - HTML5 : play on speakers stream from microphone on Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38279999/