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
RuntimeErrorif there is already another active playbackdo not support looping
To learn about the restrictions on streaming, please see:
The
pyglet.media.codecs.base.StreamingSourceclass 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_pathvia 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
Playerfromplay_sound()orSound.play().
- get_volume(player: Player) float[source]
Get the current volume.
- Parameters:
player – A pyglet
Playerfromplay_sound()orSound.play().- Returns:
A volume between
0.0(silent) and1.0(full volume).
- is_playing(player: Player) bool[source]
Trueifplayeris currently playing, otherwiseFalse.- Parameters:
player – A pyglet
Playerfromplay_sound()orSound.play().- Returns:
Trueif 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
Soundand return a pygletPlayer.Important
A
Soundwithstreaming=Trueloses features!Neither
loopnor simultaneous playbacks will work. SeeSoundand Streaming or Static Loading?.- Parameters:
volume – Volume (
0.0is silent,1.0is loudest).pan – Left / right channel balance (
-1is left,0.0is center, and1.0is right).loop –
Trueattempts to restart playback after finishing.speed – Change the speed (and pitch) of the sound. Default speed is
1.0.
- Returns:
A pyglet
Playerfor 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
Playerfromplay_sound()orSound.play().
- source: Source
The
pyglet.media.Sourceobject that holds the audio data.
- stop(player: Player) None[source]
Stop and
delete()player.All references to it in the internal table for
pyglet.media.Sourcewill be deleted.- Parameters:
player – A pyglet pyglet
Playerfromplay_sound()orSound.play().
- arcade.load_sound(path: str | Path, streaming: bool = False) Sound[source]
Load a file as a
Sounddata object.Important
A
Soundwithstreaming=Trueloses features!Neither
loopnor simultaneous playbacks will work. SeeSoundand 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
Truefor long sounds to save memory,Falsefor short sounds to speed playback.
- Returns:
- 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
soundand return a pygletPlayer.The
soundmust be a loadedSoundobject. If you pass a path orstr, the function will raise aTypeError.Important
A
Soundwithstreaming=Trueloses features!Neither
loopnor simultaneous playbacks will work. SeeSoundand 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 /
soundisNoneLog a warning
NoneYes
N/A
A pyglet
PlayerTo learn more about the
streamingkeyword and restrictions, please see:- Parameters:
sound – A
Soundinstance orNone.volume – From
0.0(silent) to1.0(max volume).pan – The left / right ear balance (
-1is left,0is center,right) (and 1 is)
loop –
Truemakes playback restart each time it reaches the end.speed – How fast to play. Slower than
1.0deepens sound while values higher than1.0raise the pitch.
- Returns:
A pyglet
Playerinstance for this playback orNoneif playback failed.
- arcade.stop_sound(player: Player) None[source]
Stop and delete a pyglet
Playerwhich is currently playing.- Parameters:
player – A pyglet pyglet
Playerfromplay_sound()orSound.play().