Cross-platform library to play audio files
Project description
Version 3.0.0
New functionalities:
- stop sounds by calling
sound.stop()- check if sound is still playing with
sound.is_alive()
playsound3
Cross platform library to play sound files in Python.
Installation
Install via pip:
pip install playsound3
Quick Start
After installation, playing sounds is simple:
from playsound3 import playsound
# Play sounds from disk
playsound("/path/to/sound/file.mp3")
# or play sounds from the internet.
playsound("http://url/to/sound/file.mp3")
# You can play sounds in the background
sound = playsound("/path/to/sound/file.mp3", block=False)
# and check if they are still playing
if sound.is_alive():
print("Sound is still playing!")
# and stop them whenever you like.
sound.stop()
Reference
playsound
def playsound(
sound: str | Path,
block: bool = True,
backend: str | None | SoundBackend | type[SoundBackend] = None,
) -> Sound
sound (required)
The audio file you want to play (local or URL).
block (optional, default=True)
Determines whether the sound plays synchronously (blocking) or asynchronously (background).
backend (optional, default=None)
Specify which audio backend to use.
If None, the best backend is determined automatically.
To see a list of backends supported by your system:
from playsound3 import AVAILABLE_BACKENDS, DEFAULT_BACKEND
print(AVAILABLE_BACKENDS) # for example: ["gstreamer", "ffmpeg", ...]
print(DEFAULT_BACKEND) # for example: "gstreamer"
Sound
playsound returns a Sound object for playback control:
| Method | Description |
|---|---|
.is_alive() |
Checks if the sound is currently playing. |
.wait() |
Blocks execution until playback finishes. |
.stop() |
Immediately stops playback. |
Supported systems
- Linux
- GStreamer
- ALSA (aplay and mpg123)
- Windows
- WMPlayer
- winmm.dll
- macOS
- AppKit
- afplay
- Multiplatform
- FFmpeg
Fork information
This repository was originally forked from playsound library created by Taylor Marks. The original library is not maintained anymore and doesn't accept pull requests. This library is a major rewrite of its original.
Feel free to create an issue or contribute to playsound3!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file playsound3-3.1.1.tar.gz.
File metadata
- Download URL: playsound3-3.1.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2038c52994e8a023eb98cda223be3c0a155a11b9f1f74a0c9921016fafb342d0
|
|
| MD5 |
58979901d0d3f6076e441347f24b275b
|
|
| BLAKE2b-256 |
6b1ed956ca938372385dffa147b4371c11ec68d3ce0d7fe6a442903456a1dda0
|
File details
Details for the file playsound3-3.1.1-py3-none-any.whl.
File metadata
- Download URL: playsound3-3.1.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d283a7ef3d100fc86dbdf9a6c06c6b7d8db73ca0bbb2b5ae5a6d5ca389be74a
|
|
| MD5 |
961f427bc3886f0b2ce1738702a9db86
|
|
| BLAKE2b-256 |
8d21737ceb95aa1c5e526df9c9c275a2bc27ad61de3285bbb745498dc95b3037
|