A word about pyo (audio backend)

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

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:


Happy coding!

Olivier Bélanger


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


Hi Olivier,

Do you have any advice on this issue?

Thank you,


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:


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!


Dear Olivier,

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


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,

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!


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.


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?

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:

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?

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!

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


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

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.

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.

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.

Hi Olivier,

I’m relatively new to PsychoPy and python coding, and have limited experience with audio backend. I was wondering if you had an advice on this issue? I’m randomly getting an error message stating “portmidi closed”. It’s described in more detail here:

I copied the code for the voice key component from the word_naming demo. The code called for the voice key at the beginning of the experiment is:

# The import and pyo_init should always come early on:
import psychopy.voicekey as vk
vk.pyo_init(rate=44100, buffersize=32)

# What signaler class to use? Here just the demo signaler:
from psychopy.voicekey.demo_vks import DemoVoiceKeySignal as Signaler

# To use a LabJack as a signaling device:
#from voicekey.signal.labjack_vks import LabJackU3VoiceKeySignal as Signaler

My settings look like this:

Any assistance or advice would be greatly appreciated as this problem is leading to much frustration and data loss.

Thank you!


Hi Mara,

“Portmidi closed” is not an error message but only a warning. It only means that there is no MIDI interface connected to the system at the moment the audio server is booted. Totally harmless…

I notice two things in your setup:

  1. A buffersize of 32 samples is unlikely to work well under windows, I think you should increase it to somthing like 128 or 256.

  2. In your preferences, sounddevice comes before pyo… Are you sure pyo is always used in your experiment? I tough that psychopy try the audio backend in the order given in the list.

Thanks for your response. I understand that “portmidi closed” is a warning, but whenever it pops up, the voice key stops recording at some point during the experiment. Therefore, something is going wrong… I’ll play around with the other settings you noted and see if that stops this annoying problem from occurring.