simpleguics2pygame — sound

simpleguics2pygame/sound (April 29, 2016)

Class Sound.

Piece of SimpleGUICS2Pygame. https://bitbucket.org/OPiMedia/simpleguics2pygame

GPLv3 — Copyright (C) 2015, 2016 Olivier Pirson http://www.opimedia.be/

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

Sound similar to SimpleGUI Sound of CodeSkulptor.

__init__(url)[source]

Set a sound (if not Sound._load_disabled).

Don’t use directly, use load_sound().

Parameters:url – str
__repr__()[source]

Return ‘<Sound object>’.

Returns:str
_get_length()[source]

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()[source]

Pause this sound. (Use Sound.play() to resume.)

play()[source]

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

rewind()[source]

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

set_volume(volume)[source]

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

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

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!)

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

Sound

SimpleGUICS2Pygame.simpleguics2pygame.sound.load_sound(url)[source]

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('http://commondatastorage.googleapis.com/codeskulptor-assets/jump.ogg') try first to loading from _snd/commondatastorage.googleapis.com/codeskulptor_assets/jump.ogg.

Supported formats are supported formats by Pygame: OGG and uncompressed WAV (see http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound ).

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

(The sound can be started by Sound.play().)

Parameters:url – str (only a valid URL, not local filename)
Returns:Sound
SimpleGUICS2Pygame.simpleguics2pygame.sound._load_local_sound(filename)[source]

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)
Returns:_LocalSound
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

[source]