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:
egg
2025-12-17 17:34:34 +08:00
parent 49dba2c43e
commit 66295f5177
2 changed files with 32 additions and 6 deletions

1
.gitignore vendored
View File

@@ -56,3 +56,4 @@ backend/record/
openspec/
AGENTS.md
CLAUDE.md
.running_pids

View File

@@ -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 }
});
}