hub.sound

The sound module includes functions to play sounds from the Spike hub speaker.

To use the sound module, add the following import statement to your project:

from hub import sound

All functions in the module should be called inside the sound module as a prefix like so:

sound.stop()

The following constants are defined:

  • ANY = -2

  • DEFAULT = -1

  • WAVEFORM_SINE = 0 (differs from the official docs)

  • WAVEFORM_TRIANGLE = 1

  • WAVEFORM_SQUARE = 2

  • WAVEFORM_SAWTOOTH = 3

Functions

beep([freq, duration, volume, attack, ...])

Play a tone from the hub.

sound(unknown)

UNDOCUMENTED Plays a sound file from the hub (maybe?).

stop()

Stop all noise from the hub.

volume(volume)

Set the baseline volume of the speaker.

hub.sound.beep(freq=440, duration=500, volume=100, *, attack=0, decay=0, sustain=100, release=0, transition=10, waveform=0, channel=-1)

Play a tone from the hub.

Parameters:
  • freq (int) – The frequency to play

  • duration (int) – The duration in milliseconds

  • volume (int) – The volume relative to baseline (0–100)

  • attack (int) – The time taken for initial run-up of level from nil to peak, beginning when the key is pressed

  • decay (int) – The time taken for the subsequent run down from the attack level to the designated sustain level

  • sustain (int) – The level during the main sequence of the sound’s duration, until the key is released

  • release (int) – The time taken for the level to decay from the sustain level to zero after the key is released

  • transition (int) – Time in milliseconds to transition into the sound if something is already playing in the channel

  • waveform (int) – The synthesized waveform. Use one of the constants in the hub.sound module

  • channel (int) – The desired channel to play on; options are: sound.DEFAULT and sound.ANY

Return type:

Awaitable

hub.sound.sound(unknown)

UNDOCUMENTED Plays a sound file from the hub (maybe?).

Return type:

None

hub.sound.stop()

Stop all noise from the hub.

Return type:

None

hub.sound.volume(volume)

Set the baseline volume of the speaker.

Parameters:

volume (int) – The volume (0–100)

Return type:

None