将javascript与计算机声音输入设备集成

时间:2016-11-10 09:54:41

标签: javascript html5-audio speaker

我正在使用javascript开发一个应用程序,它使用html 5音频上下文记录音频。我想开发一个功能,需要当前有源声音设备是连接麦克风还是默认的笔记本电脑/计算机麦克风,并调整其设置,如降低音量。有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:2)

您可以使用MediaDevices.getUserMedia() API方法。将提示用户允许使用音频输入设备。浏览器支持目前仅限于Chrome,Firefox和Opera,请参阅http://caniuse.com/#search=MediaRecorder

navigator.mediaDevices.getUserMedia({ audio: true })
.then(function (stream) {
  // the audio stream is available here
  recorder = new MediaRecorder(stream);
  // listen to dataavailable, which gets triggered
  // when an audio blob is available
  recorder.addEventListener('dataavailable', onRecordingReady);
});

function onRecordingReady(e) {
  // e.data contains a blob that represents the recording
}