Recording vocal RT using the microphone routine in Builder

Hi, I think I’ve arrived at the solution so I wanted to share it in case it helps.

After reviewing the demo word_naming program, I decided to use psychopy.voicekey to collect RT instead of psychopy.microphone. I was able to collect vocal RT after adding the following code components, which were pulled from the word_naming demo. (Note: this code includes the annotations from the demo, as well as some of my own).

Here is the URL for the word_naming demo if you need it: https://github.com/psychopy/psychopy/tree/master/psychopy/demos/builder/word_naming

In routine at beginning of experiment:

Begin Experiment

# The import and pyo_init should always come early on:
import psychopy.voicekey as vk
vk.pyo_init(rate=44100, buffersize=256)

# What signaler class to use? Here just the demo signaler:
 from psychopy.voicekey.demo_vks import DemoVoiceKeySignal as Signaler
# To use a LabJack as a signaling device:
#from voicekey.signal.labjack_vks import LabJackU3VoiceKeySignal as Signaler

In routine where RT is collected

Begin Routine


# Create a voice-key to be used. Change "trials" to reflect name of loop.
 vpvk = vk.OnsetVoiceKey(
     sec=2, 
     file_out='data/trial_'+str(trials.thisN).zfill(3)+'_'+'.wav')
 
 # Start it recording (and detecting). Change targetScreen to reflect name of routine:
 vpvk.start()  # non-blocking; don't block when using Builder
 vpvk.tStart=targetScreenClock.getTime()

End Routine

 # The recorded sound is saved upon .stop() by default. But
 # its a good idea to call .stop() explicitly, eg, if there's much slippage:
 
 vpvk.stop()
 
 # Add the detected time into the PsychoPy data file:
 #vocal RT
 thisexp.addData('vocal_RT', round(vpvk.event_onset, 3))
 #not sure what this is for
 thisexp.addData('bad_baseline', vpvk.bad_baseline)
 #name of .wav file that will be outputted (sound recording)
 thisexp.addData('filename', vpvk.filename)
 #time when the recording began
 thisexp.addData('recordOnset', vpvk.tStart)

2 Likes