Sound
- class arcade.Sound(file_name: str | Path, streaming: bool = False)[source]
Bases:
Holds playable loaded audio data.
Important
Streaming disables features!
When
streaming=True
,play()
andplay_sound()
:raise a
RuntimeError
if there is already another active playbackdo not support looping
To learn about the restrictions on streaming, please see:
The
pyglet.media.codecs.base.StreamingSource
class used internally
To learn about cross-platform loading and file format concerns, please see:
Arcade’s sound documentation:
The pyglet guide to Playing Sound and Video
- Parameters:
file_name – The path of a file to load, optionally prefixed with a resource handle.
streaming – If
True
, attempt to load data fromfile_path
via via streaming.
- get_stream_position(player: Player) float [source]
Return where we are in the stream. This will reset back to zero when it is done playing.
- Parameters:
player – A pyglet
Player
fromplay_sound()
orSound.play()
.
- get_volume(player: Player) float [source]
Get the current volume.
- Parameters:
player – A pyglet
Player
fromplay_sound()
orSound.play()
.- Returns:
A volume between
0.0
(silent) and1.0
(full volume).
- is_playing(player: Player) bool [source]
True
ifplayer
is currently playing, otherwiseFalse
.- Parameters:
player – A pyglet
Player
fromplay_sound()
orSound.play()
.- Returns:
True
if the passed pyglet player is playing.
- play(volume: float = 1.0, pan: float = 0.0, loop: bool = False, speed: float = 1.0) Player [source]
Try to play this
Sound
and return a pygletPlayer
.Important
A
Sound
withstreaming=True
loses features!Neither
loop
nor simultaneous playbacks will work. See :py;class:Sound and Streaming or Static Loading?.- Parameters:
volume – Volume (
0.0
is silent,1.0
is loudest).pan – Left / right channel balance (
-1
is left,0.0
is center, and1.0
is right).loop –
True
attempts to restart playback after finishing.speed – Change the speed (and pitch) of the sound. Default speed is
1.0
.
- Returns:
A pyglet
Player
for this playback.
- set_volume(volume: float, player: Player) None [source]
Set the volume of a sound as it is playing.
- Parameters:
volume – Floating point volume. 0 is silent, 1 is full.
player – A pyglet
Player
fromplay_sound()
orSound.play()
.
- stop(player: Player) None [source]
Stop and
delete()
player
.All references to it in the internal table for
pyglet.media.Source
will be deleted.- Parameters:
player – A pyglet pyglet
Player
fromplay_sound()
orSound.play()
.
- arcade.load_sound(path: str | Path, streaming: bool = False) Sound [source]
Load a file as a
Sound
data object.Important
A
Sound
withstreaming=True
loses features!Neither
loop
nor simultaneous playbacks will work. See :py;class:Sound and Streaming or Static Loading?.- Parameters:
path – a path which may be prefixed with a resource_handle.
streaming – Boolean for determining if we stream the sound or load it all into memory. Set to
True
for long sounds to save memory,False
for short sounds to speed playback.
- Returns:
ref:playable <sound-basics-playing>` instance of a
Sound
object.- Return type:
A
- arcade.play_sound(sound: Sound | None, volume: float = 1.0, pan: float = 0.0, loop: bool = False, speed: float = 1.0) Player | None [source]
Try to play the
sound
and return a pygletPlayer
.The
sound
must be a loadedSound
object. If you pass a path orstr
, the function will raise aTypeError.
Important
A
Sound
withstreaming=True
loses features!Neither
loop
nor simultaneous playbacks will work. See :py;class:Sound and Streaming or Static Loading?.The output and return value depend on whether playback succeeded: .. # Note: substitutions don’t really work inside tables, so the .. # pyglet player below is left as a normal class cross-reference.
Success?
Console output
Return value
No /
sound
isNone
Log a warning
None
Yes
N/A
A pyglet
Player
To learn more about the
streaming
keyword and restrictions, please see:- Parameters:
sound – A
Sound
instance orNone
.volume – From
0.0
(silent) to1.0
(max volume).pan – The left / right ear balance (
-1
is left,0
is center,right) (and 1 is)
loop –
True
makes playback restart each time it reaches the end.speed – How fast to play. Slower than
1.0
deepens sound while values higher than1.0
raise the pitch.
- Returns:
A pyglet
Player
instance for this playback orNone
if playback failed.
- arcade.stop_sound(player: Player) None [source]
Stop and delete a pyglet
Player
which is currently playing.- Parameters:
player – A pyglet pyglet
Player
fromplay_sound()
orSound.play()
.