| Reference | Downloads | Github

Import audio sound - wav file

I would like to build an experiment, where

  • first comes a sound (wav.file on my laptop, windows 10),
  • second the patient have to sign up, when he/she recognised the sound.

I created a sound stimuli, however I don’t know, how psychopy gets my wav.files. Do I have to do an import? How can I connect psychopy and my wav.files?

Thank you very much.
Anna from Germany

1 Like

Hi @Anna_Germany, it would be useful to know what version of PsychoPy you are using, and what you have achieved so far. To link your wave files to your sound component, put the filenames in a conditions spreadsheet, and load the conditions file into your loop. You can put your sound files in the same directory as your experiment and just use the filename in the excel file e.g., myWavFile.wav, or you can put all your sound files into a subdirectory and reference the file location in your excel file e.g., mySubDirectory/myWavFile.wav.

The column name in the conditions file that holds your wav filenames will be your variable name that defines your sound in the Sound field of the sound component - note, remember to switch updates to “set every repeat” - so a new sound is used on every trial.

BTW, I would recommend Psychopy 3 because there are some issues found looping through wav files in 1.90.3, which can be easily rectified, but require changes to your Python experiment code.

Dear David,

thank you very much for your mail.
I am using PsychoPy 3 as recommended. And I did all the steps, that you described. After that, my expirement now runs partially, but not completely:
There are 60 wav files that should be presented in the experiment. But after presenting two of this 60 wav files, the experiment stops, showing me this:

I don’t know what to do now. Please help me again.

Thank you very much!

Hi @Anna_Germany, would you be able to provide a minimum working example of your experiment so I can reproduce the error?

experiment_v2.psyexp (8.9 KB)
MAV_randomisiert angeordnet_V2.xlsx (9.7 KB)

Hi David,
yes, of course. Here is the experiment and the xslx.
In the experiment, the patient should hear all the 60 wav files, (everyone for one time). After every sound, the patient should raise up and choose from a list, which category the sound is. For this reaction, the patient should have 10 seconds. Then I would like to do response the category via keyboard-response.

Thank you for your support!

PS. In the excel file: the letters of “corrAns” are the categorys, which are possible.

Thanks. I have ran the experiment, with some changes. You will need to keep the ‘participant’ field in the experiment info fields in Experiment Settings. This field is used to create your filename and will throw a name error if it is not defined.

As for the looping of sounds. I used a simple .wav file and looped for a duration of 10 seconds, and had no problems. Is it possible one of your sound files are causing the problem? As you are playing sounds sequentially, and the error is always raised after the second trial, then perhaps there is a problem with the 3rd (or second) wav file in the list. If you could inspect the sound files and let me know, that would be helpful.

Hi Anna,
using PsychoPy 1.90.2, I have the same error you posted above when I use loops with wave files:

From cffi callback <function callback_ptr at 0x1E913370>:
Traceback (most recent call last):
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\”, line 1008, in callback_ptr
return _wrap_callback(callback, data, frames, time, status)
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\”, line 2773, in _wrap_callback
File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\sound\”, line 199, in callback
ValueError: list.remove(x): x not in list

I could fix it with the following steps (source 1 source 2):

  1. Get admin rights
  2. Open C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\sound\
  3. Go to line 199
  4. Remove “.sounds” from self.sounds.remove(thisSound)

Since it involves changing PsychoPy files, use it with caution. :wink:


Hi David,

thank you for trying my experiment.
In the last days I’ve tried to integrate all your tips in my experiment several times and I checked all the wav.files. I can’t recognize a problem with the wav.files. But actually my psychopy experiment doesn’t work and now the sounds stops after playing the first wav.file. Could you please have another check at my experiment, please? Thank you very much!
Maybe do you have an psychopy-expert in Germany which could help me face-to-face? I am an speech and language therapist and doingt things like set up an experiment via psychopy is really difficult for me.MAV_Vortest_randomisiert angeordnet.xlsx (8.8 KB)
psychopy_Vortest.psyexp (5.7 KB)

Hi Torge,

thanks a lot for your answer!
I tried to remove “.sounds”, but then the whole psychopy doesn’t work any longer.
As you explained, it involves changing psychopy, maybe my work was not 100% correct, so I have to delete psychopy completely and started a new download now.

Best regards, Anna

Hi Anna,
I’m sorry to hear that changing the self.sounds.remove(thisSound) line didn’t work for you. Are you sure it was self.remove(thisSound) afterwards? If you want to revert it, you don’t have to delete or reinstall PsychoPy - just changing that line back should be enough for it to work again if you haven’t changed anything else.

Hi @Anna_Germany, yes it appears to crash because your keyboard component has an infinite duration, and does not end the routine on a button press. You could either set the keyboard component to end the trial on a button press using the “Force end of Routine” option, or give your keyboard a duration equal to your sound duration, or whatever you require. Also, to help, when debugging your experiment, unselect full screen mode in Experiment Settings, so you can close the window manually using the big red cross in Builder, if things go wrong.

Hi David,
as you recommended, I did all the things you told me.
Now, it’s the same problem as last week, the experiment starts and works well until a few sounds and than stops with the same error

Torge, you told me how to change the script (remove “.sounds” …)
In the first step, you told me to get admin rights. how is it possible to get admin rights? Now, I can remove “.sounds”, but it is not possible to save it, because I’ve got NO admin rights. Could you help me?

Thank you very much!

Hi Anna,
ok, if you haven’t changed the file before, your earlier problems can’t be related to that, and the steps I mentioned might still help.
You need admin (administrator) rights in order to change the program files on your computer. It’s a safety measure that protects important files. Do the following:

  1. Open the Windows start menu
  2. Type “editor”
  3. Right-click on “Editor” and choose “Als Administrator ausführen” (open as admin)
  4. Type in your administrator password (if you don’t know it, ask the responsible person)
  5. Press Crtl+O and navigate to C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\sound\
  6. Choose “Alle Dateien” (all files) at the bottom right (where it says “Textdateien” (text files))
  7. Open
  8. Press Ctrl+F and search for “self.sounds.remove(thisSound)”
  9. Remove “.sounds” right there
  10. Save the file (it should now be possible)
  11. Enjoy (hopefully)

Dear Torge,

thank you very much for your detailed answer! Now it was possible to delete “.sounds”, but in the experiment there is still the same problem.
In your screenshot I can see german words and so let me ask politely: Are you from Germany? My psychopy experiment doesn’t work right now and I am very sad, because I would like to use it for my masterthesis. By now I am in despair. I am uncertain and I don’t want to be impolite but I don’t know another way instead of asking you: Maybe could you help me with my experiment face to face please? I think it’s really for a good cause (the research topic is: facial paralysis after stroke).

Thank you a lot.

Hi Anna,
I’m sorry to hear that the problem persists and I understand your frustration considering your thesis. We’ve all been there trying to make our first steps with new software. I’m not an expert myself and could only respond to your question because I had exactly the same problem and the workaround I described fixed it for me. I hoped it would help you, too. However, something else seems to be wrong in your case. Trying to fix it face-to-face wouldn’t help much (besides, Aachen and Münster aren’t that close :upside_down_face:), but I can offer to take another look at your experiment on my computer where I solved the issue. So could you upload your most recent version, including the PSYEXP, XLSX and WAV files, in a zip file?

Hi Torge,

thank you so much for checking my experiment - I’m very happy!
Ich erlaube mir, in Deutsch weiter zu schreiben, da mein Englisch nicht perfekt ist und ich eine Sprachbarriere jetzt gerne ausschließen würde. Vielen herzlichen Dank, dass Sie sich mein Experiment ansehen!
Ich möchte einen Test konstruieren, bei dem der Proband nacheinander verschiedene Geräusche hört. Die Geräusche sind unterschiedlich lang (zwischen Millisekunden bis ca. 3 Sekunden). Die Geräusche soll anschließend vom Probanden einer von 6 Kategorien zugeordnet werden. Der Proband nennt also nach dem Hören eine der 6 Kategorien und ich möchte seine Antwort mit einem Buchstaben (a, e, f, t, z, ü) als “response” in PsychoPy eingeben. Der Proband hat 10 Sekunden Zeit, um zu antworten. Nach max. 10 Sekunden kommt das nächste Geräusch. Die Geräusche sollen nicht randomisiert, sondern in der zuvor festgelegten Reihenfolge (s. Exceltabelle) dargeboten werden.
Insgesamt möchte ich zwei identische Experimente erstellen, wobei beim ersten Experiment (Vortest) 10 Geräusche angeboten werden, beim zweiten Experiment sind es 60 Geräusche. Der Ablauf und die Antwortenmöglichkeiten sind komplett identisch. Daher sende ich Ihnen anbei den von mir konstruierten “Vortest”.
Als Output würde ich gerne wissen, ob die jeweilige Antwort des Patienten richtig war, wie lange er dafür gebraucht hat und falls die Antwort falsch war, welche er statt dessen gewählt hat.

psychopy_Vortest.psyexp (5.7 KB)
MAV_Vortest_randomisiert angeordnet.xlsx (8.8 KB)

I’m sorry, I can’t upload the wav files, there is an error:
“Sorry, the file you are trying to upload is not authorized (authorized extensions: jpg, jpeg, png, gif, ico, icns, py, psyexp, csv, xlsx).”

Lieber Torge, vielen Dank, dass sie mir helfen möchten. Ich hoffe sehr, dass Sie den Fehler entdecken können! :slight_smile:

I’m sorry, I can’t upload the wav files, there is an error:
“Sorry, the file you are trying to upload is not authorized (authorized extensions: jpg, jpeg, png, gif, ico, icns, py, psyexp, csv, xlsx).”

Hi Anna,
please upload the experiment and wave files somewhere else (Dropbox, Sciebo, you name it…) and provide us with a public link. Otherwise, we can’t test it or would have to change the experiment. It would be best to zip them into one file so that the folder structure remains.

PS: If any admin reads this, would it be possible to allow wave uploads in the forum? It would be very helpful in such situations. :slight_smile:

I’ve added .wav as an authorised extension for attachments.

1 Like