Cross-platform library to play audio files
Project description
Version 4.0.1
New functionalities:
- New parameter to control volume
playsound4
playsound4 is a fork of playsound3 that adds native volume control while maintaining the same simple API.
Features
- Cross-platform audio playback
- Pure Python
- Volume control (0-100)
- Blocking and non-blocking playback
- Compatible with existing playsound3 code
Cross platform library to play sound files in Python.
Installation
Install via pip:
pip install playsound4
Quick Start
After installation, playing sounds is simple:
from playsound4 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)
# You can play sounds at different volumes
sound = playsound("/path/to/sound/file.mp3", volume=50)
# 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,
volume: int | None = None,
block: bool = True,
backend: str | None = 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 playsound4 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
Supported audio formats
The bare minimum supported by every backend are .mp3 and .wav files.
Using them will keep your program compatible across different systems.
To see an exhaustive list of extensions supported by a backend, refer to their respective documentation.
Fork information
This repository was originally forked from playsound3 library created by Szymon Mikler. This library is a rewrite of its original.
Feel free to create an issue or contribute to playsound4!
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 playsound4-4.0.1.tar.gz.
File metadata
- Download URL: playsound4-4.0.1.tar.gz
- Upload date:
- Size: 609.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20a4cb51de63fd3d485c902ed94e67b756c1d09ca1c7cb6f226cb1a4e0df94e1
|
|
| MD5 |
3e2ff5f1617a994b3b4205aca052c833
|
|
| BLAKE2b-256 |
aca4f314e00bc04b77b2cd4493fb9ca4cc0714774b8cc1cce63545d0e9109904
|
File details
Details for the file playsound4-4.0.1-py3-none-any.whl.
File metadata
- Download URL: playsound4-4.0.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89e4b347b51bc28b8c54d186cccb11fc5e35431f25beafe86e6fdc6bba4e0f56
|
|
| MD5 |
4b74fdfab2a7be2498dd8d235f7b50f0
|
|
| BLAKE2b-256 |
32084627b1c47f8b150535c1c17175e1fcb283f520ccde6c5d20da9620b074e8
|