World > Sound#

class miniworlds.worlds.manager.sound_manager.SoundManager(app)[source]#

Public Methods:

__init__(app)

play(path[, volume])

Plays a sound from the given path.

register(path)

Registers a sound for later use.

is_registered(path)

Checks if a sound is already registered.

stop(path)

Stops a playing sound.

is_playing(path)

Checks if the given sound is currently playing.


is_playing(path)[source]#

Checks if the given sound is currently playing.

Return type:

bool

Parameters:

path – The path to the sound.

Returns:

True if the sound is currently playing, False otherwise.

Return type:

bool

Raises:

ValueError – If path is empty.

Example

if world.sound.is_playing(“sounds/explosion.wav”):

world.sound.stop(“sounds/explosion.wav”)

is_registered(path)[source]#

Checks if a sound is already registered.

Return type:

bool

Parameters:

path – The path to the sound.

Returns:

True if the sound is already registered, False otherwise.

Return type:

bool

Raises:

ValueError – If path is empty.

Example

if not world.sound.is_registered(“sounds/explosion.wav”):

world.sound.register(“sounds/explosion.wav”)

play(path, volume=100)[source]#

Plays a sound from the given path.

Return type:

None

Parameters:
  • path – The path to the sound.

  • volume – Volume to play the sound (0 min, 100 max).

Raises:

ValueError – If path is empty or volume is out of range.

Example

world.sound.play(“sounds/explosion.wav”, volume=80)

register(path)[source]#

Registers a sound for later use.

Return type:

None

Parameters:

path – The path to the sound.

Raises:

ValueError – If path is empty.

Example

world.sound.register(“sounds/explosion.wav”)

stop(path)[source]#

Stops a playing sound.

Return type:

None

Parameters:

path – The path to the sound to stop.

Raises:

ValueError – If path is empty.

Example

world.sound.stop(“sounds/explosion.wav”)