psychopy.org | Reference | Downloads | Github

How to use Microphone component?

Hi, thank you for reading my post. I’m a beginner in Psychopy. I would be very grateful if you could offer a solution to my question :cry:

OS : Mac OS 10.14.6
PsychoPy version : 2021.2.3
Standard Standalone? (y/n) : yes
**What are you trying to achieve?: I’m compiling an experiment in which the participant sees a picture first and describes it. I would like to record the participant’s verbal response by the built-in microphone. The participant will start the recording by pressing ‘r’ on the keybord and stop it by pressing ‘s’. I’m trying to achieve this in the Builder.

**What did you try to make it work?: I added the Microphone component in the trial and wrote “if event.getKeys([‘r’]):
mic.start()”
if event.getKeys([‘s’]):
mic.stop()" in Each Frame in the Code component. The experiment could run at some times. However, the file of the recording output is empty or has no sound. I have consulted the Documentation on the official website which says “You need to switch on the microphone before use, which can take several seconds.” I don’t know whether the dysfunction of the Microphone component is due to this or not.


Sorry for my poor English if this description makes you confused :cry: And also sorry for my ignorance in Psychopy. :cry:

Hi There,

I think you want 2 routines here. The first will have a basic keyboard component (where “allowed keys” is “r”) and some text reading " press r to start recording" the second will just need a microphone component and a keyboard component to stop the recording.

For an example how to use this, open builder view, go to “demos” (top task bar) > unpack demos then return to demos > feature demos> microphone

Hope this helps,
Becca

Thank you very much for your suggestion~ I tried to run the microphone demo, but the output file was still empty. Also, I noticed that this demo experiment couldn’t run completely on my computer, which means that it only showed one tongue twister and then ended suddenly. Maybe there is something wrong with my computer :cry:

when it doesn’t run - is there an error message?

It goes like this:

Running: /Users/helene/Desktop/psychopy demo/Feature Demos/microphone/microphone_lastrun.py

PTB-INFO: Using modified PortAudio V19.6.0-devel, revision unknown
||PaMacCore (AUHAL)|| Error on line 406: err=’’!dat’’, msg=Audio Device: Unsupported Format
||PaMacCore (AUHAL)|| Error on line 406: err=’’!dat’’, msg=Audio Device: Unsupported Format
PTB-INFO: New audio device 0 with handle 0 opened as PortAudio stream:
PTB-INFO: For 2 channels Capture: Audio subsystem is Core Audio, Audio device name is Built-in Microphone
PTB-INFO: Real samplerate 16000.000000 Hz. Input latency 9.000000 msecs, Output latency 0.000000 msecs.
0.8275 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 [‘sounddevice’, ‘PTB’, ‘pyo’, ‘pygame’] (in that order).
7.1402 WARNING User requested fullscreen with size [1024 768], but screen is actually [1280, 800]. Using actual size
2021-09-03 16:01:00.173 python[18133:10130649] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Alert 4615: Chosen transcriber ‘google’ requires an API key, please supply one in Preferences.
For more info see https://docs.psychopy.org/alerts/4615.htmlTraceback (most recent call last):
File “/Users/helene/Desktop/psychopy demo/Feature Demos/microphone/microphone_lastrun.py”, line 282, in
language=‘en-US’, expectedWords=None
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/sound/microphone.py”, line 931, in bank
engine=engine, **kwargs)
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/sound/audioclip.py”, line 758, in transcribe
config=config)
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/sound/transcribe.py”, line 351, in transcribe
config=config)
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/sound/transcribe.py”, line 589, in recognizeGoogle
'No application key specified for Google Cloud Services, ’
psychopy.sound.exceptions.RecognizerAPICredentialsError: No application key specified for Google Cloud Services, specify the path to the key file with either the system environment variable GOOGLE_APPLICATION_CREDENTIALS or in preferences (General → appKeyGoogleCloud).

Experiment ended.

Aha ok that looks like it is trying to use google transcription and you haven’t yet set up an API key - do you need transcription in your experiment? if not them you can turn it off and that should avoid the error.

Thanks,
Becca

Thank you very much! Now the demo could run normally, but the outputs of recordings still have problems. :cry: The recording still has no sound.
Thanks,
Helen

hmm ok that could be a mic issue - can you record with your mic in other software? (e.g. audacity?)

Thanks!
Becca

I just wanted to edit my reply. To supplement my previous reply, I tried with and without microphone (on my headphone) on psychopy, and the result is what I have mentioned. Based on your suggestion, I tried my mic in the voice memo on Mac, it worked well. So I wonder if it is because psychopy doesn’t have access to my mic :cry:

Psychopy is not on the list in the Security and Privacy Setting (> Preference) on my Mac.
Thanks,
Helen