hum*_*ace 6 javascript audio html5 volume
该navigator.getUserMedia(....)调用可以在一些现代浏览器中用于在Javascript中录制音频.
有没有办法调整/设置麦克风的输入音量?
此设置并非总是最佳.有时麦克风设置为仅以非常低的输入音量进行录制.当然,用户可以手动调整系统中的输入音量级别,但我的大多数用户可能缺乏这样做的知识.因此,我最好能够在通过" navigator.getUserMedia(....)"方式记录数据的JavaScript应用程序内动态调整麦克风音量?
是否有解决方案来影响麦克风的输入音量?
通过Web Audio API,您可以更改流的麦克风输入.
这是一个示例,它显示了如何将a转换MediaStream为另一个MediaStream,但能够动态更改音量.如果你只是想播放的音频,则可以更改gainNode.connect(dest)到gainNode.connect(ctx.destination)并删除使用其他两个行dest变量.
if (!navigator.getUserMedia) {
navigator.getUserMedia = navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
}
navigator.getUserMedia({
audio: true
}, function(stream) {
var ctx = new AudioContext();
var source = ctx.createMediaStreamSource(stream);
var dest = ctx.createMediaStreamDestination();
var gainNode = ctx.createGain();
source.connect(gainNode);
gainNode.connect(dest);
document.getElementById('volume').onchange = function() {
gainNode.gain.value = this.value; // Any number between 0 and 1.
};
gainNode.gain.value = document.getElementById('volume').value;
// Example: play the audio
// Or if you use WebRTC, use peerConnection.addStream(dest.stream);
new Audio(URL.createObjectURL(dest.stream)).play();
// Store the source and destination in a global variable
// to avoid losing the audio to garbage collection.
window.leakMyAudioNodes = [source, dest];
}, function(e) {
alert(e); // TODO: Handle error.
});
// For the demo only:
document.getElementById('volume').onchange = function() {
alert('Please provide access to the microhone before using this.');
};Run Code Online (Sandbox Code Playgroud)
Volume: <input type=range id=volume min=0 max=1 value=1 step=0.01>Run Code Online (Sandbox Code Playgroud)
注意:通过Stack片段的实时演示在Chrome中不起作用,因为getUserMedia似乎对沙盒框架不起作用.如果您使用Chrome,请尝试以下网址:https://robwu.nl/s/mediasource-change-volume.html
| 归档时间: |
|
| 查看次数: |
3808 次 |
| 最近记录: |