A modern, local-first music library and player for Linux, with a built-in MCP server that lets your AI agent act as a local-only DJ. Playback and voice generation run on your machine. Your music stays where it is.
The player needs Python 3.11+, mpv, ffmpeg, PyGObject, and PipeWire. DJ announcements are optional and additionally need an MCP compatible agent and one of the supported speech engines: Reverb-TTS (recommended), Piper, or espeak-ng (last-resort, robotic).
Ubuntu 22.04 ships Python 3.10 and needs a newer Python before installation.
Debian / Ubuntu
sudo apt install python3 python3-venv python3-gi gir1.2-glib-2.0 mpv ffmpegArch Linux
sudo pacman -S python python-gobject mpv ffmpeg pipewire wireplumbergit clone https://github.com/Drewlius/refrain.git
cd refrain
./install.sh
.venv/bin/refrainmkdir -p ~/.local/share/applications
sed "s|Exec=refrain|Exec=$PWD/.venv/bin/refrain|" data/refrain.desktop \
> ~/.local/share/applications/refrain.desktopThe installer creates and configures .venv, installs the player and MCP server, then verifies Python, PyGObject, PySide6, and libmpv.
To install the speech engine choose one of or both, I recommend --with-reverb:
./install.sh --with-piper
./install.sh --with-reverb- you can download both at the same time with
./install.sh --with-reverb --with-piper --with-reverbrequires manual setup and you must provide a clear audio voice clip for the voice, approx. 10s long.--with-piperdownloads a default voice: Ryan (its decent enough).
On first launch, select Add Folder and import your music library. Files are not copied. The SQLite library at ~/.local/share/refrain/library.db links to your files where they already exist.
This is the fun part. Refrain ships a local MCP server (refrain-mcp). An AI agent can search your library, create playlists from your listening habits, control the queue, and speak DJ announcements with a Text-To-Speech voice.
See the complete DJ setup guide for voice installation, agent configuration, testing, and troubleshooting.
The agent starts refrain-mcp automatically over stdio.
An easy way to set up for OpenCode:
- Add
--globalbefore the--to make Refrain available in every project.
opencode mcp add refrain -- /absolute/path/to/refrain/.venv/bin/refrain-mcpYou can also merge this into opencode.jsonc:
- to reload OpenCode configuration Run
/reloadfrom within opencode, oropencode reloadfrom a terminal. Then checkopencode mcp list, or/mcpfrom within opencode, for connection status. You should see refrain in that list if setup properly. - You will need to manually edit the MCP configuration if you have a non-OpenCode agent. Register the same executable as a local mcp server.
- As long as your agent can have local mcp servers configured you should be able to get it to work.
Install with ./install.sh --with-reverb, then open, in the app Settings > DJ Voice. Supply approximately 10 seconds of clear reference audio, then manually type its exact transcript. Choose a model quality. int8 is recommended; use fp32 for
best quality. Save, then click Test Voice.
- Non-WAV clips are converted automatically with ffmpeg.
- The first run downloads model weights from Hugging Face, later announcements run locally.
Install with ./install.sh --with-piper. Our default voice: Ryan.Choose any installed voice and adjust pitch in Settings > DJ Voice.
Install the espeak-ng system package as a fallback. It works without a Python speech package but sounds robotic.
search_tracks library_stats list_playlists
create_playlist add_tracks_to_playlist get_playlist
delete_playlist top_tracks play_history
playback_control play_file play_playlist
play_tracks playback_status announce
queue_announcement clear_announcements
play_playlistandplay_tracksreplace the app's queue.playback_control playonly resumes the existing queue.queue_announcementschedules a single announcement for a track ID. Refrain prepares it before a sequential track change, ramps music down to 25 percent, speaks during the transition, then ramps the next track back up. Multiple announcements for one track play in order.clear_announcementscancels waiting announcements for one track or the whole queue. The native queue is in-memory and clears when Refrain exits.announcespeaks a one-off interruption immediately.- All announcements use the volume ramp automatically. Each queued announcement is limited to 500 characters.
- Extensions:
.mp3,.m4a/aac,.mp4,.flac,.ogg/.vorbis,.oga,.opus, and.wav.
Import folders without copying anything. The SQLite database links to your files where they already exist. Right-click a track and choose Remove from Library to remove its database entry without deleting the audio file. You can also prevent that track from being imported again during rescans.
MPV sends audio through PipeWire to your output device.
- Shuffle and repeat: shuffle on or off, repeat off, all, or one.
- Equalizer: 10 bands from 31 Hz to 16 kHz plus preamp, presets, live apply, and persistent settings. The filter chain runs inside mpv.
- Custom playlists: create your own, or ask your agent to build them and act as your DJ.
- Play history: qualified listens update the Plays column and help your agent curate playlists around what you actually listen to.
Editable Tags: title, artist, album, album artist, genre, year, and track number.
- Implementation: Refrain writes to a temporary copy, verifies it, then swaps it in. A failed write leaves the original file untouched.
KDE/GNOME media module support, keyboard media key support, and system tray integration so you can close the window without ending playback.
Theme can follow your desktop light/dark theme, or you can choose one of the themes listed below:
Refrain Dark,Refrain Light,Catppuccin Mocha, orNord.
ListenBrainz Scrobbling can be enabled in Settings with a token from ListenBrainz. Refrain submits what's playing-now and completed listens after half the track or 4 minutes, whichever comes first. This is off by default.
Install the dev. dependencies and run the pytest's:
./install.sh --dev
.venv/bin/python -m pytest- Tests generate real audio files with ffmpeg and play them through a null output, so playback and the equalizer are tested without firing your speakers.
- Pytest prints assertion failures and captured errors. Use
-vvfor verbose output and--log-cli-level=INFOshows live application logs while the test run.
./refrain/
install.sh first-run installer and dependency verification
src/refrain/
library.py SQLite library, scanner, removals, and play history
tags.py tag reading and verified tag writes
player.py mpv playback engine with PipeWire output
eq.py 10-band EQ and preamp filter-chain builder
mpris.py MPRIS2 D-Bus service
control.py local Unix socket for queue and refresh commands
tts.py Piper, Reverb, and espeak announcements
mcp_server.py MCP tools for library, playlists, playback, and DJ tools
theme.py palettes, QSS, and system light/dark detection
ui/ main window, dialogs, and native announcement playback
docs/dj-setup.md complete DJ and MCP setup guide
Refrain's code is available under the MIT License. Dependencies and voice models keep their own licenses. In particular, Reverb-TTS weights are CC BY-NC 4.0 and cannot be used commercially.
Feel free to make any contributions to this project. I will review and likely merge them.
- Hope you enjoy Refrain and the DJ integration.
If you have any issues with setup, open an issue report or email me with the error, your Linux distribution, and your Python version.
hello@drewdev.link
{ "$schema": "https://opencode.ai/config.json", "mcp": { "servers": { "refrain": { "type": "local", "command": ["/absolute/path/to/refrain/.venv/bin/refrain-mcp"], "disabled": false, "pool": true, "codemode": false } } } }