Javascript 如何在WebRTC中设置卷?
我想知道如何在WebRTC中设置卷 我画的音频是这样的:Javascript 如何在WebRTC中设置卷?,javascript,html,webrtc,Javascript,Html,Webrtc,我想知道如何在WebRTC中设置卷 我画的音频是这样的: audio = document.createElement('audio'); audio.controls = true; audio.autoplay = true; audio.src = window.URL.createObjectURL(stream); div.appendChild(audio); 我想制作我的自定义音频用户界面。所以,我将使用HTML的滑动条 <input type="range">
audio = document.createElement('audio');
audio.controls = true;
audio.autoplay = true;
audio.src = window.URL.createObjectURL(stream);
div.appendChild(audio);
我想制作我的自定义音频用户界面。所以,我将使用HTML的滑动条
<input type="range">
但是,我不知道WebRTC流中的设置卷。如何设置?对于输出(扬声器)音频音量,您可以使用音频/视频元素的音量属性进行管理
var audio = document.getElementById('audioId');
audio.volume = 0.9; // 0.0(Silent) -> 1 (Loudest)
您可以根据滑动条的位置更改audio.volume
要更改输入(麦克风)音量,WebRTC AudioTrack/MediaStream中没有可用的直接方法
我们可以使用在流/曲目级别处理音量,您可以将WebAudio输出连接到PeerConnection,如下所示
var audioContext = new AudioContext()
var gainNode = audioContext.createGain();
navigator.mediaDevices.getUserMedia({audio:true})
.then((stream) => {
console.log('got stream', stream);
window.orginalStream = stream;
return stream;
})
.then((stream) => {
audioSource = audioContext.createMediaStreamSource(stream),
audioDestination = audioContext.createMediaStreamDestination();
audioSource.connect(gainNode);
gainNode.connect(audioDestination);
gainNode.gain.value = 1;
window.localStream = audioDestination.stream;
//audioElement.srcObject = window.localStream; //for playback
//you can add this stream to pc object
// pc.addStream(window.localStream);
})
.catch((err) => {
console.error('Something wrong in capture stream', err);
})
现在我们可以通过以下功能轻松控制麦克风音量
function changeMicrophoneLevel(value) {
if(value && value >= 0 && value <= 2) {
gainNode.gain.value = value;
}
}
功能更改麦克风级别(值){
如果(value&&value>=0&&value相关:我正在使用WebRTC VoiceEngine模块。我已经能够使用WebRTCAdioRecord
类成功录制音频字节,但无法理解,我可以在WebRTCAdioTrack
中推送或放置接收字节。我还没有找到任何方法或回调来给出接收字节字节到WebRTCAdioTrack
播放。您能帮助我吗。