Problems to record audio with builder

Hello everyone,

I need to record musicians playing their instruments. Since I’m interested in their reaction time when presented with a musical score (a png file), I don’t need any sophisticated or high-resolution audio, so with my own laptop microphone is enough for my purposes.

However, although I am trying to include the basic audio recording response option in my builder, I can’t manage Psychopy to run the experiment. If I try to run it without the microphone response option, then it works well: it displays my text options and the image. But once I include the microphone without modifying anything else, it crushes. I am getting this output message:

Please, could you give me some advise on what could be happening?
Thank you very much!

Hi Alvaro, what version of psychopy are you using? I just looked at the source code and there’s no immediately obvious reason why that would be happening.

One quick fix to try is switching the sound backend (right now you’re using pyo). Go into your settings for psychopy, and try changing the sound backend to “pysound” (or pysoundcard", I can’t remember at the moment), and maybe “pygame” if that doesn’t work.

Hi Daniel,

Thank you very much for your help and sorry for the late response. I’m using version 1.85.

I’m guessing that when you say “backend” you mean the “audio library”? Sorry, I’m not very familiar with these terms. Anyway, I tried to change the “pyo” for “sounddevice”, “psysoundcard” and “pygame”. In every case it didn’t work and I got the following outcomes (I’m pasting the third image in a second reply). Could you please help me out to figure out what is going on? Many thanks!

Outcome when using “sounddevice”:

Outcome when using “pysoundcard”:

Outcome when using “pygame”:

Well it looks like pygame might not be installed on your system, it may not be worth it to go down that road. Checking the docs for sound it seems that sounddevice is not yet ready for recording.

Could you make a minimal working example and post it here?

Also, just curious, try this (I don’t know if you’ve ever worked in python so excuse the excessive detail):

  • Change the audio library back to what it was (‘pyo’ first in the list)
  • Go to the folder: C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\sound\
  • Make a backup copy of the file backend_pyo.py (copy it and name it “backup_backend_pyo.py” or something similar)
  • Open backend_pyo.py in a text editor (If it all opens on one line, install a better text editor. Sublime 2 is nice and free)
  • Find the line of that last error from your original post (it’s saying line 28.)
  • Add a line above it, that says “import sys”. Use spaces to make sure it is indented to the same level as the line below it. It should look something like this:
    import sys
    osEncoding = sys.getfilesystemencoding()

Save the file and try running again. I’m assuming it’ll still throw some type of error because something weird is going on but hopefully it’ll be more informative.

Hi Daniel,

Thank you so much for all of your help. I don’t understand when you say “could you make a minimal working example…”. Please, could you explain to me with more details what you meant?
So, I tried the instructions about changing the script. However, when I tried to save the change, I got the following message:

If you check line 28, I added there the import sys. I hope that is what you meant. Sorry, I don’t have any experience with python. I only have experience with the builder.
I tried to run again the experiment and I got again the same error message regarding line 28:

Hi Alvaro, I think the issue with saving the file is that you need to run the text editor as an administrator. I think you can just right click on Sublime and select that option (then be very careful when saving things and close the app as soon as you’re done). Then they’ll let you save the file with the extra import and we’ll see what happens.

A minimal working example is a very small example of your experiment that demonstrates the problem and nothing more. The idea is that you post whatever someone else would need so they can quickly run your experiment and focus on the technical issues without having to understand your theoretical issues, or interpret lots of information that wouldn’t make sense to someone else. For example, you can make a copy of your .psyexp, remove all unnecessary routines, make a copy of your conditions file with only a few lines, and post those two files here.

Talk to you soon.

Hi Daniel,
In your previous reply you said “change the audio library back to what it was (‘pyo’ first in the list)”. When you said that pyo is first on the list, does that means that there were other options present there? Next to my audio library I only have the ‘pyo’ option, just as you can see here:

Perhaps I deleted a second option (I believe there were two in total) the first time I modified the options next to audio library, but I can’t remember them. Do you know what should I write next to ‘pyo’?

Also, I managed to save the file as administrator. When running the experiment, I got this outcome:

Finally, here is a minimal working example. In this post you will find the two excel files from where psychopy will find the stimuli and other specifications:

stimuli.xlsx (8.0 KB)
trainingG.xlsx (8.1 KB)

Here, you will find the psychopy builder file, as well as one image used on the experiment.

forhelp.psyexp (22.6 KB)

You will need to change the image direction on the excel file.
I hope these files will help.
Thank you once again!

Hi Alvaro,

So the difficult thing is that it seems like your computer is having trouble initializing pyo, and it is very difficult for us to know why without having the computer to tinker with in our hands.

@belangeo will most likely be more helpful on looking for reasons why this could be happening.

In the meantime, I’m going to send you a message with some ways we could get sound recording for you in the short term.

Hola Daniel,

Now back to English :wink: . With the risk of being annoying, I would like to ask your help with I have a new problem going on. I decided to modified the structure of the experiment. I’m still interested in measuring the reaction time of the musicians when showed with the scores. What is new is that I have re-organized the number of blocks in my experiment.
In the version that you saw, there was only one block containing 50 stimuli. However, in the new version that I’m working on, there are 10 blocks containing 5 stimuli each. Recording works perfectly for the first block. However, when it reaches block 2, it crushes and reports this outcome:

These are the only audio files that were saved before crushing:

I created a minimal working example and run it just to see what happened and I got a similar message as before:

I’m also attaching a minimal working example of this experiment.

Here are the files of the minimal working experiment:

6higher.xlsx (8.2 KB)
5higher.xlsx (9.0 KB)
2higher.xlsx (8.2 KB)
3higher.xlsx (8.2 KB)
4higher.xlsx (8.2 KB)
simpleAudio.py (5.2 KB)
written.xlsx (8.1 KB)
trainingG.xlsx (8.0 KB)
newhelp.psyexp (54.4 KB)
newhelp_lastrun.py (104.4 KB)

I hope you have some time for helping me with this. This can’t be repaid with a beer, but a full box of them…

Thank you very much :slight_smile:

Hi,

Did you have a look at this page:

http://ajaxsoundstudio.com/pyodoc/winaudioinspect.html

There is some tips on how to configure the audio backend of pyo, especially on Windows.

Olivier

Hi,

I am experiencing the same issue as the one described by Alvaro:

Traceback (most recent call last):
File “/Users/quentinraffaelli/Desktop/Think Aloud_lastrun.py”, line 93, in
mic_1 = microphone.AdvAudioCapture(name=‘mic_1’, saveDir=wavDirName, stereo=False)
File “/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/microphone.py”, line 357, in init
self.setMarker()
File “/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/microphone.py”, line 402, in setMarker
sampleRate = sound.pyoSndServer.getSamplingRate()
AttributeError: ‘NoneType’ object has no attribute ‘getSamplingRate’

I was wondering whether a solution to this problem was found and
if so what it would be.

Thanks,
Quentin

Hi,

On Windows, pyo use the WASAPI driver by default. Altough this is the most modern one, I don’t think (naymore) it’s a good idea to use it as the default. The reason is that the system config and pyo must absolutely be on the same page (input available, number of channels, sampling rate, etc.). If psychopy allows you to change the audio config in its preferences, you should try to change the host api to “directsound” or the input/output devices to “Primary Sound Driver”, that should be enough to make it work.

I will change pyo’s default driver on Windows before the next release…

Olivier