PsychoPy currently supports a choice of two sound libraries: pyo, or pygame. Select which will be used via the audioLib preference. sound.Sound() will then refer to either SoundPyo or SoundPygame. This can be set on a per-experiment basis by importing preferences, and setting the audioLib preference to use.
It is important to use sound.Sound() in order for proper initialization of the relevant sound library. Do not use sound.SoundPyo or sound.SoundPygame directly. Because they offer slightly different features, the differences between pyo and pygame sounds are described here. Pygame sound is more thoroughly tested, whereas pyo offers lower latency and more features.
Create a sound object, from one of MANY ways.
By default, a Hamming window (5ms duration) will be applied to a generated tone, so that onset and offset are smoother (to avoid clicking). To disable the Hamming window, set hamming=False.
stereo: True (= default, two channels left and right), False (one channel)
bits: has no effect for the pyo backend
Return the duration of the sound
Returns the current requested loops value for the sound (int)
Returns the current volume of the sound (0.0 to 1.0, inclusive)
Starts playing the sound on an available channel.
For playing a sound file, you cannot specify the start and stop times when playing the sound, only when creating the sound initially.
Playing a sound runs in a separate thread i.e. your code won’t wait for the sound to finish before continuing. To pause while playing, you need to use a psychopy.core.wait(mySound.getDuration()). If you call play() while something is already playing the sounds will be played over each other.
Sets the current requested extra loops (int)
Sets the current volume of the sound (0.0 to 1.0, inclusive)
Stops the sound immediately
Create a sound object, from one of many ways.
Parameters: |
secs: duration (only relevant if the value is a note name or a frequency value)
sampleRate(=44100): If a sound has already been created or if the bits(=16): Pygame uses the same bit depth for all sounds once initialised |
---|
fades out the sound (when playing) over mSecs. Don’t know why you would do this in psychophysics but it’s easy and fun to include as a possibility :)
Get’s the duration of the current sound in secs
Returns the current volume of the sound (0.0:1.0)
Starts playing the sound on an available channel.
If no sound channels are available, it will not play and return None. This runs off a separate thread i.e. your code won’t wait for the sound to finish before continuing. You need to use a psychopy.core.wait() command if you want things to pause. If you call play() whiles something is already playing the sounds will be played over each other.
Sets the current volume of the sound (0.0:1.0)
Stops the sound immediately