以下代码可在Windows,Android和Safari桌面版本上运行,但是当我尝试在iPhone SE的Safari中运行它时,我没有听到耳语或低增益。我检查了增益节点的值,并在单击按钮时将其设置为0.1,但似乎没有生效。
https://unrupt.github.io/webrtc-samples/stream-gain-control.html
<h2 class="w3-center">Media Stream with Gain Control</h2>
<p class="w3-center">The aim of this sample is to control the gain of the stream</p>
<audio id="audio" playsinline="true" controls autoplay></audio><br>
<button class="btn-fn" onclick="start()">Start!</button>
<button class="btn-fn" onclick="updateGain(0.001)">Low Gain</button>
<button class="btn-fn" onclick="updateGain(1)">Default Gain</button>
<script>
var AudioContext = window.AudioContext || window.webkitAudioContext;
var localStream;
var gainNode;
var ctx;
var dst;
var start = () => navigator.mediaDevices.getUserMedia({audio: true})
.then(stream => audio.srcObject = modifyGain(stream, 2.5))
.catch(e => log(e));
var modifyGain = (stream, gainValue) => {
localStream = stream;
ctx = new AudioContext();
var src = ctx.createMediaStreamSource(stream);
dst = ctx.createMediaStreamDestination();
gainNode = ctx.createGain();
gainNode.gain.value = gainValue;
src.connect(gainNode);
gainNode.connect(dst);
outputStream = dst.stream;
stream.addTrack(outputStream.getAudioTracks()[0]);
stream.removeTrack(stream.getAudioTracks()[0]);
//[src, gainNode, dst].reduce((a, b) => a && a.connect(b));
return stream;
};
var updateGain = (value) => {
gainNode.gain.value = value;
};
var log = msg => div.innerHTML += "<br>" + msg;
</script>
有什么建议可以尝试吗?