simpleguics2pygame — sound

simpleguics2pygame/sound (April 29, 2016)

Class Sound.

Piece of SimpleGUICS2Pygame.

GPLv3 — Copyright (C) 2015, 2016 Olivier Pirson

class SimpleGUICS2Pygame.simpleguics2pygame.sound.Sound(url)[source]

Sound similar to SimpleGUI Sound of CodeSkulptor.


Set a sound (if not Sound._load_disabled).

Don’t use directly, use load_sound().

Parameters:url – str

Return ‘<Sound object>’.


Return the length of this sound in seconds.

(If initialization of this sound was failed then return 0.)

(Not available in SimpleGUI of CodeSkulptor.)

Returns:int or float

Pause this sound. (Use to resume.)


If this sound is paused then resume the sound, else start the sound.


If this sound has already been started then stop the sound and rewind to the begining.


Change the volume of this sound. The default volume is 1 (maximum).

Parameters:volume – 0 <= int or float <= 1

list of weak references to the object (if defined)

SimpleGUICS2Pygame.simpleguics2pygame.sound.create_sound(sound_data, sample_rate=8000, num_channels=1)[source]

NOT YET IMPLEMENTED! (Return an empty Sound.)

(Available in SimpleGUI of CodeSkulptor but not in CodeSkulptor documentation!)

  • sound_data – (tuple or list) of (0 <= int < 256)
  • sample_rate – int >= 0
  • num_channels – int >= 0



Create and return a sound by loading a file from url. Not founded URL and errors are ignored.

SimpleGUICS2Pygame try first to loading sound from Sound._dir_search_first local directory (_snd/ by default), and next if failed, try to loading from url.

This local directory is relative to the directory of your program.

For example, load_sound('') try first to loading from _snd/

Supported formats are supported formats by Pygame: OGG and uncompressed WAV (see ).

(CodeSkulptor may supported also MP3, dependant on browser support.)

(The sound can be started by

Parameters:url – str (only a valid URL, not local filename)

Create and return a sound by loading a file from filename. Not founded file and errors are ignored.

I recommend to use only Internet resources with the load_sound() function. Then you can use your program both in standard Python and in CodeSkulptor. (See Tips.html#download-medias .)

But if it is necessary, you can load local sound with this “private” function.

Supported formats are the same as the load_sound() function.

(Not available in SimpleGUI of CodeSkulptor.)

Parameters:filename – str (only a valid filename, not URL)
SimpleGUICS2Pygame.simpleguics2pygame.sound.__all__ = ['Sound', 'create_sound', 'load_sound', '_load_local_sound']

list() -> new empty list list(iterable) -> new list initialized from iterable’s items