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 |
---|---|
|
Mouse click |
|
A menu is closed |
|
Generic error |
|
Generic event |
|
Error generated by user |
|
User type a key |
|
User deletes with a key |
|
A menu is opened |
|
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
Sound engine channel
- Return type
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
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