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

File(path[, amplitude])

A .wav file.

Gap(duration, **kwargs)

A silent sound that does not pad its final chunk – used for creating precise silent gaps in a continuous noise.

Noise(duration[, amplitude])

White Noise

Speech(path, speaker, consonant, vowel, token)

Speech subclass of File sound.

Tone(frequency, duration[, amplitude])

The Humble Sine Wave

Data

SOUND_LIST

Sounds must be added to this SOUND_LIST so they can be indexed by the string keys used elsewhere.

STRING_PARAMS

These parameters should be given string columns rather than float columns.

Functions

int_to_float(audio)

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

PARAMS

Built-in mutable sequence.

type

str(object=’‘) -> str

Methods

init_sound()

Create a sine wave table using pyo or numpy, depending on the server type.

PARAMS = ['frequency', 'duration', 'amplitude']
type = 'Tone'
init_sound()[source]

Create a sine wave table using pyo or numpy, depending on the server type.

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

PARAMS

Built-in mutable sequence.

type

str(object=’‘) -> str

Methods

init_sound()

Create a table of Noise using pyo or numpy, depending on the server_type

PARAMS = ['duration', 'amplitude']
type = 'Noise'
init_sound()[source]

Create a table of Noise using pyo or numpy, depending on the server_type

class File(path, amplitude=0.01, **kwargs)[source]

Bases: object

A .wav file.

Todo

Generalize this to other audio types if needed.

Attributes

PARAMS

Built-in mutable sequence.

type

str(object=’‘) -> str

Methods

init_sound()

Load the wavfile with scipy.io.wavfile , converting int to float as 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

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

PARAMS

Built-in mutable sequence.

type

str(object=’‘) -> str

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

PARAMS

Built-in mutable sequence.

type

str(object=’‘) -> str

Methods

buffer()

chunk([pad])

If gap is not duration == 0, call parent chunk.

init_sound()

Create and chunk an array of zeros according to Gap.duration

play()

type = 'Gap'
PARAMS = ['duration']
init_sound()[source]

Create and chunk an array of zeros according to Gap.duration

chunk(pad=False)[source]

If gap is not duration == 0, call parent chunk. :Parameters: pad (bool) – unused, passed to parent chunk

buffer()[source]
play()[source]
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

numpy.ndarray