# Class cocos.audio.pygame.mixer.Sound

The Sound object represents actual sound sample data.

Methods that change the state of the Sound object will the all instances of the Sound playback.

## Methods

| __del__(self)
| __init__(self, file, _chunk=None) Create a new Sound object from a file.
| fadeout(self, time) Stop sound playback after fading out.
float | get_length(self) Get the length of the Sound.
int | get_num_channels(self) Count how many times this Sound is playing.
float | get_volume(self) Get the playback volume.
Channel | play(self, loops=0, maxtime=-1) Begin sound playback.
| set_volume(self, volume) Set the playback volume for this Sound.
| stop(self) Stop sound playback.

## Method Details

### __init__

(Constructor) __init__(self, file, _chunk=None)

Create a new Sound object from a file.

Load a new sound buffer from a filename or from a python file object. Limited resampling will be performed to help the sample match the initialize arguments for the mixer.

The Sound can be loaded from an OGG audio file or from an uncompressed WAV.

Parameters:
  file : str or file-like object
    The filename or file to load.
  _chunk : None
    Internal use only.

### fadeout

fadeout(self, time)

Stop sound playback after fading out.

This will stop playback of the sound after fading it out over the time argument in milliseconds. The Sound will fade and stop on all actively playing channels.

Parameters:
  time : int
    Time to fade out, in milliseconds.

### get_length

get_length(self)

Get the length of the Sound.

Return the length of this Sound in seconds.

Returns: float

### get_num_channels

get_num_channels(self)

Count how many times this Sound is playing.

Return the number of active channels this sound is playing on.

Returns: int

### get_volume

get_volume(self)

Get the playback volume.

Return a value from 0.0 to 1.0 representing the volume for this Sound.

Returns: float

### play

play(self, loops=0, maxtime=-1)

Begin sound playback.

Begin playback of the Sound (i.e., on the computer's speakers) on an available Channel. This will forcibly select a Channel, so playback may cut off a currently playing sound if necessary.

The loops argument controls how many times the sample will be repeated after being played the first time. A value of 5 means that the sound will be played once, then repeated five times, and so is played a total of six times. The default value (zero) means the Sound is not repeated, and so is only played once. If loops is set to -1 the Sound will loop indefinitely (though you can still call stop() to stop it).

The maxtime argument can be used to stop playback after a given number of milliseconds.

Parameters:
  loops : int
    Number of times to repeat the sound after the first play.
  maxtime : int
    Maximum number of milliseconds to play for.
Returns:
  Channel: The Channel object for the channel that was selected.

### set_volume

set_volume(self, volume)

Set the playback volume for this Sound.

This will set the playback volume (loudness) for this Sound. This will immediately affect the Sound if it is playing. It will also affect any future playback of this Sound. The argument is a value from 0.0 to 1.0.

Parameters:
  volume : float
    Volume of playback, in range [0.0, 1.0]

### stop

stop(self)

Stop sound playback.

This will stop the playback of this Sound on any active Channels.