【发布时间】:2020-04-28 10:11:23
【问题描述】:
我在处理数据流方面完全没有经验,想将 getUserMedia 作为一个学习项目提供给 opus 转换器,然后 - 可能太天真了 - 通过 socket.io 发送它。 我的——也许是错误的想法——是我不断地分割和转换流。
我感谢所有解释一般流处理更好一点的解释,因为我说过这是一个学习项目,我知道使用 WebRTC 可以获得更好的解决方案。
作为编码器,我想使用https://github.com/ImagicTheCat/libopusjs。欢迎使用替代方案,但我想坚持使用基于 wasm 的编码器的想法。
到目前为止我所拥有的(作为第一步,我的想法是对流进行编码并解码并再次输出):
if (navigator.mediaDevices) {
console.log('getUserMedia supported.');
navigator.mediaDevices.getUserMedia ({audio: true, video: true})
.then(function(stream) {
video.srcObject = stream;
video.onloadedmetadata = function(e) {
video.play();
video.muted = true;
};
var audioCtx = new AudioContext();
var source = audioCtx.createMediaStreamSource(stream);
var enc = new libopus.Encoder(1,48000,24000,20,false);
=> enc stream
var dec = new libopus.Decoder(1,48000);
=> perspectively send this enc stream via socketio
=> dec enc stream => RESULT stream
RESULT.connect(audioCtx.destination);
})
.catch(function(err) {
console.log('The following gUM error occured: ' + err);
});
} else {
console.log('getUserMedia not supported on your browser!');
}
【问题讨论】:
-
也看看这个:61292834
标签: javascript stream webassembly opus