2011-06-27 05:12:03 +00:00
|
|
|
"""
|
|
|
|
Basic Sound Playback
|
2011-06-27 07:44:59 +00:00
|
|
|
++++++++++++++++++++
|
2015-09-08 04:30:05 +00:00
|
|
|
|
2020-03-19 20:20:26 +00:00
|
|
|
This script shows how to use the classes: :class:`Device`, :class:`Sound` and
|
2011-06-27 05:12:03 +00:00
|
|
|
:class:`Handle`.
|
|
|
|
"""
|
|
|
|
import aud
|
|
|
|
|
2020-03-19 20:20:26 +00:00
|
|
|
device = aud.Device()
|
2011-06-27 05:12:03 +00:00
|
|
|
# load sound file (it can be a video file with audio)
|
2020-03-19 20:20:26 +00:00
|
|
|
sound = aud.Sound('music.ogg')
|
2011-06-27 05:12:03 +00:00
|
|
|
|
|
|
|
# play the audio, this return a handle to control play/pause
|
2020-03-19 20:20:26 +00:00
|
|
|
handle = device.play(sound)
|
2011-06-27 05:12:03 +00:00
|
|
|
# if the audio is not too big and will be used often you can buffer it
|
2020-03-19 20:20:26 +00:00
|
|
|
sound_buffered = aud.Sound.buffer(sound)
|
|
|
|
handle_buffered = device.play(sound_buffered)
|
2011-06-27 05:12:03 +00:00
|
|
|
|
|
|
|
# stop the sounds (otherwise they play until their ends)
|
|
|
|
handle.stop()
|
|
|
|
handle_buffered.stop()
|