Adding sounds¶
A sound engine can be created using the Sound
class. The sound engine can be customized by setting a sound
file to several sounds defined by a type.
For example, buttons or keys…
Example:
import pygame_menu
from pygame_menu import sound
engine = sound.Sound()
engine.set_sound(sound.SOUND_TYPE_CLICK_MOUSE, '/home/me/click.ogg')
engine.set_sound(sound.SOUND_TYPE_OPEN_MENU, '/home/me/open.ogg')
menu = pygame_menu.Menu(...)
menu.set_sound(engine, recursive=True) # Apply on menu and all sub-menus
Sound types are the following:
Type | Description |
---|---|
pygame_menu.sound.SOUND_TYPE_CLICK_MOUSE |
Mouse click |
pygame_menu.sound.SOUND_TYPE_CLOSE_MENU |
A menu is closed |
pygame_menu.sound.SOUND_TYPE_ERROR |
Generic error |
pygame_menu.sound.SOUND_TYPE_EVENT |
Generic event |
pygame_menu.sound.SOUND_TYPE_EVENT_ERROR |
Error generated by user |
pygame_menu.sound.SOUND_TYPE_KEY_ADDITION |
User type a key |
pygame_menu.sound.SOUND_TYPE_KEY_DELETION |
User deletes with a key |
pygame_menu.sound.SOUND_TYPE_OPEN_MENU |
A menu is opened |
pygame_menu.sound.SOUND_TYPE_WIDGET_SELECTION |
A widget is selected |
Sound engine class.
Parameters: - uniquechannel (bool) – Force the channel to be unique, this is set at the moment of creation of the object
- frequency (int) – Frequency of sounds
- size (int) – Size of sample
- channels (int) – Number of channels by default
- buffer (int) – Buffer size
- devicename (str) – Device name
- allowedchanges (bool) – Convert the samples at runtime, only in pygame>=2.0.0
- force_init (bool) – Force mixer init with new parameters
Return the channel of the sound engine.
Returns: Channel Return type: pygame.mixer.Channel
Return the current channel information of the sound engine.
Returns: An info dict e.g.: {‘busy’: 0, ‘endevent’: 0, ‘queue’: None, ‘sound’: None, ‘volume’: 1.0} Return type: dict
Load the example sounds provided by the package.
Parameters: volume (float) – Volume of the sound, (0-1) Returns: None
Pause the current channel.
Returns: None
Play click mouse sound.
Returns: None
Play close menu sound.
Returns: None
Play error sound.
Returns: None
Play event sound.
Returns: None
Play event error sound.
Returns: None
Play key addition sound.
Returns: None
Play key deletion sound.
Returns: None
Play open menu sound.
Returns: None
Play widget selection sound.
Returns: None
Link a sound file to a sound type.
Parameters: Returns: The status of the sound load, True if the sound was loaded
Return type:
Stop the current the channel.
Returns: None
Unpause channel.
Returns: None