gpt4 book ai didi

safari - try catch 音频但 navigator.mediaDevices.enumerateDevices() 在 Safari 12 上为 NULL,即使已授予麦克风权限

转载 作者:行者123 更新时间:2023-12-05 07:23:26 30 4
gpt4 key购买 nike

参见相关问题:Navigator.mediaDevices.getUserMedia not working on iOS 12 Safari

我们正在尝试从用户输入的用户 MediaDevices.getUserMedia 和音频上下文中捕获音频

当用户点击一个按钮时,我们检查可用的设备,然后我们捕获他们的音频流

let enumDevicePromise = navigator.mediaDevices.enumerateDevices()
.then(devices => devices.find(d => d.kind === "audioinput" && d.label !== "" && d.deviceId === "default"))
.catch((error) => {
// handle error
});
this.handleCheckEnumeratedDevices(enumDevicePromise); // capture device in backend

.....

navigator.mediaDevices
.getUserMedia({
audio: true,
video: false,
})
.then(stream => {
let AudioContext = window.AudioContext || window.webkitAudioContext;
if (AudioContext) {
let context = new AudioContext();
let source = context.createMediaStreamSource(stream);
let processor = context.createScriptProcessor(4096, 1, 1);
source.connect(processor);
processor.connect(context.destination);
processor.onaudioprocess = (event) => {
let audioIn = event.inputBuffer.getChannelData(0);
this.sendMessage(this.toInt16(audioIn));
}
} else {
// handle error, ie, Audio Context not supported
}
}).catch((error) => {
// handle error
});
});

这在 Chrome 和 Firefox 上运行良好,但在 Safari 12 上,我们从枚举设备 promise 中得到一个 Null 响应 - 尽管允许麦克风权限 - 因此我们无法捕获音频流

最佳答案

发生这种情况是因为 Mobile Safari 不公开“audioinput”类型的媒体设备。这是一个已知的限制。

关于safari - try catch 音频但 navigator.mediaDevices.enumerateDevices() 在 Safari 12 上为 NULL,即使已授予麦克风权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56047028/

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