[mirotalk] - rb
This commit is contained in:
+29
-40
@@ -2930,48 +2930,37 @@ async function initEnumerateVideoDevices() {
|
||||
* @param {object} stream
|
||||
*/
|
||||
async function enumerateAudioDevices(stream) {
|
||||
try {
|
||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||
|
||||
// Detect presence of potentially low-quality Bluetooth headsets
|
||||
const hasLowQualityBT = devices.some(
|
||||
(d) => d.kind === 'audioinput' && /(bluetooth|headset|hands[- ]?free|hsp|hfp|sco|airpods)/i.test(d.label)
|
||||
);
|
||||
if (hasLowQualityBT) {
|
||||
alert(
|
||||
'⚠️ You’re using a Bluetooth headset with limited audio quality. For best results, use your device’s built-in microphone or a wired headset.'
|
||||
);
|
||||
}
|
||||
|
||||
// Populate selects and counts
|
||||
devices.forEach(async (device) => {
|
||||
console.log('enumerateAudioDevices', device.label);
|
||||
let el,
|
||||
eli = null;
|
||||
if ('audioinput' === device.kind) {
|
||||
el = audioInputSelect;
|
||||
eli = initMicrophoneSelect;
|
||||
lS.DEVICES_COUNT.audio++;
|
||||
} else if ('audiooutput' === device.kind) {
|
||||
el = audioOutputSelect;
|
||||
eli = initSpeakerSelect;
|
||||
lS.DEVICES_COUNT.speaker++;
|
||||
console.log('06. Get Audio Devices');
|
||||
await navigator.mediaDevices
|
||||
.enumerateDevices()
|
||||
.then((devices) =>
|
||||
devices.forEach(async (device) => {
|
||||
let el,
|
||||
eli = null;
|
||||
if ('audioinput' === device.kind) {
|
||||
el = audioInputSelect;
|
||||
eli = initMicrophoneSelect;
|
||||
lS.DEVICES_COUNT.audio++;
|
||||
} else if ('audiooutput' === device.kind) {
|
||||
el = audioOutputSelect;
|
||||
eli = initSpeakerSelect;
|
||||
lS.DEVICES_COUNT.speaker++;
|
||||
}
|
||||
if (!el) return;
|
||||
await addChild(device, [el, eli]);
|
||||
})
|
||||
)
|
||||
.then(async () => {
|
||||
await stopTracks(stream);
|
||||
isEnumerateAudioDevices = true;
|
||||
//const sinkId = 'sinkId' in HTMLMediaElement.prototype;
|
||||
audioOutputSelect.disabled = !sinkId;
|
||||
// Check if there is speakers
|
||||
if (!sinkId || initSpeakerSelect.options.length === 0) {
|
||||
elemDisplay(initSpeakerSelect, false);
|
||||
elemDisplay(audioOutputDiv, false);
|
||||
}
|
||||
if (!el) return;
|
||||
await addChild(device, [el, eli]);
|
||||
});
|
||||
|
||||
await stopTracks(stream);
|
||||
isEnumerateAudioDevices = true;
|
||||
audioOutputSelect.disabled = !sinkId;
|
||||
// Check if there is speakers
|
||||
if (!sinkId || initSpeakerSelect.options.length === 0) {
|
||||
elemDisplay(initSpeakerSelect, false);
|
||||
elemDisplay(audioOutputDiv, false);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('enumerateAudioDevices error', err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user