sounds¶
Classes to play sounds.
Each sound inherits a base type depending on prefs.AUDIOSERVER
prefs.AUDIOSERVER == ‘jack’ :
Jack_Sound
prefs.AUDIOSERVER == ‘pyo’ :
Pyo_Sound
To avoid unnecessary dependencies, Jack_Sound is not defined if AUDIOSERVER is ‘pyo’ and vice versa.
Todo
Implement sound level and filter calibration
Classes:
|
The Humble Sine Wave |
|
White Noise |
|
A .wav file. |
|
Speech subclass of File sound. |
|
A silent sound that does not pad its final chunk – used for creating precise silent gaps in a continuous noise. |
Data:
Sounds must be added to this SOUND_LIST so they can be indexed by the string keys used elsewhere. |
|
These parameters should be given string columns rather than float columns. |
Functions:
|
Convert 16 or 32 bit integer audio to 32 bit float. |
-
class
Tone
(frequency, duration, amplitude=0.01, **kwargs)[source]¶ Bases:
object
The Humble Sine Wave
- Parameters
frequency (float) – frequency of sin in Hz
duration (float) – duration of the sin in ms
amplitude (float) – amplitude of the sound as a proportion of 1.
**kwargs – extraneous parameters that might come along with instantiating us
Attributes:
Methods:
Create a sine wave table using pyo or numpy, depending on the server type.
-
PARAMS
= ['frequency', 'duration', 'amplitude']¶
-
type
= 'Tone'¶
-
class
Noise
(duration, amplitude=0.01, **kwargs)[source]¶ Bases:
object
White Noise
- Parameters
duration (float) – duration of the noise
amplitude (float) – amplitude of the sound as a proportion of 1.
**kwargs – extraneous parameters that might come along with instantiating us
Attributes:
Methods:
Create a table of Noise using pyo or numpy, depending on the server_type
-
PARAMS
= ['duration', 'amplitude']¶
-
type
= 'Noise'¶
-
class
File
(path, amplitude=0.01, **kwargs)[source]¶ Bases:
object
A .wav file.
Todo
Generalize this to other audio types if needed.
- Parameters
path (str) – Path to a .wav file relative to the prefs.SOUNDDIR
amplitude (float) – amplitude of the sound as a proportion of 1.
**kwargs – extraneous parameters that might come along with instantiating us
Attributes:
Methods:
Load the wavfile with
scipy.io.wavfile
, converting int to float as needed.-
PARAMS
= ['path', 'amplitude']¶
-
type
= 'File'¶
-
init_sound
()[source]¶ Load the wavfile with
scipy.io.wavfile
, converting int to float as needed.Create a sound table, resampling sound if needed.
-
class
Speech
(path, speaker, consonant, vowel, token, amplitude=0.05, **kwargs)[source]¶ Bases:
autopilot.stim.sound.sounds.File
Speech subclass of File sound.
Example of custom sound class - PARAMS are changed, but nothing else.
- Parameters
speaker (str) – Which Speaker recorded this speech token?
consonant (str) – Which consonant is in this speech token?
vowel (str) – Which vowel is in this speech token?
token (int) – Which token is this for a given combination of speaker, consonant, and vowel
Attributes:
-
type
= 'Speech'¶
-
PARAMS
= ['path', 'amplitude', 'speaker', 'consonant', 'vowel', 'token']¶
-
class
Gap
(duration, **kwargs)[source]¶ Bases:
object
A silent sound that does not pad its final chunk – used for creating precise silent gaps in a continuous noise.
- Parameters
duration (float) – duration of gap in ms
- Variables
gap_zero (bool) – True if duration is zero, effectively do nothing on play.
Attributes:
Methods:
Create and chunk an array of zeros according to
Gap.duration
chunk
([pad])If gap is not duration == 0, call parent
chunk
.buffer
()play
()-
type
= 'Gap'¶
-
PARAMS
= ['duration']¶
-
SOUND_LIST
= {'File': <class 'autopilot.stim.sound.sounds.File'>, 'Gap': <class 'autopilot.stim.sound.sounds.Gap'>, 'Noise': <class 'autopilot.stim.sound.sounds.Noise'>, 'Speech': <class 'autopilot.stim.sound.sounds.Speech'>, 'Tone': <class 'autopilot.stim.sound.sounds.Tone'>, 'speech': <class 'autopilot.stim.sound.sounds.Speech'>}¶ Sounds must be added to this SOUND_LIST so they can be indexed by the string keys used elsewhere.
-
STRING_PARAMS
= ['path', 'speaker', 'consonant', 'vowel', 'type']¶ These parameters should be given string columns rather than float columns.
Bother Jonny to do this better.
v0.3 will be all about doing parameters better.
-
int_to_float
(audio)[source]¶ Convert 16 or 32 bit integer audio to 32 bit float.
- Parameters
audio (
numpy.ndarray
) – a numpy array of audio- Returns
Audio that has been rescaled and converted to a 32 bit float.
- Return type