How to change AudioDevice in Hardware preferences?

Hi! We just bought new external soundcard (Focusright Scarlett Solo) to reduce latencies. PsychoPy never allowed to choose Focusrite Usb Audio as audio device, no matter which audio library was chosen (sound device / pyo). My selection always reset to Realtek Digital Output, which is internal sound card, after clicking on “OK”/ “Apply”. Could someone help us, please?

Hi!
Did you find a solution for this?
I’m working in coder and trying to figure out how to tell psychopy ptb backend to use the focusrite rather than the built in soundcard.

Thanks!

I managed to change audio device in code.

First I got the name of the device by using
from psychopy.sound import backend_ptb as ptb
ptb.getDevices(kind=‘output’)

Then I added the following to my code
perfs.hardware[‘audioLib’] = ‘ptb’
perfs.hardware[‘audioLatencyMode’] = 3
perfs.hardware[‘audioDevice’] = ‘Scarlett Solo USB: Audio (hw:1,0)’

(The last setting comes from the list of devices).

For some reason choosing Scarlett does not work unless I explicitly set the latency mode beforehand.

Did you ever find a solution to this using builder? I’m experiencing the same issue with a different sound card in Pyschopy v2023.2.3.

My temporary solution for this is using the sounddevice library and rolling back to v2022.2.5.

I think the cause of this is the preferences dialog being unable to find the specified audio device so returning to the default value - in 2024.1.0 we’re adding the ability for the :sound: Sound Component to point to a specific speaker which should hopefully solve this.

1 Like


We are running Psychopy verison 2024.1.4 and we’re still having issues with sound not coming from the headphones, even though we have clearly specified it in the Preferences. Is there a workaround this? Thanks!

What device is set in the :sound: Sound Component itself though?

We just changed this to how it looks in the picture but it didn’t seem to have fixed it.

I have a similar problem.

I have a Samsung Odyssey G40B monitor with a headphone jack. Using Control Panel > Sound, I can choose whether to output sounds via the monitor or directly from the PC speaker. But PsychoPy (v2024.1.5) will only output sounds via the monitor. I am trying to minimise the audio latency and am concerned that transmission of the signal between the PC and the monitor (HDMI connection) might increase latency (please tell me if it will not).

I can select my PC speakers as the ‘audioDevice’, but PsychoPy still plays sound through the monitor:

I can get PsychoPy to list the available speakers and both the monitor and the PC speakers come up, so it’s not that PsychoPy can’t find the PC speakers:

from psychopy.sound import backend_ptb as ptb
print(ptb.getDevices(kind=‘output’))
{
'Odyssey G40B (NVIDIA High Definition Audio)': {'DeviceIndex': 3.0, 'HostAudioAPIId': 13.0, 'HostAudioAPIName': 'Windows WASAPI', 'DeviceName': 'Odyssey G40B (NVIDIA High Definition Audio)', 'NrInputChannels': 0.0, 'NrOutputChannels': 2.0, 'LowInputLatency': 0.0, 'HighInputLatency': 0.0, 'LowOutputLatency': 0.003, 'HighOutputLatency': 0.01, 'DefaultSampleRate': 48000.0, 'id': 0}, 
'Speakers (Realtek(R) Audio)': {'DeviceIndex': 4.0, 'HostAudioAPIId': 13.0, 'HostAudioAPIName': 'Windows WASAPI', 'DeviceName': 'Speakers (Realtek(R) Audio)', 'NrInputChannels': 0.0, 'NrOutputChannels': 2.0, 'LowInputLatency': 0.0, 'HighInputLatency': 0.0, 'LowOutputLatency': 0.003, 'HighOutputLatency': 0.01, 'DefaultSampleRate': 48000.0, 'id': 1}
}

Setting the ‘audioDevice’ in Coder doesn’t work either: the simplest possible Coder program also plays sound through the monitor:

import time
from psychopy import prefs, sound
prefs.hardware['audioLib'] = ['PTB']
prefs.hardware['audioLatencyMode'] = 3
prefs.hardware['audioDevice'] = 'Speakers (Realtek(R) Audio)'
tone = sound.Sound('A', secs = 0.2)
for thisTrial in range(2):
    tone.play()
    time.sleep(1)

The last relevant fix in the PsychoPy changelog seems to be for 2024.1.0. Does anybody know of a way to make this work?

Hi! Try to change the preferences before importing sound :).

https://psychopy.org/api/preferences.html

I’m experiencing the exact same problem as Gavkhar and have no solution:
The system device is set on the headphones, when I play a sound in windows, it does come out through the headphones, but when I launch my experiment, everything come out of the laptop speaker.
Alex, I don’t understand your answer. How can you do that in the builder ?

Ps: Funfact: the behaviour I described is when I run it in windows. If I run the same experiment on my mac, the sound comes out from the device set at the system level…

Ah sorry, I was replying to the last bit related to the Coder only (I was having the same issue and I think my brain skipped the Builder part). If you run your experiment by exporting the code from the builder maybe you could tweak the code once it’s exported? I also have understood that psychopy keeps the default configuration parameters in a file in your computer; I guess you could also change that file so that Windows uses your headphones by default. Not sure where it’s located in Windows though.

Hello, did you add the code snippet in the beginning of the experiment tab?
I had the same issue, by adding the following code I printed the name of my available devices than I pasted in prefs . You have it listed in your audioDevice in the pref for hardrive, I hadn’t mine there. Interestingly, this made my headphones to be created in audioDevice pref for hardrive. Moreover, now I also have the option to select it in the soundcomponent I am using to play the stimuli in the routine. Try this:
from pprint import pprint

List all available audio devices

audio_devices = sound.getDevices(kind=‘output’)
pprint(audio_devices)
prefs.hardware[‘audioLib’] = ‘ptb’
prefs.hardware[‘audioLatencyMode’] = 3
prefs.hardware[‘audioDevice’] = ‘Headphones (2- Realtek(R) Audio)’