Automatically view song lyrics as you listen
Tutorial – Lyrics-in-terminal
Whether you listen to music on Spotify or a classic audio player like Rhythmbox, Lollypop, or Audacious, a tool named Lyrics-in-terminal will let you read the lyrics for the track you are currently playing.
In today's very challenging times, there are many artists who write expressive, interesting, and relevant lyrics. Whether it's hip-hop, pop, or folk music, you'll find many artists in recent years who definitely have something to say.
However, it is often not easy for the listener to hear exactly what an artist is saying or singing, or to follow along quickly enough – consider for example, Eminem's double-time rap. Regardless of your taste in music, for many songs you might wish you had a simple option for displaying the lyrics, so you can follow along without having to search for the lyrics on the web time and time again. Some players do offer the ability to display the lyrics for the track currently playing, but even better, the Lyrics-in-terminal [1] program can retrofit this feature for virtually any player.
Installation
Currently you will not find the program in the package sources of the common distributions. Users of Arch Linux and its derivatives have the easiest approach to installing the application: Just download the package lyrics-in-terminal from the Arch User Repository (AUR) onto your system. If you are working with a different distribution, use the pip Python package manager instead, and then run the commands from Listing 1 to install the program on Debian or Ubuntu.
Listing 1
Installation
$ sudo apt install python3-pip $ pip install lyrics-in-terminal
The package manager installs the program into ~/.local/bin/
. However, the shell only adds this directory to the PATH
environment variable if the directory already exists at login time. For the program's lyrics
command to work, you may need to log out and log back in again. If the system still does not find the command, check the ~/.profile
in your home directory and append the lines from Listing 2. After logging out and back on again, the shell command should work.
Listing 2
~/.profile
[...] # set PATH so it includes user's # private bin if it exists if [ -d "$HOME/.local/bin" ]; then PATH="$HOME/.local/bin:$PATH" fi
Lyrics in the Terminal
By default, Lyrics-in-terminal automatically connects to Spotify. You just need to launch the program in a terminal window using the lyrics
command to play any song with the official Spotify client (Figure 1). A short while later, the song lyrics will appear in the terminal window; you do not need a commercial premium account. In the header, you will also see the name of the song, the artist, and below it the album title. If the length of the lyrics exceeds the space in the terminal, you can scroll through the contents with the arrow keys.
In our test, Lyrics-in-terminal worked better than the feature included in Spotify's Android client (the PC variant of the client does not offer this option as of yet). The display in the Android app only provides results for really well-known artists, while Lyrics-in-terminal had no problem identifying salsa from the Caribbean, chansons from France, fado from Portugal, or even Deutschrap (German hip hop). The program only showed a lyrics not found message for instrumentals or acoustic techno tracks – no surprises there.
Under the hood, Lyrics-in-terminal does not use its own database, but accesses the freely available data from AZLyrics [2]. This project has been collecting song lyrics for years and legitimately licensing them from record labels. There is no danger that the texts will disappear off the web overnight. If lyrics are missing or incorrect, the community can add the data via the service's portal.
Not Only Spotify
Now, not every user uses Spotify to play music. No problem: Lyrics-in-terminal does not tap the data about the song currently playing from the player, but via the native D-Bus and the Media Player Remote Interfacing Specification (MPRIS) [3] – a feature that most media players on Linux support. For example, the desktop environments use the technology to control the player's playback via widgets or to display information about the current song.
You can specify which media players Lyrics-in-terminal should now listen out for via an option attached to the call. The lyrics
command links with Spotify as described, while lyrics rhythmbox
links with the Gnome desktop's Rhythmbox media player. The connection works with any media player that can be controlled via D-Bus/MPRIS – that is, with just about any music player on Linux. We tested VLC, Audacious, Lollypop (Figure 2), and the still quite young Gnome Music player.
The only problem here is the correct spelling: You have to write the options rhythmbox
or vlc
in lowercase. Lollypop
, on the other hand, must start with an uppercase letter, and for Gnome Music you must specify the D-Bus name org.gnome.Music
. Otherwise, the program thinks that the desired player would not run (Listing 3).
Listing 3
Lyrics-in-terminal
$ lyrics $ lyrics rhythmbox $ lyrics vlc $ lyrics Lollypop $ lyrics org.gnome.Music
If linking to the desired player does not work right away, you need to check whether you first have to enable support for MPRIS in the player itself. Then experiment with the different spellings if necessary.
As a tip, to avoid the need to specify the audio player as an option, it is a good idea to create an alias for the lyrics
command. To do this, edit the shell's configuration, which is usually the ~/.bashrc
file, and add an entry such as:
alias lyrics='lyrics Lollypop'
After restarting the terminal program, the requirement to specify your preferred player is then dropped.
You can determine the D-Bus name quite easily using a D-Bus debugger like D-Feet [4]. This program is included in the official package sources of most distributions. After launching the application, first switch to the Session Bus in the header of the window and then enter the name of the player in the search field in the left sidebar. The name then appears as a search result; on the right in the display area, the name can then also be copied and pasted to the clipboard (Figure 3).
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.