Routine won't start with PTB audio selected

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 2020.2.1
Standard Standalone? (y/n) If not then what?: Yes
What are you trying to achieve?:

I am running an experiment which uses the movie component. Videos are played that have their own audio, but the audio and video don’t sync up properly, which is important for my experiment. I was also getting a warning advising me to use PTB instead of sounddevice, which I thought might be the cause of the syncing issue, but when I switched to PTB the routine featuring the movie component now won’t run. Instead I get a grey screen and the loading wheel, and I have to force close the window to get out (‘Not Responding’).

What did you try to make it work?:

In Preferences I changed the order of audio library to [‘PTB’, ‘sounddevice’, ‘pyo’, ‘pygame’]. In Experiment Settings in the Audio tab I have ‘3: Aggressive low latency’ selected and ‘Use preferences’ for Audio library. I have also tried changing the Audio library here to ‘PTB’ which didn’t help.

What specifically went wrong when you tried that?:

Here is the error I get in the Experiment Runner:

Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 582, in stream
    blockSize=self.blockSize)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 143, in getStream
    blockSize=blockSize)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 183, in _getStream
    .format(label, list(self.keys())[0], sys.platform)
psychopy.exceptions.SoundFormatError: Tried to create audio stream 44100_2_128 but 48000_2_128 already exists and win32 doesn't support multiple portaudio streams

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\movie3.py", line 189, in loadMovie
    sampleRate=self._mov.audio.fps)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 334, in __init__
    hamming=self.hamming)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 428, in setSound
    _SoundBase.setSound(self, value, secs, octave, hamming, log)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\_base.py", line 198, in setSound
    self._setSndFromArray(numpy.array(value))
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 500, in _setSndFromArray
    self.track = audio.Slave(self.stream.handle, data=self.sndArr,
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 590, in stream
    raise SoundFormatError(err)
psychopy.exceptions.SoundFormatError: Tried to create audio stream 44100_2_128 but 48000_2_128 already exists and win32 doesn't support multiple portaudio streams

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 582, in stream
    blockSize=self.blockSize)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 143, in getStream
    blockSize=blockSize)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 183, in _getStream
    .format(label, list(self.keys())[0], sys.platform)
psychopy.exceptions.SoundFormatError: Tried to create audio stream 44100_2_128 but 48000_2_128 already exists and win32 doesn't support multiple portaudio streams

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\g34890cw\Documents\PsychoPy\StudentCompExp\StudentExperiment_shortVideos_lastrun.py", line 764, in <module>
    depth=-1.0,
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\contrib\lazy_import.py", line 120, in __call__
    return obj(*args, **kwargs)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\movie3.py", line 140, in __init__
    self.loadMovie(self.filename)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\movie3.py", line 198, in loadMovie
    sampleRate=self._mov.audio.fps)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 334, in __init__
    hamming=self.hamming)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 428, in setSound
    _SoundBase.setSound(self, value, secs, octave, hamming, log)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\_base.py", line 198, in setSound
    self._setSndFromArray(numpy.array(value))
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 500, in _setSndFromArray
    self.track = audio.Slave(self.stream.handle, data=self.sndArr,
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 590, in stream
    raise SoundFormatError(err)
psychopy.exceptions.SoundFormatError: ##### Experiment ended. #####

In case it helps, here is the error message I received once I force closed the experiment window:

  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\runner\runner.py", line 277, in onClose
    self.onQuit()
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\runner\runner.py", line 285, in onQuit
    self.panel.stopTask()
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\runner\runner.py", line 545, in stopTask
    self.stopFile(event)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\runner\scriptProcess.py", line 109, in stopFile
    self.onProcessEnded()
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\runner\runner.py", line 514, in onProcessEnded
    ScriptProcess.onProcessEnded(self)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\runner\scriptProcess.py", line 140, in onProcessEnded
    self.app.runner.stdOut.write(buff)
AttributeError: 'NoneType' object has no attribute 'stdOut'

I need a way to ensure my videos sync with their audio, and if the way to do this is to use the PTB audio library, I need to know how to do this without the experiment crashing!

In case it’s relevant, below is my flow. The experiment crashes (grey screen that doesn’t respond) when trying to start the ‘AOMI’ routine:
image

Here are the routine details:

Here is the info I have for the movie component:

The videos I am uploading are 38MB .MOV files.

Any help hugely appreciated!

Hello,

You seem to use files with different sampling frequency. See also here.

You might want to try to load your videos in a trial period in which nothing else happens, insert an ISI-component and load the video then during this ISI (set during …ISI). Audio- and video-loading might take quite some time.

Best wishes Jens

Hi @JensBoelte ,

Thanks so much for your reply. I have changed all of my videos so they are all 44100 sampling rate, which didn’t seem to help.

I have tried adding in a static component as you suggest. My routine now looks like the below, with the static component timed to match a static fixation cross:

The static component looks like this:
image

I have changed my movie component to ‘set during:AOMI.videoLoading’ as below:

But I am still having the exact same issue and error messages! I have also tried making the duration of the static component and fixation longer (10 secs) to no avail. Have I implemented this correctly, or is there anything else I can try?

Also, my videos need to change every trial (every iteration of the loop ‘trials_2’), so if this component is no longer set to ‘set every repeat’ will the videos still update on every trial?

Thanks for your help so far.

Hello,

does your experiment run with another sound-library? Do you experience the audio lag when playing the video with vlc or some other video program? Did you try a different movie backend? H.264 encoded MP4 with AAC audio encoding are best when you plan running the experiment on-line.

Best wishes Jens

Hi @JensBoelte ,

Thanks for the advice, as I do plan to run this online eventually! I don’t get any audio lag when the video plays in vlc or other media players. I haven’t tried a different sound library or movie backend yet. I’ve found that changing the audio library back to sounddevice but keeping the audio latency as 3. Aggressive low latency, seems to have fixed the lag and the routine actually runs, so I’m going to work with that for now.

Many thanks!

Hello,

Ok, I wish you success. The audio latency setting has an effect only for the PTB-library psychopy.sound - play various forms of sound — PsychoPy v2021.1

Best wishes Jens