psychopy.org | Reference | Downloads | Github

Audio stimuli changed in pitch?

OS : Mac, Mojave (10.14.6)
PsychoPy version : 2020.1.2

Hello all, I have an experiment on builder that reads in some sound files to present as stimuli. This has been working well for the past few weeks, but today I ran it and the pitch of the stimuli was increased by a little over an octave. I am guessing it is doing some kind of time compression or getting the wrong sampling frequency, but I’m not sure why.

I checked the original files, and they are still playing normally. Then, I fiddled with the sound engines (as hinted here). I found that setting the preferences to sound device instead of PTB reverses the problem; however, psychopy generates a warning strongly recommending PTB.

Should I continue ahead with the local sound device, even if I eventually upload to Pavlovia? Millisecond timing is not super crucial for this experiment.

Did you change anything in the meantime - install a new version of Psychopy or change the sound files?
If the behaviour is due to the sound library mistaking your sampling rate, you could edit your sound as suggested in the post you quote:

If you’re planning on running your experiment online, your choice of the offline Python sound library is irrelevant as far as I know. But if the sampling rate is to blame, you may still want to check, because you might get the same problem when running online with the PsychoJS counterpart of the sound libraries of Psychopy.

@LukasPsy I didn’t change the PsychoPy version or the files themselves, but I think my computer may have installed some updates; perhaps it is that.
For now, I’d rather not tamper with the sound files… I guess I will find out what happens when I go online.

@aisa2 I understand your caution, but you wouldn’t have to change the original files. You could modify a copy of the original. Your results would help others with the same problem, who stumble over your question here. You could also upload one (small) sound file, which produces the effect you describe on your system to make your problem reproducible.

In any case, let us know whether the problem persists when you debug online. :slight_smile:

@LukasPsy I could see how uploading one could be useful for others to play with. Here’s one:

However, I don’t think changing the sampling rates of the original files will help for now, as it is really changing between the libraries in psychopy that reproduces the error. The files always play fine when I access them individually outside of psychopy. It’s less a question of caution and more a question of saving time for now. But I will definitely update when things go online!

1 Like

I couldn’t replicate the effect with the following script and Psychopy 2020.1.3 standalone on Windows:

from psychopy import prefs, logging
prefs.hardware['audioLib'] = ['ptb']

logging.console.setLevel(logging.DEBUG)  # get messages about the sound lib as it loads

from psychopy import sound, core

print('Using %s (with %s) for sounds' % (sound.audioLib, sound.audioDriver))

goose_sound = sound.Sound('goose_sound.wav')
goose_sound.play() # play the sound

core.wait(2)
print('done')

core.quit()

I tried to find out whether the file was compressed, but I don’t think it is.

I also have the same issue of sounds not playing right with PTB. It does sound like a speed issue, with pitch rise and also some clipping distortion. (The sampling rate of my audio is the pretty standard 44.1 kHz.)

Sounddevice plays correctly, but trims all clips to the same length, which isn’t desirable. Pyo is missing, for reasons unknown, and pygame crashes psychopy. So it’s a rather inconvenient situation. (Setting the clips during ISI doesn’t help either.)

Running newly re-installed 3.2.4 on macOS 10.14.6. Didn’t work on 2020.1.3 either.

Update on this: despite not working on python locally, audio does seems to play correctly online. Though NOT if it’s set during an ISI – then the audio doesn’t play, but instead you get a nice 0 dBFS tone in your earbuds. :thinking: So keep your volume low when experimenting!

But yeah, this doesn’t solve the original PTB distortion issue. It would be nice if that was solved, if it’s going to be The Soundlibrary from now on in PsychoPy.

Hi all,
same issue here.
I am using v2020 1.3 on Win10 machine.

With the PTB library the sounds plays fine on line bu not locally.
Specifically I have one channel sounds (left and right) high and low pitch (800 and 400hz). The one that get distorted is the 400HZ left channel.

Did you guys manage to solve this?

Thanks

I don’t think your choice of library affects online sound production. I’d recommend trying the other libraries to see which one works best for you locally.