# Audio¶

Load an audio sound and play it with:

from kivy.core.audio import SoundLoader

if sound:
print("Sound found at %s" % sound.source)
print("Sound is %.3f seconds" % sound.length)
sound.play()


You should not use the Sound class directly. The class returned by SoundLoader.load will be the best sound provider for that particular file type, so it might return different Sound classes depending the file type.

Changed in version 1.8.0: There are now 2 distinct Gstreamer implementations: one using Gi/Gst working for both Python 2+3 with Gstreamer 1.0, and one using PyGST working only for Python 2 + Gstreamer 0.10. If you have issue with GStreamer, have a look at GStreamer compatibility

Note

The core audio library does not support recording audio. If you require this functionality, please refer to the audiostream extension.

class kivy.core.audio.Sound[source]

Represents a sound to play. This class is abstract, and cannot be used directly.

Events : on_play : None Fired when the sound is played. on_stop : None Fired when the sound is stopped.
filename

Deprecated since version 1.3.0: Use source instead.

get_pos()[source]

Returns the current position of the audio file. Returns 0 if not playing.

New in version 1.4.1.

length

Get length of the sound (in seconds).

loop

Set to True if the sound should automatically loop when it finishes.

New in version 1.8.0.

loop is a BooleanProperty and defaults to False.

play()[source]

Play the file.

seek(position)[source]

Go to the <position> (in seconds).

source

Filename / source of your audio file.

New in version 1.3.0.

state

State of the sound, one of ‘stop’ or ‘play’.

New in version 1.3.0.

status

Deprecated since version 1.3.0: Use state instead.

stop()[source]

Stop playback.

volume

Volume, in the range 0-1. 1 means full volume, 0 means mute.

New in version 1.3.0.

volume is a NumericProperty and defaults to 1.