gpt4 book ai didi

javascript - WebRTC - 如何使本地音频输出静音

转载 作者:可可西里 更新时间:2023-11-01 01:33:26 24 4
gpt4 key购买 nike

我试图在 WebRTC 中仅将本地音频播放静音,更具体地说是在 getUserMedia() 之后和建立任何服务器连接之前。我找到的所有选项都不起作用; Muaz Khan 的这个失败了:

var audioTracks = localMediaStream.getAudioTracks();
// if MediaStream has reference to microphone
if (audioTracks[0]) {
audioTracks[0].enabled = false;
}

source

这个技巧也是described here作为“工作”,但在 Chrome 版本 39.0.2171.95(64 位)(Ubuntu 14.04) 上失败。

据说通过使用音量增益起作用的其他方法:

window.AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
var source = audioContext.createMediaStreamSource(clientStream);
var volume = audioContext.createGain();
source.connect(volume);
volume.connect(audioContext.destination);
volume.gain.value = 0; //turn off the speakers

tl;dr 我不想在我的扬声器上听到麦克风的输入,但我确实想看到我的视频图像。

解决方法

此解决方法由 Benjamin Trent 建议它通过在视频标签上设置 muted 属性来使音频静音,如下所示:

document.getElementById("html5vid").muted = true;

Also similar question, but its for video, so not the same

最佳答案

添加这个作为答案,因为它是事实上的正确答案:

您所说的解决方法是许多主要 WebRTC 视频平台所使用的方法:

navigator.mediaDevices.getUserMedia({ video: true, audio: true })
.then(stream => {
const vid = document.getElementById('html5vid');
vid.autoplay = true;
vid.muted = true;
vid.srcObject = stream;
});

关于javascript - WebRTC - 如何使本地音频输出静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27908408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com