This has been reported before but it turns out to be much weirder than it looks: Error: non-broadcastable output during sound exp
Basically, I have a PyHab experiment (my add-on for PsychoPy). On windows, the first time I run it, it plays all the audio fine. Subsequent runs produce the following error with sounddevice, which appears as a pop-up message but does not crash the experiment (but no sound will play):
From cffi callback <function _StreamBase.__init__.<locals>.callback_ptr at 0x0000021E1D8E77B8>:
Traceback (most recent call last):
File "C:\Program Files\PsychoPy3\lib\site-packages\sounddevice.py", line 740, in callback_ptr
return _wrap_callback(callback, data, frames, time, status)
File "C:\Program Files\PsychoPy3\lib\site-packages\sounddevice.py", line 2516, in _wrap_callback
callback(*args)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_sounddevice.py", line 208, in callback
toSpk[:len(dat), :] += dat # add to out stream
ValueError: non-broadcastable output operand with shape (128,1) doesn't match the broadcast shape (128,2)
If I use PTB instead, it does crash outright, when it loads (before it attempts to play) with a similar error:
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\contrib\lazy_import.py", line 120, in __call__
return obj(*args, **kwargs)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\movie3.py", line 135, in __init__
self.loadMovie(self.filename)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\movie3.py", line 197, in loadMovie
sampleRate=self._mov.audio.fps)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 334, in __init__
hamming=self.hamming)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 413, in setSound
_SoundBase.setSound(self, value, secs, octave, hamming, log)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\_base.py", line 198, in setSound
self._setSndFromArray(numpy.array(value))
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py", line 486, in _setSndFromArray
volume=self.volume)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychtoolbox\audio.py", line 300, in __init__
self.fill_buffer(data)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychtoolbox\audio.py", line 242, in fill_buffer
self.buffer = Buffer(stream=self, data=data)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychtoolbox\audio.py", line 260, in __init__
data)
Exception: Number of columns of audio data matrix doesn't match number of output channels of selected audio device.
The truly perplexing thing is that it works once and then throws this error, but even deleting pycache doesnât fix it, and deleting the app config files only fixes it once. It canât be modifying the files themselves, so I have not the faintest clue whatâs causing it to suddenly and irreparably fail.
Notably, it specifically seems to happen in cases when I load more than one movie or audio file, even though I am only attempting to play one file at a time, so itâs possible this is a memory allocation issue but that would be even weirder. Basically if I take one of the movie files that produces this error and run it in MovieStim, it works fine every time.
@jon @dvbridges or @michael, any suggestions? Iâve tried different sound libraries, different sound drivers, pretty much every audio setting I can think of, making sure the audio files are both mono and stereo, etc. Again, the file works in other contexts, but the nature of this error is utterly mystifying to me.