Audio In The Console
How The Great Radar Oven Hears His Tunes

Table of Contents

Site Map

Intro

I like music, and I listen to a lot of it. I have about 90hrs in my Spotify playlist that I am slowly moving to a long list of legally downloaded files for use on my computer which, without a GUI, has no easy way to play Spotify (though there is Mopidy).

All I need now is some way to play it!

Linux audio, almost famously, hasn't been renowned for being robust and simple. However, detailed documentation and modern desktop environments means that GUIs enjoy easy audio comparable to that of Windows and MacOS.

Despite considering myself somewhat Linux-familiar, I have put it off due to this reputation. After finally deciding to bite the bullet, it only took maybe 8-10 minutes to get a working audio system. Noice!

About

This guide is not an advanced tutorial for obscure, professional sound cards using low-latency sound servers and special Linux kernels for high quality audio production. I just don't have any experience with that sort of stuff.

I also cannot really help with more than basic troubleshooting as, once again, I don't really have any experience there. My setup didn't really have any problems, but you can e-mail me and I will do what I can.

That said, this guide will walk you through getting a bare-bones Linux system to play a bit of music for the casual user.

If you do feel like contributing some information about your experiences on the subject then do let me know and I will be happy to add it here with accreditation.

Sound Service

Linux used to use a sound service called OSS but it lacked support for lots of hardware and became closed-source for a time. The Linux kernel replaced it with Advanced Linux Sound Architecture (ALSA).

ALSA itself is like a driver installed in the kernel itself that allows the output of audio. To get a few useful programs and features, I recommend installing the alsa-lib and alsa-utils packages. They come in handy and are almost certainly in your distributions package manager.

For example, on Void Linux, this is: # xbps-install -S alsa-lib alsa-utils

After this, I just gave it a go. Type the command $ speaker-test and if everything works you should hear static. Escape from it with C-c.

If this is not working, try running $ alsamixer, a TUI allowing you to choose the sound card with F6 and set volume options graphically.

Players

While we now have audio working in itself, this just means that the computer can output raw data. This won't yet let you play an encoded audio file.

My preferred method of playing music is by using standalone applications that do nothing but decode the audio file and allow ALSA to output it. The vast majority of codecs that I come across are likely covered by the twin packages, mpg123 and ogg123 (as part of the vorbis-tools package).

Note: Daemon Players

As aforementioned, this is not a comprehensive guide aimed at anyone in particular, just the method that I chose.

I feel I should mention another popular way to play music from a console: A background process (daemon in *Nix) that you can 'tap into' using a separate client. The Music Player Daemon (MPD) is probably the most prevalent example of such a player. There are many clients available for MPD, such as ncmpcpp.

Luke Smith made a great video demonstrating just this.

Front-ends

So now we can theoretically decode and output a variety of music codecs using commands, but it is slow and annoying using the raw commands. What we need is a way of abstracting out and automating these commands using a different application, to make our lives a lot easier.

Cmus

'The C* Music Player' is a standalone front-end application that interfaces well with ogg123 and mpg123. It works similarly to Vi/Vim, using : to begin typed commands, and single-key actions. It is fast to use and, being a CLI application, fast to run.

It looks very nice and works right out of the box, though it does have a comprehensive configuration file for changing the look, feel, and functionality. This is my favourite standalone music player front-end, and I would recommend it for almost everyone. My personal complaint is that the bindings take a while to learn, but I believe them to be re-bind-able and are all available in the man-page. Plus I am just bad at remembering key chords, especially non-Emacs ones.

Cmus also happens to be one of the only players available in the Void Linux repositories, so it is the easiest to install and try out (at least for me).

Emacs

That's right, Emacs can still do everything! While I try and reserve Emacs for text editing only, I have taken a liking to using Emacs for managing my playing music.

One nice thing is that you can run music in the background by using the Emacs server before using $ emacsclient <file>, though just suspending the Emacs job with M-x suspend-emacs does the trick (return to it with $ fg).

Bongo

I really like the name of this package. This media player is very simple and, like Cmus, works out of the box, no setup required (apart from requiring Emacs). Usage is simple and intuitive by quickly dropping in and out of the relevant buffers, while allowing enough power to make it my preferred console music player.

The defaults are sane, but I have made a couple of changes and assigned one or two custom keybindings to my preference.

I have changed the mode-line strings to +>+ and +=+, as I felt them to be a bit unwieldy, defaulting to [ Playing ] or [ Paused ].

There is a dedicated text character for a right pointing arrow available on the Linux TTY. I should really change the icon into this in the future.

This is by bongo config file:

;; ==================== Bongo Music Player Config
;; Send me to right directory
(setq bongo-default-directory "~/sounds/")
(bongo-insert-directory-tree "~/sounds/")
;; Change mode-line settings
(setq bongo-mode-line-playing-string ">")
(setq bongo-mode-line-paused-string "=")
(defun bongo-default-mode-line-indicator-function ()
  (concat " +" (bongo-mode-line-pause/resume-button) "+"))
;; Play my playlist in a random order
(bongo-random-playback-mode t)
;; Fixes Ogg123/MPG123 occasionally not stopping on exit
(add-hook 'kill-emacs-hook 'bongo-stop)
  • Volume

    This is a separate package that allows the user to adjust the sound-card volume from within Emacs. It gives you a nice graphical bar in the minibuffer and is the method that bongo recommends for adjusting the volume. It is not included by default or as a Bongo dependency, but it is available in the MELPA package repositories.

    (global-set-key (kbd "C-c v") 'volume)
    

EMMS

The Emacs Multimedia System is the more powerful of the two main players that Emacs offers. I will probably end up moving to this player eventually but I am a little daunted by the large documentation that it has. I know of several hardcore Emacs users who do very well with EMMS, but frankly, it has more features than I need and will take a bit more setup. I had a short play around with it though, and it looks good.

Codecs

Personally, I would recommend using free (as in freedom) codecs for your music. If you are a casual user, this won't really affect your listening experience and you will help out the free-software developers.

Furthermore, a free codec will likely have longer support with much lower risk of a complete drop in support like that which happened to MP3 recently. I include mpg123 in this guide because chances are that you still have MP3s and will still come across them for a while yet. Think of it like a backwards compatibility thing that we should slowly phase out in favour of something else.

For a loss-y codec, like MP3, I recommend Ogg Vorbis (.ogg file extension).

Alternatively, Opus is available, which is apparently higher quality and lower latency.

For those who hear a difference with lossless codecs, FLAC (.flac file extension) literally stands for 'Free Lossless Audio Codec'. It is supposed to be the fastest lossless codec out there.