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.
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.
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.
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.
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?
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.
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!
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 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?
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
“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:
A buffersize of 32 samples is unlikely to work well under windows, I think you should increase it to somthing like 128 or 256.
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.