Python controllable command-line audio player for Linux

Python controllable command-line audio player for Linux … here is a solution to the problem.

Python controllable command-line audio player for Linux

I want to use my Raspberry Pi as a media station. It should be able to play songs through network commands. These commands should be handled by the server written in Python. Therefore, I need a way to control audio playback through Python.

I decided to use command-line music players for Linux because they should provide maximum flexibility for audio file formats. Also, Python libraries like PyAudio and PyMedia don’t seem to work for me.

I didn’t expect much from a music player. It must be possible to play and pause sound files in as many codecs as possible, and turn the volume up and down. It also has to be a headless player because I’m not running any desktop environment. There seem to be a lot of players like this. For example, mpg123, which works well for all my needs.

The problem I’m having now is that all these players seem to have a user interface written in ncurses, and I don’t know how to access it using the Python subprocess module. So, I either need a music player with Python bindings (bind) or a music player that can be controlled from the command line via the subprocess module. At least these are the solutions I have in mind now.

Does anyone know a Linux command line audio player that can solve my problem? Or is there another way?

Thanks in advance

Solution

MPD should be your best choice. It is a daemon that can be controlled by a variety of clients, from GUI-less command-line clients like mpc to GUI command-line clients like ncmpc and ncmpcpp and up to a few full-featured desktop clients.

MPD + MPC should do the job for you because MPC can be easily controlled through the command line and is also capable of providing various status information about the currently playing songs and other content.

There already seems to be a python client library available for mpd – python-mpd.

Related Problems and Solutions