百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

go-librespot

> 编程语言
开源

又一个使用 Go 编写的 开源 Spotify 客户端。

345 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

又一个使用 Go 编写的 开源 Spotify 客户端。

go-librespot

Yet another open-source Spotify Connect compatible client, written in Go.

go-librespot gives you the freedom to have a Spotify Connect device wherever you want.

Features • Getting Started • Configuration • Development

Features

  • Spotify Connect — show up as a speaker in the Spotify app and stream to it from any device on your network (Spotify Premium required).
  • Multiple audio backends — ALSA, PulseAudio, AudioToolbox on macOS, WASAPI on Windows, or a raw named pipe for custom routing.
  • Loudness normalization — Spotify-standard −14 LUFS (ITU-R BS.1770) with configurable pregain.
  • Crossfade — configurable overlap between consecutive tracks.
  • ️ Podcast resume — episodes pick up where you left off, and progress syncs back to your other devices.
  • DJ X — Spotify's AI DJ, narration included: the spoken lines are synthesized and played around each track.
  • ️ Flexible volume control — independent, synchronized with the ALSA mixer, or fully external.
  • On-disk audio cache — skip re-downloading tracks, bounded by an LRU size limit.
  • Multiple login flows — Zeroconf discovery, interactive OAuth, or a Spotify access token.
  • Selectable mDNS backend — the built-in responder or the system Avahi daemon.
  • REST API + WebSocket events — control and monitor playback programmatically.
  • ️ MPRIS integration — control playback over D-Bus / standard Linux media keys.
  • Lightweight & portable — a single Go binary, ideal for Raspberry Pi and other embedded devices.

Getting Started

Using prebuilt binary

To get started you can download prebuilt binaries for the latest release.

Development prebuilt binaries are also available as GitHub Actions artifacts.

Using Docker

A lightweight Docker image for go-librespot is available on the GitHub Container Registry.

An example Docker Compose configuration for PulseAudio is available here.

Using Brew

You can also install go-librespot using Brew on macOS and Linux (thanks @kriive):

bash
brew install go-librespot

Building from source

To build from source the following prerequisites are necessary:

  • Go 1.25 or higher
  • Libraries: libogg, libvorbis, flac, mpg123 (plus libasound2 on Linux)

To install Go, download it from the Go website.

To install the required libraries on Debian-based systems (Debian, Ubuntu, Raspbian), use:

bash
sudo apt-get install libogg-dev libvorbis-dev libflac-dev libmpg123-dev libasound2-dev

On Windows the default backend is WASAPI (default playback device). Install the decode libraries as MinGW packages (MSVC .lib files will not link with CGO), for example with MSYS2:

pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-pkg-config mingw-w64-x86_64-libogg mingw-w64-x86_64-libvorbis mingw-w64-x86_64-flac mingw-w64-x86_64-mpg123

Cross-compiling a static windows/amd64 binary with vcpkg is described in CROSS_COMPILE.md.

Once prerequisites are installed you can clone the repository and run the daemon with:

bash
go run ./cmd/daemon

Details about cross-compiling go-librespot are described here (thank you @felixstorm).

Configuration

The default directory for configuration files is ~/.config/go-librespot. On macOS this is ~/Library/Application Support/go-librespot. On Windows it is %APPDATA%\go-librespot. You can change this directory with the -config_dir flag. The configuration directory contains:

  • config.yml: The main configuration (does not exist by default)
  • state.json: The player state and credentials
  • lockfile: A lockfile to prevent running multiple instances on the same configuration

The full configuration schema is available here, only the main options are detailed below.

Zeroconf Mode and mDNS Backend Selection

Zeroconf mode enables mDNS auto discovery, allowing Spotify clients inside the same network to connect to go-librespot. This is also known as Spotify Connect.

Backend selection:
go-librespot supports two different backends for mDNS service registration:

  • builtin: (default) Uses the built-in mDNS responder provided by go-librespot itself.
  • avahi: Uses the system's avahi-daemon (via D-Bus) for mDNS service registration.

You can configure which backend to use via the zeroconf_backend setting in your configuration file:

yaml
zeroconf_backend: avahi   # Options: "builtin" (default), "avahi"

Or via the command line:

bash
go-librespot -c zeroconf_backend=avahi

Which backend should I use?

  • Use avahi if you want to integrate with an existing Avahi daemon, e.g. on embedded systems, to avoid port conflicts, or to centralize mDNS advertisements with system service management (e.g., using systemd).
    • Compatible with Avahi 0.6.x and later (tested with 0.7 and 0.8).
  • Use builtin if you do not have Avahi running and want go-librespot to manage its own mDNS advertisements (no extra dependencies required).

Example minimal Zeroconf configuration

yaml
zeroconf_enabled: true # Whether to keep the device discoverable at all times, even if authenticated via other means
zeroconf_port: 0       # The port to use for Zeroconf, 0 for random
zeroconf_backend: avahi
credentials:
  type: zeroconf
  zeroconf:
    persist_credentials: false # Whether to persist zeroconf user credentials even after disconnecting

If persist_credentials is true, after connecting to the device for the first time credentials will be stored locally and you can switch to interactive mode without having to authenticate manually.

If zeroconf_interfaces_to_advertise is provided, you can limit interfaces that will be advertised. For example, if you have Docker installed on your host, you may want to disable advertising to its bridge interface, or you may want to disable interfaces that will not be reachable.

Interactive mode

This mode allows you to associate your account with the device and make it discoverable even outside the network. It requires some manual steps to complete the authentication:

  1. Configure interactive mode

    yaml
    zeroconf_enabled: false # Whether to keep the device discoverable at all times
    credentials:
      type: interactive
  2. Start the daemon to begin the authentication flow

  3. Open the authorization link in your browser and wait to be redirected

  4. If go-librespot is running on the same device as your browser, authentication should complete successfully

  5. (optional) If go-librespot is running on another device, you'll need to copy the URL from your browser and call it from the device, for example:

    bash
    curl http://127.0.0.1:36842/login?code=xxxxxxxx

Device authorization mode

This mode associates your account with the device without a browser on the device itself: Spotify issues a short code which you enter at spotify.com/pair from a phone or computer. Nothing has to listen on a port, so unlike interactive mode there is no redirect URL to copy around when go-librespot runs headless.

  1. Configure device authorization mode

    yaml
    zeroconf_enabled: false # Whether to keep the device discoverable at all times
    credentials:
      type: device_auth
  2. Start the daemon to begin the authentication flow

  3. Open the link it logs, or go to spotify.com/pair and enter the code it prints

  4. Approve the request; the daemon picks it up automatically and stores the credentials

With the API server enabled, the same link and code are also served at GET /auth/code for as long as the daemon is waiting, so a frontend can show them instead of asking the user to read the logs.

API server

Optionally, an API server can be started to control and monitor the player. To enable this feature, add the following to your configuration:

yaml
server:
  enabled: true
  address: localhost # Which address to bind to
  port: 3678 # The server port
  allow_origin: '' # Value for the Access-Control-Allow-Origin header
  cert_file: '' # Path to certificate file for TLS
  key_file: '' # Path to key file for TLS
  image_size: 'default' # Album art image size (default, small, large, xlarge)

For detailed API documentation see here.

Audio cache

Downloaded audio files can be cached on disk so that replaying a track does not download it again from the CDN. Only the raw, still-encrypted files are stored: a cached file is useless without a valid Spotify account, since the audio key is retrieved again on every playback. The cache is disabled by default; once enabled it applies a 1 GB limit, after which the least-recently-used files are evicted.

yaml
cache:
  enabled: false # Whether to cache downloaded audio files (default: false)
  dir: '' # Directory for cached files (default: the XDG cache directory, e.g. $XDG_CACHE_HOME/go-librespot or $HOME/.cache/go-librespot)
  size_limit: '1GB' # Maximum total cache size before evicting least-recently-used files ('0' for unlimited)

Track metadata cache

Optionally, the daemon can cache track metadata (name, artists, cover art) in memory and fetch it — via the same internal API playback uses, not the rate-limited public Web API — for the tracks around the playback position. This enables a next_track field in GET /status and a GET /context/tracks?uri=... endpoint that lists any playable context (playlist, album, artist) in order with metadata, so a client can render a browsable song list and start any entry via POST /player/play with skip_to_uri. Everything is opt-in and disabled by default: a headless speaker has no use for metadata beyond the playing track and should not pay network requests for it.

yaml
metadata:
  enabled: false # Cache + fetch metadata around the playback position; enables next_track and /context/tracks
  context_sweep: false # Also resolve metadata for the whole context when one starts playing (requires enabled)
  max_tracks: 800 # Maximum number of tracks of a context to enumerate and sweep

Volume synchronization

Various configurations for volume control are available:

  1. No external volume without mixer: Spotify volume is controlled independently of the device volume, output samples are multiplied with the volume
  2. No external volume with mixer: Spotify volume is synchronized with the device volume and vice versa, output samples are not volume dependant, Spotify volume changes are applied to the ALSA mixer and vice versa
  3. External volume without mixer: Spotify volume is not synchronized with the device volume, output samples are not volume dependant
  4. External volume with mixer: Device volume is synchronized with Spotify volume, output samples are not volume dependant, volume changes are not applied to the ALSA mixer

Audio normalization

go-librespot implements audio normalization according to Spotify's standards, which targets -14 dB LUFS (Loudness Units relative to Full Scale) based on the ITU-R BS.1770 standard. Source

Normalization can be configured with the following options:

yaml
normalisation_disabled: false # Whether to disable normalization (default: false)
normalisation_use_album_gain: false # Whether to use album gain instead of track gain (default: false)
normalisation_pregain: 0 # Pregain in dB to apply before normalization (default: 0)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goaudio-playerspotifyspotify-connect

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言