PsychoPy is amazing, but sometimes, it doesn’t want to play nice. Here is an example where I first output a sound with PsychoPy (PTB backend) and then I output a second sound with
sounddevice directly. For some reason, this is hanging the interpreter.
sounddevice is unable to output a sound after psychopy.
from psychopy import prefs prefs.hardware["audioLib"] = ["PTB", "sounddevice", "pyo", "pygame"] prefs.hardware["audioLatencyMode"] = "0" from psychopy.clock import wait from psychopy.sound import Sound sound = Sound(value=1000, volume=1, secs=0.2, hamming=False) sound.play() wait(0.5) import numpy as np import sounddevice as sd fs = 44100 times = np.linspace(0, 1, fs, endpoint=True) signal = np.sin(2 * np.pi * 440 * times) sd.play(signal, samplerate=fs, mapping=[1, 2], blocking=False)
I understand that mixing backends is uncommon, and mixing psychopy with
sounddevice directly is even more uncommon, but it’s still problematic, e.g. for unit test which will start by running test functions which use
psychopy and then other test functions which use