Loop with sound files

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): macOS Catalina, version 10.15.7
PsychoPy version (e.g. 1.84.x): 2020.2.4

Hi everyone! I am new to PsychoPy but really struggle with making it work.

I wish to make an experiment in which the participants will have to identify voices. The participants will first have to go through a “training phase”, in which they will be presented with 8 audio files of different people speaking one at a time. Each audiofile is 30s long and placed in a subfolder called “stimuli” in the same directory as my experiment. The audiofiles are .wav format. I have made an excel sheet in which the top of the column says “Trainfile”, and each cell below this includes a unique path to the audiofiles I wish to include in the loop (an example is the following: stimuli/audiotrain1female.wav).

What are you trying to achieve?:
What I am struggling with is how to include these audiofiles in a loop (in a random order). After one audioclip has played, there should be a text saying “Press any key to hear the next voice”. The participant should then press a key and the next audiofile should start playing. This is the structure that I have made so far.

What did you try to make it work?:
I tried to add the excel file in the trainloop. Don’t know if I did something wrong?

image

What specifically went wrong when you tried that?:

I get this error message:

Running: /Users/emma/OneDrive - Aarhus Universitet/1. Semester/CogCom/CogCom Exam/Demo/builderdemo_lastrun.py

2.0851 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).
2020-12-04 07:12:17.790 python[96835:1530843] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Traceback (most recent call last):
File “/Users/emma/OneDrive - Aarhus Universitet/1. Semester/CogCom/CogCom Exam/Demo/builderdemo_lastrun.py”, line 277, in
sound_1.setSound(‘Trainfile’, hamming=False)
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/sound/backend_sounddevice.py”, line 361, in setSound
_SoundBase.setSound(self, value, secs, octave, hamming, log)
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.6/psychopy/sound/_base.py”, line 193, in setSound
raise ValueError(msg + value)
ValueError: setSound: could not find a sound file named Trainfile

Experiment ended.

Hello Emma,

try $Trainfile as a sound instead of Trainfile. The column Trainfile in your Excel-file should contain the names of the sound-files you intend to play.

Best Jens

Hi Jens,

Thank you a lot for your time and reply.

Would that mean that PsychoPy would know to look in Excel-files in the same directory to find a column with the name “Trainfile”. I haven’t included the path to the Excel-file anywhere, so I am just wondering how PsychoPy knows where to find the Excel file in the first place.

Hello Emma,

PsychoPy knows where to look for the file because you specified the path when adding it as a condition file. In the Excel-file you have to specify the path and names to your soundfiles, e.g. stim/sound1.mp3, stim/sound2.mp3 aso when you soundfiles are in the folder stim. The path is relative to the experiment. If your experiment is in the folder emma, then your soundfile folder should be emma/stim.

Best Jens