Hi!
I tried an auto‑probe on a working output device/rate (sounddevice). The idea is to try every output device with 48k/44.1k and pick the first valid one, then play a beep sound. I make a new file probe_and_play_sd.py
and run it in PsychoPy Coder:
#==========================
from psychopy import prefs
prefs.hardware[‘audioLib’] = [‘sounddevice’] # force SD backend before importing sound
import sounddevice as sd
from psychopy import sound, core
#Candidate sample rates to try
CANDIDATE_RATES = [48000, 44100]
#List devices
print(“\n=== PortAudio devices ===”)
devs = sd.query_devices()
for i, d in enumerate(devs):
print(f"{i:2d} | {d[‘name’]} | host={sd.query_hostapis()[d[‘hostapi’]][‘name’]} "
f"| outCh={d[‘max_output_channels’]}")
#Find a device+rate that passes sd.check_output_settings
good = None
for i, d in enumerate(devs):
if d[‘max_output_channels’] <= 0:
continue
for rate in CANDIDATE_RATES:
try:
sd.check_output_settings(device=i, samplerate=rate, channels=2)
good = (i, rate)
break
except Exception as e:
print(f"skip dev {i} @ {rate} Hz: {e}")
pass
if good:
break
if not good:
raise RuntimeError("No output device worked with 44.1/48 kHz, 2ch. "
“Try changing Windows device settings or unplug/replug USB.”)
OUT_INDEX, RATE = good
print(f"\n>>> Using device index {OUT_INDEX} at {RATE} Hz")
#Lock defaults at PortAudio layer
sd.default.device = (None, OUT_INDEX) # input=None, output=OUT_INDEX
sd.default.samplerate = RATE
sd.default.channels = 2
#Now try a PsychoPy tone
beep = sound.Sound(1000, secs=0.5, sampleRate=RATE, stereo=True)
beep.setVolume(0.4)
beep.play()
core.wait(0.7)
print(“Played beep OK.”)
#==========================
I got this output and a sounding beep:
=== PortAudio devices ===
0 | Microsoft Sound Mapper - Input | host=MME | outCh=0
1 | Microphone (Realtek(R) Audio) | host=MME | outCh=0
2 | Microsoft Sound Mapper - Output | host=MME | outCh=2
3 | Speakers/Headphones (Realtek(R) | host=MME | outCh=8
4 | Primary Sound Capture Driver | host=Windows DirectSound | outCh=0
5 | Microphone (Realtek(R) Audio) | host=Windows DirectSound | outCh=0
6 | Primary Sound Driver | host=Windows DirectSound | outCh=2
7 | Speakers/Headphones (Realtek(R) Audio) | host=Windows DirectSound | outCh=8
8 | Speakers/Headphones (Realtek(R) Audio) | host=Windows WASAPI | outCh=2
9 | Microphone (Realtek(R) Audio) | host=Windows WASAPI | outCh=0
10 | Speakers 1 (Realtek HD Audio output with SST) | host=Windows WDM-KS | outCh=2
11 | Speakers 2 (Realtek HD Audio output with SST) | host=Windows WDM-KS | outCh=8
12 | PC Speaker (Realtek HD Audio output with SST) | host=Windows WDM-KS | outCh=0
13 | Stereo Mix (Realtek HD Audio Stereo input) | host=Windows WDM-KS | outCh=0
14 | Microphone 1 (Realtek HD Audio Mic input with SST) | host=Windows WDM-KS | outCh=0
15 | Microphone 2 (Realtek HD Audio Mic input with SST) | host=Windows WDM-KS | outCh=0
16 | Microphone 3 (Realtek HD Audio Mic input with SST) | host=Windows WDM-KS | outCh=0
Using device index 2 at 48000 Hz
Played beep OK.
2.3823 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘sounddevice’] (in that order).
################ Experiment ended with exit code 0 [pid:11172] #################”
Since I got a sound, I also tried the output ‘Speakers/Headphones (Realtek(R) Audio) ‘ with index 8 by changing ‘OUT_INDEX’ to number 8 in the line
‘sd.default.device = (None, 8)’
and it worked as well. Hope it helps.