Playing audio files works on mac, but not on windows 10

OS (e.g. Win10): Windows 10
PsychoPy version (e.g. 1.84.x): 2022.2.4
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: I have an experiment file that requires sound files. It’s a version of an experiment that I’ve run successfully on my personal and office Macs (and on pavlovia, in previous iterations), but is NOT running on my lab computers. It doesn’t seem to be able to load sound files, but I’m not exactly sure how to read the error messages.

What did you try to make it work?: changing the order of the sound drivers in psychopy preferences (ptb is what the experiment calls for and it’s in the list) and seeing the preferences in the other experiments that DO work on the lab computers (everything seems to be the same?)

What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.

207.8668     INFO     Loaded monitor calibration from ['2019_10_01 07:46']
Generating PsychoPy script...

Alert 4405: Editable textbox component textbox and keyboard component key_resp_2 in the same routine may compete for keypresses
For more info see https://docs.psychopy.org/alerts/4405.htmlAlert 4405: Editable textbox component patResp and keyboard component endpatResp in the same routine may compete for keypresses
For more info see https://docs.psychopy.org/alerts/4405.htmlAlert 4405: Editable textbox component testResp and keyboard component key_resp_5 in the same routine may compete for keypresses
For more info see https://docs.psychopy.org/alerts/4405.html####### Running: C:\Users\SPPLab\Desktop\Shiloh_Sleep\NoSleep_lastrun.py #######
519.4837     INFO     Loaded monitor calibration from ['2019_10_01 07:46']
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate 
Traceback (most recent call last):
PTB-ERROR: Seems the requested audio sample rate 22050.000000 Hz is not supported by this combo of hardware and sound driver.
Error in function Open:     Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio('Open' [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate 
PTB-ERROR: Seems the requested audio sample rate 22050.000000 Hz is not supported by this combo of hardware and sound driver.
Error in function Open:     Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio('Open' [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
9.3409     WARNING     User requested fullscreen with size [2560 1440], but screen is actually [1920, 1080]. Using actual size
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 226, in __init__
    audio.Stream.__init__(self, device_id=deviceID, mode=mode+8,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 97, in __init__
    self.handle = PsychPortAudio('Open', device_id, mode,
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\SPPLab\Desktop\Shiloh_Sleep\NoSleep_lastrun.py", line 110, in <module>
    test_sound = sound.Sound('ALL_059_M_ENG_ENG_HT1.wav', secs=-1, stereo=True, hamming=True,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 331, in __init__
    self.setSound(value, secs=self.secs, octave=self.octave,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 426, in setSound
    _SoundBase.setSound(self, value, secs, octave, hamming, log)
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\_base.py", line 200, in setSound
    self._setSndFromFile(p)
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 459, in _setSndFromFile
    self._setSndFromArray(sndArr)
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 498, in _setSndFromArray
    self.track = audio.Slave(self.stream.handle, data=self.sndArr,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 578, in stream
    label, s = streams.getStream(sampleRate=self.sampleRate,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 139, in getStream
    return self._getStream(sampleRate,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 186, in _getStream
    self[label] = _MasterStream(sampleRate, channels, blockSize,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 247, in __init__
    audio.Stream.__init__(self, mode=mode+8,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 97, in __init__
    self.handle = PsychPortAudio('Open', device_id, mode,
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <function Stream.__del__ at 0x0000025D3B229820>
0.8795     WARNING     Monitor specification not found. Creating a temporary one...
Traceback (most recent call last):
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 236, in __del__
    self.close()
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 146, in close
    raise err
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 139, in close
    PsychPortAudio('Close', self.handle)
AttributeError: '_MasterStream' object has no attribute 'handle'
################# Experiment ended with exit code 1 [pid:5220] #################
534.0666     INFO     Loaded monitor calibration from ['2019_10_01 07:46']

22050 Hz is a non-standard sampling rate. Many sound cards will not support it.

Try up-sampling the audio to 44100 Hz (This is the most common sampling rate)

Sox is some free software that will do the job

https://sox.sourceforge.net/

https://sox.sourceforge.net/SoX/Resampling

Hope this work for you.

Nope, not working yet. I’ve resampled all of my sound files to 44.1kHz, and I’m still seeing a message in the error readout about “the requested sampling rate of 22050Hz…” as a PTB error.

8.8113     INFO     Loaded monitor calibration from ['2019_10_01 07:46']
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate 
Traceback (most recent call last):
PTB-ERROR: Seems the requested audio sample rate 22050.000000 Hz is not supported by this combo of hardware and sound driver.
Error in function Open:     Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio('Open' [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate 
PTB-ERROR: Seems the requested audio sample rate 22050.000000 Hz is not supported by this combo of hardware and sound driver.
Error in function Open:     Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio('Open' [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
7.6878     WARNING     User requested fullscreen with size [2560 1440], but screen is actually [1920, 1080]. Using actual size
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 226, in __init__
    audio.Stream.__init__(self, device_id=deviceID, mode=mode+8,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 97, in __init__
    self.handle = PsychPortAudio('Open', device_id, mode,
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\SPPLab\Desktop\Shiloh_Sleep\NoSleep_lastrun.py", line 110, in <module>
    test_sound = sound.Sound('ALL_059_M_ENG_ENG_HT1.wav', secs=-1, stereo=True, hamming=True,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 331, in __init__
    self.setSound(value, secs=self.secs, octave=self.octave,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 426, in setSound
    _SoundBase.setSound(self, value, secs, octave, hamming, log)
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\_base.py", line 200, in setSound
    self._setSndFromFile(p)
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 459, in _setSndFromFile
    self._setSndFromArray(sndArr)
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 498, in _setSndFromArray
    self.track = audio.Slave(self.stream.handle, data=self.sndArr,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 578, in stream
    label, s = streams.getStream(sampleRate=self.sampleRate,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 139, in getStream
    return self._getStream(sampleRate,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 186, in _getStream
    self[label] = _MasterStream(sampleRate, channels, blockSize,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 247, in __init__
    audio.Stream.__init__(self, mode=mode+8,
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 97, in __init__
    self.handle = PsychPortAudio('Open', device_id, mode,
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <function Stream.__del__ at 0x0000021B1C3489D0>
Traceback (most recent call last):
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 236, in __del__
    self.close()
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 146, in close
    raise err
  File "C:\Users\SPPLab\AppData\Local\Programs\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 139, in close
    PsychPortAudio('Close', self.handle)
AttributeError: '_MasterStream' object has no attribute 'handle'
################# Experiment ended with exit code 1 [pid:7216] #################
21.4084     INFO     Loaded monitor calibration from ['2019_10_01 07:46']

looking a little closer it look like your code is trying to open the sound card with a frequency of 22050.

pahandle = PsychPortAudio(‘Open’ [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);

the freq value need to be set to 44100.

You might also try changing your audio preference. Change latency and/or select a different driver. It would be useful to know if this is a PortAudio issue.

  1. Right, where can I change the freq value? I’m using builder; I’ve checked in the experiment preferences and in psychopy’s preferences and can’t find anything immediately looking like it will help.

  2. The latency and driver are both working for another psychopy experiment running on the same computer, so it seems like it’s an issue with this experiment specifically (and I’d rather not “fix” global settings for psychopy that would cause problems for the other people in my lab whose experiments are running fine). Or am I misunderstanding?

For some reason your code is trying to open a sound device for 22050 Hz, which is not supported by your system.

I thought the obvious answer was that you have sound files at this sampling rate. But you say all your sources are now at 44100 so I am at a loss for why the audio system want to use this frequency.

Note! You can always revert any changes to the audio preferences. But changing the preferences (just for a run or two) to see if it fixes your problem is a useful troubleshooting tool.

Okay, so I was actually able to fix it by altering the preferences like you suggested and got it to play both the 22050 sound files and the 44100 sound files.

  • I added sounddevice to the allowed sound libraries in the global psychopy settings, and put it at the top of the list
  • I added coreaudio and portaudio to the audio drivers in the global psychopy settings (not deleting anything, just in case it was important for my labmates!), and ordered them at the top of the list
  • In the experiment settings, I changed the latency from “3: aggressive low-latency” to “2: exclusive low-latency”
  • Also in the experiment settings, I changed the requested sound library from ptb to sounddevice

After doing all that, it was able to play the 22050Hz sound files and the 44100Hz files as well.

Could you help me understand these steps better?
-where can I find the “global psychopy settings”?

Hello

go to FilePreferencesHardware

Best wishes Jens