问题
It's seems like audio capturing using chrome.tabCapture.capture can produce some choppy sounds.
There is already a bug report for this.
Is it possible to increase the buffer that receives the captured stream in order to prevent the stutter, or does the tabCapture
method already defines a buffer?
Basic capturing:
chrome.tabCapture.capture({
audio: true,
video: false
}, function (stream) {
var ctx = new AudioContext();
var output = ctx.createMediaStreamSource(stream);
output.connect(ctx.destination)
});
回答1:
I had the same issue, but the choppy sound seems to disappear if you create the AudioContext
with a LatencyHint
argument:
new AudioContext({latencyHint: 'playback'});
Here you can read more about it: MDN AudioContext.AudioContext()
latencyHint: This value identifies type of playback, which affects tradeoffs between audio output latency and power consumption. The prefered values are "balanced", "interactive", and "playback", with the default value: "interactive". These values mean "balance audio output latency and power consumption", "provide lowest audio output latency as possible without glitching", and "prioritize sustained playback without interruption over audio output latency". You can also specify double value for the number of seconds of latency, for finer control.
来源:https://stackoverflow.com/questions/45910705/chrome-extension-prevent-chrome-tabcapture-capture-choppy-sound-by-increasing-b