A simple, minimal-hassle, few-dependency Python audio playback solution.
Play audio using any of the optional dependencies you have installed.
Options (clink to see installation instructions): ffplay mpv vlc mpg123 cmus gst aplay simpleaudio pyaudio playsound filemgr elisa (and auto)
Note: If you prefer the most convenient audio playback on a modern PC and don't mind the additional hard disk space (less than 256 MB), choose the optional dependency ffplay.
Installation:
pip install anyplayerSimple Example:
from anyplayer import get_player
player = get_player('auto', './ba.mp3')
player.start()
player.wait()ffplay mpv vlc mpg123 cmus gst aplay simpleaudio pyaudio playsound filemgr elisa
FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video.
Windows: Download binaries from BtbN/FFmpeg-Builds GitHub Releases (and add it to your PATH).
Linux:
pacman -Syu ffmpeg
# or
apt install ffmpegmpv is a free, open source, and cross-platform media player.
Windows: Download binaries from First-party builds (and add it to your PATH).
Linux:
pacman -Syu mpv
# or
apt install mpvVLC is a free and open source cross-platform multimedia player and framework that plays most multimedia files as well as DVDs, Audio CDs, VCDs, and various streaming protocols.
Linux:
pacman -Syu vlc
# or
apt install vlcmpg123 is a fast console MPEG Audio Player and decoder library.
Windows: Download binaries from First-party builds (and add it to your PATH).
Linux:
pacman -Syu mpg123
# or
apt install mpg123cmus is a small, fast and powerful console music player for Unix-like operating systems.
Linux:
pacman -Syu cmusNote: To use the optional player cmus, ensure cmus is running in a separate terminal session.
gst-plugins-base-libs is a multimedia graph framework.
Linux:
pacman -Syu gst-plugins-base-libsaplay is an utility for the playback of .wav, .voc, .au files. It's included in the official alsa-utils package.
Linux:
pacman -Syu alsa-utilsThe simplaudio package provides cross-platform, dependency-free audio playback capability for Python 3 on OSX, Windows, and Linux.
pip install simplaudio
# or
pacman -Syu python-simpleaudioNote: Unfortunately, simpleaudio has been archived and unmaintained for over three years. It has known bugs and compatibility issues with Python 3.12 or later.
(A segmentation fault will occur when audio playback is completed or aborted. This can be used if you are only playing once and have no other tasks after the playback stops.)
Additionally, on Windows, ensure you call multiprocessing.freeze_support() immediately after the if __name__ == '__main__': line in the main module:
# main.py
import multiprocessing
...
if __name__ == '__main__':
multiprocessing.freeze_support()
...PyAudio provides Python bindings for PortAudio v19, the cross-platform audio I/O library.
pip install pyaudio
# or
conda install pyaudio portaudio
# or
pacman -Syu python-pyaudioNote: The optional module pyaudio may fail to play 64-bit WAV files, as the wave module does not support 64-bit WAV audio.
Additionally, on Linux, pyaudio may produce significant noise during playback.
playsound is a pure Python, cross platform, single-function module with no dependencies for playing sounds.
Note: However, as the original module is no longer maintained and doesn't accept pull requests, we use playsound3 as an alternative.
pip install playsound3Invokes the default file manager directly.
Windows: explorer.exe.
Linux: dolphin or xdg-open.
Note: filemgr directly invokes the default file manager so may not exit cleanly.
Elisa is the default music player for KDE.
More information specific to OSX (optional dependencies, testing, ...)