Skip to content
DrewliusPublic

About

A 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

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

39 Commits

Folders and files

Repository files navigation

Refrain

Refrain hero banner 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.


Requirements

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 ffmpeg
Arch Linux
sudo pacman -S python python-gobject mpv ffmpeg pipewire wireplumber

Install / run

git clone https://github.com/Drewlius/refrain.git
cd refrain
./install.sh
.venv/bin/refrain

Optional launcher integration:

mkdir -p ~/.local/share/applications
sed "s|Exec=refrain|Exec=$PWD/.venv/bin/refrain|" data/refrain.desktop \
  > ~/.local/share/applications/refrain.desktop

The 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-reverb requires manual setup and you must provide a clear audio voice clip for the voice, approx. 10s long.
  • --with-piper downloads 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.


DJ mode

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.

MCP configuration

An easy way to set up for OpenCode:

  • Add --global before the -- to make Refrain available in every project.
opencode mcp add refrain -- /absolute/path/to/refrain/.venv/bin/refrain-mcp

You can also merge this into opencode.jsonc:

{
  "$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
      }
    }
  }
}
  • to reload OpenCode configuration Run /reload from within opencode, or opencode reload from a terminal. Then check opencode mcp list, or /mcp from 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.

Voices

Reverb-TTS (Recommended)

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.

Piper

Install with ./install.sh --with-piper. Our default voice: Ryan.Choose any installed voice and adjust pitch in Settings > DJ Voice.

espeak-ng (last resort)

Install the espeak-ng system package as a fallback. It works without a Python speech package but sounds robotic.


MCP Tools

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

Notes

  • play_playlist and play_tracks replace the app's queue. playback_control play only resumes the existing queue.
  • queue_announcement schedules 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_announcements cancels waiting announcements for one track or the whole queue. The native queue is in-memory and clears when Refrain exits.
  • announce speaks a one-off interruption immediately.
  • All announcements use the volume ramp automatically. Each queued announcement is limited to 500 characters.

Features

Format Support

  • Extensions: .mp3, .m4a/aac, .mp4, .flac, .ogg/.vorbis, .oga, .opus, and .wav.

Library

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.

Playback

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.

Tag editor

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.

Built-in Desktop Integration

KDE/GNOME media module support, keyboard media key support, and system tray integration so you can close the window without ending playback.

Theming

Theme can follow your desktop light/dark theme, or you can choose one of the themes listed below:

  • Refrain Dark, Refrain Light, Catppuccin Mocha, or Nord.

Optional ListenBrainz scrobbling

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.


Tests

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 -vv for verbose output and --log-cli-level=INFO shows live application logs while the test run.

Layout

./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

License

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.


Footnotes

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

About

A 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

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages