2022 Microphone component causes error message

OS (Win10):
PsychoPy version (2022.2.4):
What are you trying to achieve?:
Microphone recording that starts at the beginning of a routine, and ends on button press

What did you try to make it work?:
I selected the microphone array

What specifically went wrong when you tried that?:
I get the following error message. I tried using the default microphone settings in the component, and got the following. I also tried using other settings but got the same message.

Hello from the pygame community. Contribute - pygame wiki
PTB-ERROR: Failed to open audio device 5. PortAudio reports this error: Invalid device
Traceback (most recent call last):
PTB-ERROR: Desired audio parameters likely unsupported by audio device.
PTB-ERROR: This could be, e.g., due to an unsupported combination of audio sample rate, audio channel count/allocation, or audio sample format.
Error in function Open: Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio(‘Open’ [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
4.7025 WARNING User requested fullscreen with size [1536 864], but screen is actually [1920, 1080]. Using actual size
File “C:\Users\james\Documents\ZDesktop\PhD\Switching Study\Tasks\All EEG tasks\AllTasksEEG_lastrun.py”, line 450, in
mic = sound.microphone.Microphone(
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychopy\sound\microphone.py”, line 478, in init
self._stream = audio.Stream(
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychtoolbox\audio.py”, line 97, in init
self.handle = PsychPortAudio(‘Open’, device_id, mode,
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <function Stream.del at 0x000001D909532F70>
Traceback (most recent call last):
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychtoolbox\audio.py”, line 236, in del
self.close()
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychtoolbox\audio.py”, line 146, in close
raise err
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychtoolbox\audio.py”, line 139, in close
PsychPortAudio(‘Close’, self.handle)
AttributeError: ‘Stream’ object has no attribute ‘handle’
1.0203 WARNING Monitor specification not found. Creating a temporary one…
################ Experiment ended with exit code 1 [pid:27424] #################

I also tried using the code import psychopy.sound.microphone.Microphone as Microphone, by following the overview here: Microphone - for recording sound — PsychoPy v2022.2.4, however in that case I got the error message. However, I received the message
ModuleNotFoundError: No module named ‘psychopy.sound.microphone.Microphone’; ‘psychopy.sound.microphone’ is not a package
This might be because I haven’t installed psychtoolbox, but since psychtoolbox runs in MATLAB I don’t see the connection.

As an update, if I try to run the microphone demo in psychopy 2022.2.4, I get the following error message:

Hello from the pygame community. Contribute - pygame wiki
PTB-ERROR: Desired audio parameters for device 5 unsupported by audio device: Invalid sample rate
Traceback (most recent call last):
File “C:\Users\james\Documents\ZDesktop\PhD\Switching Study\psychopy demos\Feature Demos\microphone\microphone_lastrun.py”, line 125, in
mic = sound.microphone.Microphone(
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychopy\sound\microphone.py”, line 478, in init
self._stream = audio.Stream(
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychtoolbox\audio.py”, line 97, in init
self.handle = PsychPortAudio(‘Open’, device_id, mode,
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <function Stream.del at 0x000002509E0BDD30>
Traceback (most recent call last):
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychtoolbox\audio.py”, line 236, in del
self.close()
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychtoolbox\audio.py”, line 146, in close
raise err
File “C:\Program Files\PsychoPy2022\lib\site-packages\psychtoolbox\audio.py”, line 139, in close
PsychPortAudio(‘Close’, self.handle)
AttributeError: ‘Stream’ object has no attribute ‘handle’
################ Experiment ended with exit code 1 [pid:22700] #################

Hello,

it seems as if you selected sampling parameters, most likely sampling frequency, which are not supported by your device and the chosen sound-library

Best wishes Jens
.

Thanks Jens,

I read the error message before I sent it to you - I thought you might have some more information or tips. This seems like it might be a common issue since it is quite basic.

I tried all the different settings for sampling frequency but still received the same message.
My channel count is stereo, and the audio sample format is set to default.
I have no idea why the error is thrown.
I can record in MATLAB using any arbitrary sampling frequency.
I can record in e.g., audacity with no issues at all using different sampling frequencies.

I then used the code used in the microphone component manually. It is described here: Microphone - for recording sound — PsychoPy v2022.2.4) is possible, but that link contains some errors. It does not seem to require Psychtoolbox, contrary to what it says. Also, using “bufferSecs” as written in the example will throw an error. The argument is streamBufferSecs as you can see in the description of parameters.

I used the code:
mic = sound.microphone.Microphone(streamBufferSecs =10,
device=None, channels=None,
sampleRateHz=44100)

I have no idea why this works but it seems to work. The microphone component itself does not work however.

Hello, I’ve met the same problem…No idea why it always shows this type of error how I change the settings