A word about pyo (audio backend)

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.

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!

Best,
Maya

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 (psychopy.microphone - Capture and analyze sound — PsychoPy v2023.2.3) 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!

~Mara

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.

Hi there, I am new to Psychopy and python coding. I am using Psychopy3 for a psychology EEG study. It is a language comprehension study where I am presenting the subjects with word pairs in a prime-target fashion (i.e. dog-cat, you-card, mom-dad) and so on. I get no error message when I run the experiment. However, some words are not fully heard. They are abruptly cut in the middle/before they end. The experiment runs fully and with no stops. It is just that some words are cut randomly, but then it proceeds fine to the next word. I noticed that those words are usually the longer ones for some reason (i.e. inexpensive, migraine etc.). My supervisor and I tried different things regarding that matter but it stills seems to be a problem. My trial loop is random so sometimes the words being cut are not the same as before. Do you reckon this is because of a bug in the programme which can be solved easily? Is there something I can do about it (would it help downloading the recent version of pyo or downgrading the psychopy?)

Thanks in advance for any help

Hi Cleopetra,
I was wondering if you were able to resolve this issue. I am designing a similar task and I keep getting the same error about closing audio backend. In study, it is a picture naming task where participants are presented with pictures that they have to name. The program seems to be working fine but I am really not sure how to solve this error.

Hello,

I’d advise everyone with such audio issues to upgrade to the latest version of PsychoPy (> 3.2). Version 3.2 introduced a new PTB audio backend that was ported from the PsychToolbox project. It is much more reliable than the variety of other third party backends that we have had to rely upon before.

Hi Michael,

Thanks very much for responding. I am actually using 3.2.1 after receiving an email about the latest release. Maybe it has to do with the Hardware settings ? I am attaching a screenshot of my settings.

Hi Oliver,

I am trying to get pro to play in Windows with ASIO card and I installed pyo and ASIO on the machine but then when I ran the test script that you recommend:
“”"
Windows audio host inspector.

This script will check if pyo can run in duplex mode (both audio input and output)
and will test every host API to help the user in making his audio device choice.

“”"
import sys, time
from pyo import *

if sys.platform == “win32”:
host_apis = [“mme”, “directsound”, “asio”, “wasapi”, “wdm-ks”]
else:
print(“This program must be used on a windows system! Ciao!”)
exit()

print("* Checking for any available audio input… *")

input_names, input_indexes = pa_get_input_devices()

print("* Checking audio output hosts… *")

s = Server(duplex=0)
s.verbosity = 0

host_results = []
for host in host_apis:
print("* Testing %s… *" % host)
try:
s.reinit(buffersize=1024, duplex=0, winhost=host)
s.boot().start()
a = Sine(freq=440, mul=0.2).out()
time.sleep(2)
s.stop()
s.shutdown()
host_results.append(True)
except:
host_results.append(False)

print("\nResults")
print("-------\n")

if len(input_names):
print(“Duplex mode OK!”)
print(“Initialize the Server with duplex=1 as argument.\n”)
else:
print(“No input available. Duplex mode should be turned off.”)
print(“Initialize the Server with duplex=0 as argument.\n”)

for i, host in enumerate(host_apis):
if host_results[i]:
print(“Host: %s ==> OK!” % host)
else:
print(“Host: %s ==> Failed…” % host)

print(“Initialize the Server with the desired host given to winhost argument.”)

print("\nFinished!")

I get the error message stating that the “pa_get_input_devices()” is not defined. What does it mean? and what do I do next? I am quite new to Python and psychoPy so any detailed help you can provide will be appreciated.

Thanks,
Ana

Hi,

How did you install pyo? And how do you run the python script? If the line

from pyo import *

does not give an error, then pa_get_input_devices() should exist…

Olivier

Sorry, I missed your reply @Roaa. It looks like you manually need to insert 'PTB', at the start of list of audio libraries in your hardware settings.

Michael, thanks very much! I now have only ‘pyo’ and ‘sounddevice’ libraries in my hardware settings and everything is working. I still get an error message though but all of my data are and files are saved securely.
I just have one related question please. In my experiment, I want to mark the presentation of every visual stimulus with a beep sound. For that, I have created high frequency beeps that I will play with each picture.
The problem is : that beep sound never gets recorded, although I hear it when I run the experiment, and I can see that is being presented.