### Navigation

- index
- next |
- previous |
- Pygame SGE 0.7.0 documentation »
- Classes »

# sge.Sound

class `sge.``Sound`(fname, ID=None, volume=100, max_play=1)

  Sound handling class.

  This class stores and plays sound effects. Note that this is inefficient for large music files; for those, use `sge.Music` instead.

  What sound formats are supported depends on the implementation of the SGE, but sound formats that are generally a good choice are Ogg Vorbis and uncompressed WAV. See the implementation-specific information for a full list of supported formats.

  `volume`

    The volume of the sound in percent from `0` to `100` (`0` for no sound, `100` for max sound).

  `max_play`

    The maximum number of instances of this sound playing permitted. If a sound is played while this number of the instances of the same sound are already playing, one of the already playing sounds will be stopped before playing the new instance. Set to `None` or `0` for no limit.

  `fname`

    The file name of the sound given when it was created. (Read-only)

  `length`

    The length of the sound in milliseconds. (Read-only)

  `playing`

    The number of instances of this sound playing. (Read-only)

## sge.Sound Methods

`Sound.``__init__`(fname, ID=None, volume=100, max_play=1)

  Constructor method.

  Arguments:

  - `fname` – The name of the sound file in one of the paths specified in `sge.sound_directories`. If set to `None`, this object will not actually play any sound. If this is neither a valid sound file nor `None`, `IOError` is raised.
  - `ID` – The value to set `id` to. If set to `None`, `fname` minus the extension will be used, modified by the SGE if it is already the unique identifier of another sound object.

  All other arguments set the respective initial attributes of the sound. See the documentation for `sge.Sound` for more information.

`Sound.``play`(loops=1, volume=100, balance=0, maxtime=None, fade_time=None)

  Play the sound.

  Arguments:

  - `loops` – The number of times to play the sound; set to `None` or `0` to loop indefinitely.
  - `volume` – The volume to play the sound at as a percentage of `self.volume` from `0` to `100` (`0` for no sound, `100` for `self.volume`).
  - `balance` – The balance of the sound effect on stereo speakers as a float from `-1` to `1`, where `0` is centered (full volume in both speakers), `1` is entirely in the right speaker, and `-1` is entirely in the left speaker.
  - `maxtime` – The maximum amount of time to play the sound in milliseconds; set to `None` or `0` for no limit.
  - `fade_time` – The time in milliseconds over which to fade the sound in; set to `None` or `0` to immediately play the sound at full volume.

`Sound.``stop`(fade_time=None)

  Stop the sound.

  Arguments:

  - `fade_time` – The time in milliseconds over which to fade the sound out before stopping; set to `None` or `0` to immediately stop the sound.

`Sound.``pause`()

  Pause playback of the sound.

`Sound.``unpause`()

  Resume playback of the sound if paused.

static `Sound.``stop_all`()

  Stop playback of all sounds.

### Navigation

- index
- next |
- previous |
- Pygame SGE 0.7.0 documentation »
- Classes »