# 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.

## Event dispatching and state changes¶

Audio is often processed in parallel to your code. This means you often need to enter the Kivy eventloop in order to allow events and state changes to be dispatched correctly.

You seldom need to worry about this as Kivy apps typically always require this event loop for the GUI to remain responsive, but it is good to keep this in mind when debugging or running in a REPL (Read-eval-print loop).

バージョン 1.10.0 で変更: The pygst and gi providers have been removed.

バージョン 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.

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[ソース]

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

バージョン 1.3.0 で撤廃: Use source instead.

get_pos()[ソース]

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

バージョン 1.4.1 で追加.

length

Get length of the sound (in seconds).

load()[ソース]

loop

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

バージョン 1.8.0 で追加.

loop is a BooleanProperty and defaults to False.

pitch

Pitch of a sound. 2 is an octave higher, .5 one below. This is only implemented for SDL2 audio provider yet.

バージョン 1.10.0 で追加.

pitch is a NumericProperty and defaults to 1.

play()[ソース]

Play the file.

seek(position)[ソース]

Go to the <position> (in seconds).

Most sound providers cannot seek when the audio is stopped. Play then seek.

source

Filename / source of your audio file.

バージョン 1.3.0 で追加.

source is a StringProperty that defaults to None and is read-only. Use the SoundLoader.load() for loading audio.

state

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

バージョン 1.3.0 で追加.

state is a read-only OptionProperty.

status

バージョン 1.3.0 で撤廃: Use state instead.

stop()[ソース]

Stop playback.

unload()[ソース]

volume

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

バージョン 1.3.0 で追加.

volume is a NumericProperty and defaults to 1.

class kivy.core.audio.SoundLoader[ソース]

ベースクラス: builtins.object

Load a sound, using the best loader for the given file type.

static load(filename)[ソース]

Load a sound, and return a Sound() instance.

static register(classobj)[ソース]

Register a new class to load the sound.