Package psychopy :: Module sound :: Class SoundPyglet
[frames] | no frames]

Class SoundPyglet

source code


Create a sound object, from one of MANY ways.
Instance Methods
 
__init__(self, value='C', secs=0.5, octave=4, sampleRate=44100, bits=16)
value: can be a number, string or an array.
source code
 
play(self, fromStart=True)
Starts playing the sound on an available channel.
source code
 
stop(self)
Stops the sound immediately
source code
 
getDuration(self) source code
 
getVolume(self)
Returns the current volume of the sound (0.0:1.0)
source code
 
setVolume(self, newVol)
Sets the current volume of the sound (0.0:1.0)
source code

Inherited from _SoundBase: setSound

Method Details

__init__(self, value='C', secs=0.5, octave=4, sampleRate=44100, bits=16)
(Constructor)

source code 

value: can be a number, string or an array.

If it's a number between 37 and 32767 then a tone will be generated at that frequency in Hz. ----------------------------- It could be a string for a note ('A','Bfl','B','C','Csh'...) - you may want to specify which octave as well ----------------------------- Or a string could represent a filename in the current location, or mediaLocation, or a full path combo ----------------------------- Or by giving an Nx2 numpy array of floats (-1:1) you can specify the sound yourself as a waveform
secs: is only relevant if the value is a note name or
a frequency value
octave: is only relevant if the value is a note name.
Middle octave of a piano is 4. Most computers won't output sounds in the bottom octave (1) and the top octave (8) is generally painful
sampleRate(=44100): only used for sounds using pyglet. Pygame uses one rate for all sounds
sample rate for all sounds (once initialised)
bits(=16): Only 8- and 16-bits supported so far.
Only used for sounds using pyglet. Pygame uses the same sample rate for all sounds (once initialised)
Parameters:
  • value, can, be, a, number, string, or, an, array, -
    • If it's a number between 37 and 32767 then a tone will be generated at that frequency in Hz.

    • It could be a string for a note ('A','Bfl','B','C','Csh'...). Then you may want to specify which octave as well

    • Or a string could represent a filename in the current location, or mediaLocation, or a full path combo

    • Or by giving an Nx2 numpy array of floats (-1:1) you can specify the sound yourself as a waveform

  • secs, is, only, relevant, if, the, value, is, a, note, name, or - a frequency value
  • octave, is, only, relevant, if, the, value, is, a, note, name. - Middle octave of a piano is 4. Most computers won't output sounds in the bottom octave (1) and the top octave (8) is generally painful
  • sampleRate(=44100), only, used, for, sounds, using, pyglet., Pygame, uses, one, rate, for, all, sounds - sample rate for all sounds (once initialised)
  • bits(=16), Only, 8-, and, 16-bits, supported, so, far. - Only used for sounds using pyglet. Pygame uses the same sample rate for all sounds (once initialised)
Overrides: _SoundBase.__init__

play(self, fromStart=True)

source code 

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.

Overrides: _SoundBase.play

stop(self)

source code 
Stops the sound immediately
Overrides: _SoundBase.stop

getDuration(self)

source code 
Overrides: _SoundBase.getDuration

getVolume(self)

source code 
Returns the current volume of the sound (0.0:1.0)
Overrides: _SoundBase.getVolume

setVolume(self, newVol)

source code 
Sets the current volume of the sound (0.0:1.0)
Overrides: _SoundBase.setVolume