simpleguics2pygame — sound

simpleguics2pygame module: simpleguics2pygame/sound.

Class Sound.

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

license:GPLv3 — Copyright (C) 2015-2016, 2020 Olivier Pirson
author:Olivier Pirson — http://www.opimedia.be/
version:November 29, 2020
class SimpleGUICS2Pygame.simpleguics2pygame.sound._LocalSound(filename)[source]

Child of Sound to load local file sound.

(Not available in SimpleGUI of CodeSkulptor.)

__init__(filename)[source]

Set a sound (if not Sound._load_disabled).

Don’t use directly, use _local_load_sound().

Parameters:filename – str
__repr__()[source]

Return ‘<_LocalSound object>’.

Returns:str
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
__weakref__

list of weak references to the object (if defined)

_dir_search_first = '_snd/'

load_sound() try first to loading sound from this directory, and next if failed, try to loading from URL.

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

_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
_load_disabled = False

If True then load sounds are disabled.

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
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: OGG, WAV and MP3.

If MP3 sound failed on your system read installation of audioread.

(Supported formats by CodeSkulptor are browser dependant.)

(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__ = ('_LocalSound', 'Sound', 'create_sound', 'load_sound', '_load_local_sound')

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.

[source]