gpt4 book ai didi

javascript - 如何处理音频流

转载 作者:行者123 更新时间:2023-12-02 21:08:05 28 4
gpt4 key购买 nike

我在处理数据流方面完全没有经验,并且想将 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!');
}

最佳答案

您见过这些 WASM 模块吗?

关于javascript - 如何处理音频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61172551/

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