psychopy.org | Reference | Downloads | Github

A word about pyo (audio backend)

sound

#1

Hi everyone,

It’s my first post here so let me introduce myself to you. I’m the author of pyo,
one of the many possible audio back-ends of PsychoPy. I spent a lot of time in
the past few weeks to fix bugs related to conflicts between portaudio and the
python Global Interpreter Lock and concerning the choice of audio driver on
Windows (I’m an old mac user and mostly on linux today). Even on Windows, the
latency with pyo is now very low (~ 5ms for a buffer size of 256 samples).

I’m writing this post to let you know that almost every problem I saw about pyo
on this forum is likely to be fixed now (version 0.8.5). Pyo is not only a
"sound driver" but a complete dsp toolbox and there is a lot of working examples
in the sources. If you had some frustrations in the past with pyo, I recommend
you to give it another shot, it’s a much more mature module now.

Now that I’m registered on this forum, I will be here to help with audio related
problems.

You can download the most recent version of pyo on ajaxsoundstudio.com:

Github is used to maintain the sources and track the bugs:

The online documentation:

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

Happy coding!

Olivier Bélanger


#2

Hi Olivier, thanks very much for the update and for making the effort to keep us informed.

Cheers.


#3

Hi Olivier,

Do you have any advice on this issue?

Thank you,
Fintan


Partial success getting PYO to work: help needed!
#4

Hi,

First of all, on Windows, you must choose the good host (asio, wasapi (default as of 0.8.7), mme, etc.) and, if needed the good device ( Server.setOutputDevice(device_index) ). There is a script in the pyo documentation to test the audio setup on your system:

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

Then, if you’re using wasapi, be sure there is both an output AND an input configured on your system (it’s not always the case on Windows). Otherwise, you boot the Server in output only by setting the duplex argument to 0. Sampling rate of pyo must also match the sampling rate of the system (System’s sr is often 48000 while pyo’s default is 44100).

Now, in your code, you should always call Server.stop() when you’re done so that pyo can properly release the audio driver. Maybe that’s the problem described in that post. If a process didn’t release the driver, subsequent attempts will probably fail.

Hope that help!

Olivier


Bugfixes for "Unable to share contexts" and "Portaudio not initialized"
#5

Dear Olivier,

Thank you very much for the advice - that sounds very promising - I will have a go tomorrow.

Cheers,
Fintan


#6

PYO now works on my system, see here:

Thanks for your advice.

I have a follow-up question: in your experience, are ASIO and wasapi likely to differ in their sound playback (of simple WAV files) in either a) volume or b) latency?

I am wondering whether I should validate identical playback between our machine using ASIO and our machine using wasapi.

Thank you,
Fintan


#7

ASIO is probably a little better than wasapi regarding latency (if tout have an ASIO driver you should prefer it ). Quality will be the same, really!

Olivier


#8

Hello Oliver @belangeo

I am new to psychopy and am using PsychoPy2 Experiment Builder (v1.90.1) to create a miniature natural language learning experiment. I am not using python. My experiment includes listen and repeat along with production trials and thus I need to utilize the microphone component in psychopy.

When I use the microphone component, my experiment crashes and I receive the following error:

 File "/Users/mayarose/Dropbox/MAYA Turkish Project/TurkishExperiments/TestRunFolder/TestTestTest2_MR.py", line 371, in <module>
    VoiceRespB1_mic = microphone.AdvAudioCapture(name='VoiceRespB1_mic', saveDir=wavDirName, stereo=True)
  File "/Applications/PsychoPy2_PY3.app/Contents/Resources/lib/python3.6/psychopy/microphone.py", line 381, in __init__
    buffering=buffering, chnl=chnl, stereo=stereo)
  File "/Applications/PsychoPy2_PY3.app/Contents/Resources/lib/python3.6/psychopy/microphone.py", line 170, in __init__
    raise AttributeError('pyo server not created')
AttributeError: pyo server not created

I understand I need to download pyo from the link you provided above. As I am using the builder that comes with Python 3, I did not download Python separately. Do I need to download python separately to create the Pyo server?

I appreciate your support and hope you understand that I am new to python.

Best,
Maya


#9

Hi,
I don’t think you need to install pyo separately, I’m pretty sure that it is bundled with psychopy.
You got the “pyo server not created” error much likely because you asked something your system was not able to do at this moment. You try to start a server in duplex mode (duplex=1), does the system has at least one input configured? How many audio channels are you trying to use?


#10

Okay the fact that pyo is bundled with psychopy makes sense.

At this point, I am simply trying to create a draft of my experiment using my macbook pro’s built-in internal microphone which Omnidirectional, and which I believe is just one audio channel (mono).

I do not know what you mean by starting the server in duplex mode. Would you be able to explain a bit more what you mean by that?

If it helps, I set the mic component to start at 1 sec and have a stop duration time of 15 sec. I specified the stop duration as some of the other components in psychopy (sound) do not work unless you specify a stop-duration.

Lastly, this is what my preferences look like:


#11

update: i read some of the related comments and changed some things around in the preferences. Now it looks like this and it seems to be working:

This is very exciting. Any ideas as to why these minor changes (putting ‘pyo’ first in the audio library list’ enabled the mic component to work?


#12

Oh, I see, you were not using pyo but sounddevice library as the audio backend. AFAICT Psychopy try audio backends in the order of the given list, so now you’re using pyo. I can’t tell what was happening with sounddevice but I’m glad it is working now!


#13

Great! You may hear from me in the near future concerning pyo and the microphone component. Thanks again!

Best,
Maya


#14

Hello everyone,

I am a PhD student from Germany who is trying to figure out the working of Psychopy. Unfortunately, I do not have any previous experience with programming. My question is whether it is possible to create a spoken word recognition experiment in Psychopy and measure the reaction time of the participants?
On the official website of Psychopy they introduce three different packages that work with audio files: pygame, pyo and sounddevice.
Could you please tell which software is more appropriate for the experiment mentioned above.

Thank you for help in advance.

Best regards


#15

Hey, I haven’t done experiments with spoken words but you should look into using psychopy.microphone (http://www.psychopy.org/api/microphone.html?highlight=microphone) which lets you record voice, and I think it uses ‘pyo’ audio library.


#16

Thank you very much for your answer. Now, I am struggling with another issue: I cannot open the xlsx file. It simply does not recognise it.
Do you have an idea why?

Thanks for your response in advance.


#17

Do you have any error code that shows up? Also, I think you should make that into a new post because this one is about audio library stuff.