Sound#

class arcade.Sound(file_name: str | Path, streaming: bool = False)[source]#

Bases:

This class represents a sound you can play.

get_length() float[source]#

Get length of audio in seconds

get_stream_position(player: Player) float[source]#

Return where we are in the stream. This will reset back to zero when it is done playing.

Parameters:

player – Player returned from play_sound().

get_volume(player: Player) float[source]#

Get the current volume.

Parameters:

player – Player returned from play_sound().

Returns:

A float, 0 for volume off, 1 for full volume.

is_complete(player: Player) bool[source]#

Return true if the sound is done playing.

is_playing(player: Player) bool[source]#

Return if the sound is currently playing or not

Parameters:

player – Player returned from play_sound().

Returns:

A boolean, True if the sound is playing.

play(volume: float = 1.0, pan: float = 0.0, loop: bool = False, speed: float = 1.0) Player[source]#

Play the sound.

Parameters:
  • volume – Volume, from 0=quiet to 1=loud

  • pan – Pan, from -1=left to 0=centered to 1=right

  • loop – Loop, false to play once, true to loop continuously

  • speed – Change the speed of the sound which also changes pitch, default 1.0

set_volume(volume, player: Player) None[source]#

Set the volume of a sound as it is playing.

Parameters:
  • volume – Floating point volume. 0 is silent, 1 is full.

  • player – Player returned from play_sound().

stop(player: Player) None[source]#

Stop a currently playing sound.

arcade.load_sound(path: str | Path, streaming: bool = False) Sound | None[source]#

Load a sound.

Parameters:
  • path – Name of the sound file to load.

  • streaming – Boolean for determining if we stream the sound or load it all into memory. Set to True for long sounds to save memory, False for short sounds to speed playback.

Returns:

Sound object which can be used by the play_sound() function.

arcade.play_sound(sound: Sound, volume: float = 1.0, pan: float = 0.0, loop: bool = False, speed: float = 1.0) Player | None[source]#

Play a sound.

Parameters:
  • sound – Sound loaded by load_sound(). Do NOT use a string here for the filename.

  • volume – Volume, from 0=quiet to 1=loud

  • pan – Pan, from -1=left to 0=centered to 1=right

  • loop – Should we loop the sound over and over?

  • speed – Change the speed of the sound which also changes pitch, default 1.0

arcade.stop_sound(player: Player)[source]#

Stop a sound that is currently playing.

Parameters:

player – Player returned from play_sound().