User:StasFomin/HowTo/GetDefaultMicOnWindows

From Wiki4Intranet
Jump to: navigation, search

Written For: https://github.com/spatialaudio/python-sounddevice/issues/45#issuecomment-256570747


The problem
Get default mic on Windows, to specify it for ffmpeg. For example I want to capture some video or audio and specify default windows audio device.

I have about 10 of laptops with such audio devices:

Audio configuration of HP2540p on Windows10.png
Audio configuration of HP2540p on Windows10 and Audacity.png


As we can see, we have two audio devices with same name

  • "Microphone (High Definition Audio Device)"

(One — working, default, one - disabled).

We have to specify the right one, but we cannot use original name.


If we list devices by ffmpeg, we see unique alternative names like "@device_cm_{xxxx}\wave_{yyyy}"

ffmpeg -list_devices true -f dshow -i dummy:
…
DirectShow video devices (some may be both video and audio devices)
[dshow @ 04e332a0] Could not enumerate video devices (or none found).
[dshow @ 04e332a0] DirectShow audio devices
[dshow @ 04e332a0]  "Microphone (High Definition Audio Device)"
[dshow @ 04e332a0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{26076D90-56E0-4313-8919-07C91C3285D8}"
[dshow @ 04e332a0]  "Line (Elgato Sound Capture)" [dshow @ 04e332a0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{066F1F62-9858-4DC2-A6E6-CBA5DC57D17F}"
[dshow @ 04e332a0]  "Microphone (High Definition Audio Device)"
[dshow @ 04e332a0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{469C7D87-9CF7-4C0C-A12B-419714989D7E}"
…

The only way to set correct input device for ffmpeg — is to specify unique alternative name.

I tried to get default input device by sounddevice

import sounddevice as sd
print sd.query_devices()

get

   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
>  1 Microphone (High Definition Aud, MME (2 in, 0 out)
   2 Line (Elgato Sound Capture), MME (2 in, 0 out)
   3 Microphone (High Definition Aud, MME (2 in, 0 out)
   4 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
<  5 Speakers (High Definition Audio, MME (0 in, 2 out)
   6 Speakers (Elgato Sound Capture), MME (0 in, 2 out)
   7 Primary Sound Capture Driver, Windows DirectSound (2 in, 0 out)
   8 Microphone (High Definition Audio Device), Windows DirectSound (2 in, 0 out)
   9 Line (Elgato Sound Capture), Windows DirectSound (2 in, 0 out)
  10 Microphone (High Definition Audio Device), Windows DirectSound (2 in, 0 out)
  11 Primary Sound Driver, Windows DirectSound (0 in, 2 out)
  12 Speakers (High Definition Audio Device), Windows DirectSound (0 in, 2 out)
  13 Speakers (Elgato Sound Capture), Windows DirectSound (0 in, 2 out)
  14 Speakers (Elgato Sound Capture), Windows WASAPI (0 in, 2 out)
  15 Speakers (High Definition Audio Device), Windows WASAPI (0 in, 2 out)
  16 Line (Elgato Sound Capture), Windows WASAPI (2 in, 0 out)
  17 Microphone (High Definition Audio Device), Windows WASAPI (2 in, 0 out)
  18 Microphone (High Definition Audio Device), Windows WASAPI (2 in, 0 out)
  19 Microphone 1 (HD Audio Muxed capture), Windows WDM-KS (2 in, 0 out)
  20 Microphone 2 (HD Audio Muxed capture), Windows WDM-KS (2 in, 0 out)
  21 Speakers (HD Audio Headphone/Speakers), Windows WDM-KS (0 in, 2 out)
  22 Line (Elgato Sound Capture Wave), Windows WDM-KS (2 in, 0 out)
  23 Speakers (Elgato Sound Capture Wave), Windows WDM-KS (0 in, 2 out)

So impossible to distingvish between device 1 "Microphone (High Definition Aud, MME (2 in, 0 out)" and 3 "Microphone (High Definition Aud, MME (2 in, 0 out)" and now way how to map selected by sounddevice input device to ffmpeg list of directshow input devices (I tried buy numbers/orders, but there is no correlations).