fix: Filter out Stereo Mix and select real microphone device
- Filter out "立體聲混音" (Stereo Mix) devices which are not real microphones - Skip the "default" device which may point to Stereo Mix - Prefer "communications" device or devices with "麥克風/microphone" in label - Use exact deviceId constraint for better device selection - Add fallback to preferred constraint if exact fails - Add more detailed console logging for debugging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -415,14 +415,39 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Try with simple constraints first, fall back to more specific ones
|
||||
// Filter out Stereo Mix (立體聲混音) - it's not a real microphone
|
||||
const realMicrophones = audioInputs.filter(d =>
|
||||
!d.label.includes('立體聲混音') &&
|
||||
!d.label.toLowerCase().includes('stereo mix') &&
|
||||
d.deviceId !== 'default' // Skip default which might be Stereo Mix
|
||||
);
|
||||
|
||||
// Prefer communications device or actual microphone
|
||||
let selectedMic = realMicrophones.find(d =>
|
||||
d.deviceId === 'communications' ||
|
||||
d.label.includes('麥克風') ||
|
||||
d.label.toLowerCase().includes('microphone')
|
||||
) || realMicrophones[0];
|
||||
|
||||
console.log('Real microphones found:', realMicrophones.length);
|
||||
console.log('Selected microphone:', selectedMic);
|
||||
|
||||
if (!selectedMic) {
|
||||
alert('No real microphone found. Only Stereo Mix detected. Please connect a microphone.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Try with the selected microphone
|
||||
try {
|
||||
mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||
} catch (simpleErr) {
|
||||
console.warn('Simple audio constraints failed, trying with device ID:', simpleErr);
|
||||
// Try with explicit device ID
|
||||
mediaStream = await navigator.mediaDevices.getUserMedia({
|
||||
audio: { deviceId: audioInputs[0].deviceId }
|
||||
audio: { deviceId: { exact: selectedMic.deviceId } }
|
||||
});
|
||||
console.log('Successfully connected to:', selectedMic.label);
|
||||
} catch (exactErr) {
|
||||
console.warn('Exact device ID failed, trying preferred:', exactErr);
|
||||
// Fallback: try with preferred instead of exact
|
||||
mediaStream = await navigator.mediaDevices.getUserMedia({
|
||||
audio: { deviceId: selectedMic.deviceId }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user