Audio Playback Problem

OS: Win7 (64 bit)
PsychoPy version: PsychoPy3 2020.2.5
Standard Standalone?**: Yes

Hi everyone,

I am experiencing some problem with audio playback in PsychoPy Builder. I want participants to speak into their microphone and play it back to check if their device is working. I’m hopeless at coding so I just copied and pasted the codes from a relevant PsychoPy demo called ‘word naming’:

Begin Experiment:

The import and pyo_init should always come early on:

import psychopy.voicekey as vk
vk.pyo_init(rate=44100, buffersize=32)

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 the routine where participants speak into their microphone I wrote the following:
Under the Begin Routine tab:

Create a voice-key to be used:

vpvk = vk.OnsetVoiceKey(
sec=2,
file_out=‘data/trial_’+str(trials.thisN).zfill(3)+’_’+word+’.wav’)

Start it recording (and detecting):

vpvk.start() # non-blocking; don’t block when using Builder

In the playback routine I wrote the following:
Under the Begin Routine tab:

Create another instance to use for play-back:

vpvk2 = vk.OnsetVoiceKey(
file_in=vpvk.filename) # the input file; here is output of the prior trial

vpvk2.start() # non-blocking

Under the End Routine tab:
thisExp.addData(‘vocal_RT’, round(vpvk2.event_onset, 3))
thisExp.addData(‘filename’, vpvk.filename)

only needed if no other event will make this happen:

thisExp.nextEntry() # otherwise data is not saved

However, when I ran the experiment, the following error messages came up:

Portaudio error in Pa_AbortStream (pa_stop): Unanticipated host error
Portaudio error in Pa_CloseStream (pa_deinit): PortAudio not initialized
Portaudio error in Pa_Terminate (pa_deinit): PortAudio not initialized
Pyo error: Error closing audio backend.
Traceback (most recent call last):
File “C:\Users\Administrator\Desktop\Life at KCL\Stimuli\Experiment II\ExpII_lastrun.py”, line 304, in
file_out=‘data/trial_’+str(trials.thisN).zfill(3)+’_’+word+’.wav’)
NameError: name ‘trials’ is not defined

Could anyone kindly tell me what to do? Many thanks in advance!

Xinyan

trials refers to the name of your loop. If you routine isn’t in a loop called trials then trials.thisN will fail.

Thank you so much for the reply! I changed the name of the loop and it worked! Sorry I just didn’t know what the code referred to. Thanks a lot!

hey! did you also solve the “Portaudio error in Pa_AbortStream (pa_stop): Unanticipated host error” ? I’m struggling to get past this, despite calling pyo_init()