Psychopy cannot find my microphone

Hi everyone, I’m programming my experiment using PsychoPy. I’m running the experiment on a lab PC which is connected to a bunch of different audio devices. In my experiment I need to recording participants’ responses, but it looks like PsychoPy cannot fine the microphone I’m using. Both Windows and Audacity can find the microphone and record with no problem. When I run the experiment using PsychoPy, it runs normally but all the recorded files are silence.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2023.1.1
Standard Standalone? (y/n) Y
What are you trying to achieve?:
Record participants’ answers
What did you try to make it work?:
I have a microphone component in my routine. The hardware setting of the microphone component is set to channels: auto, sample rate: 44.1Hz, max recording size 24000kb.

In the code view this is how the microphone is set up:

# create a microphone object for device: default
defaultMicrophone = sound.microphone.Microphone(
    device=None, channels=1, 
    sampleRateHz=44100, maxRecordingSize=24000.0
)

I wonder whether it’s the device=None doing something funny but I don’t know how to change it in the GUI.
What specifically went wrong when you tried that?:
With the current setting, the experiment runs normally. (There is no “‘Stream’ object has no attribute ‘handle’” error so presumably I have the sampling rate set correctly). It also generates recording files when the experiment is finished, but all is recorded is just silence.

Edit:
This is the output when I run the experiment.

##### Running: \test_no_mictest.py #####
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
PTB-INFO: Using modified PortAudio V19.7.0-devel, revision unknown
PTB-INFO: New audio device 31 with handle 0 opened as PortAudio stream:
PTB-INFO: For 2 channels Capture: Audio subsystem is Windows WASAPI, Audio device name is Analog (3+4) (RME Fireface UC)
PTB-INFO: Real samplerate 44100.000000 Hz. Input latency 9.795918 msecs, Output latency 0.000000 msecs.
2.7961     WARNING     We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use ['pygame'] (in that order).
9.8675     WARNING     Hamming was requested using the 'pygame' sound library but hamming is not supported there.
9.8822     WARNING     Hamming was requested using the 'pygame' sound library but hamming is not supported there.
0.9419     WARNING     Monitor specification not found. Creating a temporary one...
ioHub Server Process Completed With Code:  0

No wonder it’s not recording, Analog (3+4) (RME Fireface UC) is not the microphone I’m using. It’s also not the input device in the Windows setting, I have no idea why psychopy is finding this one.

Edit 2:
I fixed it. (I reverted to PsychoPy 2022.2.5 before fixing the issue but maybe the fix is similar in newer versions.) I looked at C:\Program Files\PsychoPy\Lib\site-packages\psychopy\microphone.py, and found out that if no device index is provided, PsychoPy will use the first device in the device list it gets from psychtoolbox. Which, in my case, is neither the Window default or the one that I’m using. I still cannot find where to provide the device index in the GUI, but I can change the experiment.py in coder view. To find out what indices my devices have, I ran this in the coder view (after importing everything):

devices = sound.microphone.Microphone.getDevices()
devicesByIndex = {d.deviceIndex: d for d in devices}
print(devicesByIndex)

which gave me something like this:

{31: AudioDeviceInfo(deviceIndex=31, deviceName=Analog (3+4) (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb'), 32: AudioDeviceInfo(deviceIndex=32, deviceName=ADAT (5+6) (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb'), 33: AudioDeviceInfo(deviceIndex=33, deviceName=Analog (7+8) (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb'), 34: AudioDeviceInfo(deviceIndex=34, deviceName=ADAT (3+4) (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb'), 35: AudioDeviceInfo(deviceIndex=35, deviceName=ADAT (7+8) (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb'), 36: AudioDeviceInfo(deviceIndex=36, deviceName=Analog (5+6) (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb'), 37: AudioDeviceInfo(deviceIndex=37, deviceName=SPDIF coax. (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb'), 38: AudioDeviceInfo(deviceIndex=38, deviceName=Analog (1+2) (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb'), 39: AudioDeviceInfo(deviceIndex=39, deviceName=SPDIF/ADAT (1+2) (RME Fireface UC), hostAPIName=Windows WASAPI, outputChannels=0, outputLatency=(0.0, 0.0), inputChannels=2, inputLatency=(0.003, 0.01), defaultSampleRate=44100, audioLib='ptb')}

I found the index of my device and in experiment.py, I simply provided the index:

response = sound.microphone.Microphone(
    device=38, channels=2, 
    sampleRateHz=44100, maxRecordingSize=24000.0
)

Now PTB can use the correct microphone and I can get my recordings.