psychopy.org | Reference | Downloads | Github

Audio file loop is not working


#1

OS : Win10
PsychoPy version: 3.0.0

Hello everyone,
I am relatively knew to working with Psychopy and I have encountered the following problem when trying to programme my experiment:
I want to create a loop using various audio files (.wav). I have put the file names of my audio files into an excel file and named the column “audio”. Then I’ve entered the variable name “$audio” into the sound field of the sound component and clicked the option “set every repeat”.
However, if I want to start the experiment, I get the following error:

Running: C:\Users\Public\Documents\audio_test\audio_test_4_lastrun.py

Traceback (most recent call last):
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py”, line 349, in setSound
blockSize=self.blockSize)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py”, line 90, in getStream
blockSize=blockSize)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py”, line 129, in _getStream
.format(label, list(self.keys())[0], sys.platform)
psychopy.exceptions.SoundFormatError: Tried to create audio stream 22050_2_128 but 44100_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\Public\Documents\audio_test\audio_test_4_lastrun.py”, line 112, in
sound_1.setSound(audio)
File “C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py”, line 357, in setSound
raise SoundFormatError(err)
psychopy.exceptions.SoundFormatError: Tried to create audio stream 22050_2_128 but 44100_2_128 already exists and win32 doesn’t support multiple portaudio streams

Does anyone know how I can fix this problem? I’d be really grateful if someone could help me with this!
Thanks, Sabrina


#2

The problem here is that your audio files have different “sample rates”. At least 1 is running at 22050 samples per second and at least one is at 44100. On windows that’s not supported. You’ll need to use some audio converter to get them both to the same sample rate.


#3

Thanks very much for your advice, but I don’t really understand how that’s possible.

I just wanted to try out whether the loop works or not, so I just used the exact same audio file, by copying the original and naming them “Audio01” and “Audio02”. So, I don’t understand how there can be a different sample rate if it is the same file.


#4

There are no other sounds in the experiment?


#5

Yes, there will be 20 different audio files, but they haven’t all been recorded yet. So just for practice reasons (so I understand how the loop thing works in general) I just used one audio file to try it out. But unfortunately, I have encountered the above problem.


#6
  • Just to reiterate Jon’s question, are there any other sounds of any sort in the experiment (eg even a pure tone beep, which doesn’t need a sound file)?
  • What sound-related lines occur in your .py script prior to line 112?
  • Lastly, what happens if you use software like Audacity to resample your current single file to 44100 Hz?

#7

I have changed the rate to 44100 Hz in the audio file with Audacity and now it works. Thanks a lot! :slight_smile: