Registry / communication / playsound

playsound

JSON →
library1.3.0pypypiunverified

playsound is a pure Python, cross-platform module designed for playing sounds with a single function call. It aims for simplicity and has no external Python dependencies. The current version is 1.3.0, released in 2021, indicating a stable but currently dormant release cadence.

pip install playsound
INSTALL
IMPORT
SIG · PLAYSOUND
P
playsound
communicationpythonv1.3.0
Install
2.1s avg
Import
25ms
Disk
20MB
Pass rate
6/ 10
Env Coverage6 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 2s
py 3.11
✓ —
✓ 2.05s
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 2.3s
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

playsound
from playsound import playsound

This example demonstrates how to play a sound file using `playsound`. It dynamically creates a small, silent WAV file for cross-platform compatibility and then plays it. Replace `tmp_file_name` with the actual path to your sound file (e.g., `playsound('path/to/your/audio.mp3')`). Be aware that `playsound` blocks the execution of the script until the sound finishes, and specific audio formats may have platform-dependent support.

import os import tempfile from playsound import playsound # Create a dummy WAV file for demonstration # (playsound has no stop/pause, so a very short sound is ideal) # In a real scenario, use an actual sound file like 'path/to/my_sound.wav' # NOTE: For Windows, WAV is the most reliable format. MP3 support is limited. try: with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file: tmp_file_name = tmp_file.name # Minimal WAV header + 1 second of silent audio for demonstration # This is a very basic valid WAV header for a mono 16-bit 44.1kHz sound wav_header = b'RIFF\x2c\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00D\xac\x00\x00\x88\x58\x01\x00\x02\x00\x10\x00data\x08\x00\x00\x00\x00\x00\x00\x00' tmp_file.write(wav_header) tmp_file.flush() print(f"Playing sound from: {tmp_file_name}") playsound(tmp_file_name) print("Sound playback finished.") finally: if 'tmp_file_name' in locals() and os.path.exists(tmp_file_name): os.remove(tmp_file_name) print(f"Cleaned up temporary file: {tmp_file_name}")
Debug
Known issues
gotchaThe `playsound()` function is blocking by default. It will pause the execution of your Python script until the sound finishes playing. For non-blocking playback, you must use Python's `threading` module.
fix
To play sound asynchronously, wrap `playsound()` in a separate thread: `import threading; threading.Thread(target=playsound, args=('path/to/sound.mp3',)).start()`
affects: 1.x.x
gotchaOn Linux, `playsound` relies on the GStreamer media framework. You need to install system-level GStreamer packages (e.g., `gstreamer1.0-plugins-good` and `gstreamer1.0-alsa` on Debian/Ubuntu) for MP3/OGG support. Without them, playback will fail silently or with GStreamer-related errors.
fix
Install required GStreamer packages. Example for Debian/Ubuntu: `sudo apt-get install gstreamer1.0-plugins-good gstreamer1.0-alsa`
affects: 1.x.x
gotcha`playsound` does not provide any functionality to stop, pause, or control the volume of a sound once it has started playing. The sound will play to its completion.
fix
For granular control over sound playback (stop, pause, volume), consider using libraries like `pygame.mixer` or `pydub` (which often requires `ffmpeg`).
affects: 1.x.x
gotchaFile format support is platform-dependent. WAV files generally work reliably across all platforms. MP3 files are supported on macOS and Linux (with GStreamer) but may not work consistently on Windows, which primarily relies on `winsound` for WAV.
fix
For maximum compatibility, convert audio files to WAV format. Always test your chosen format on your target operating systems.
affects: 1.x.x
gotchaError reporting can be minimal or cryptic. If a file is not found, or the format is unsupported, playsound might raise a generic `PlaysoundException` with an obscure error code (e.g., `Error 263` on Windows) or simply fail silently.
fix
Always ensure the file path is correct and the file exists. Verify the file format is supported on the target OS. Wrap `playsound` calls in `try...except PlaysoundException:` blocks to catch specific errors if they are raised.
affects: 1.x.x
Upgrade
Version history
1.3.0latest on PyPI · released Jul 24, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
2
Amazon
1
Resources