Skip to content

A go application to play the same music on multiple devices at (exactly) the same time.

License

Notifications You must be signed in to change notification settings

LogicalOverflow/music-sync

Repository files navigation

Build Status Coverage Status Codacy Grade Code Climate Issues Code Climate Maintainability GitHub Release Version GoDoc Reference License

Music Sync

A go application to play the same music on multiple devices at once. It works best when all playing devices are similar, to avoid differences in the time it takes the audio to be played. I usually test the timing with two Windows 7 machines, one x64, one x86 to ensure the timing difference between the devices is small enough that hearing 2 different devices playing music sounds like one.

Installation

To install do go get github.com/LogicalOverflow/music-sync/... or download the executable from the latest release.

Getting Started

After installing, create a directory named audio and put your audio files into it. Also, create a users.json containing at least one username and password/public key of your choice:

{
    "username": {
        "password": "a password",
        "pubKey": "a public key formatted for use in the SSH wire protocol (RFC 4253, section 6.6)"
    }
 }

If you want, you can add lyrics information to your songs. To add lyrics to a song called song.mp3, create a file called song.mp3.json next to the mp3 file containing the lyrics:

[
    [
        {
            "timestamp": 1234,
            "caption": "The first "
        },
        {
            "timestamp": 5678,
            "caption": "line of lyrics."
        }
    ],
    [
        {
            "timestamp": 9101,
            "caption": "The second "
        },
        {
            "timestamp": 10112,
            "caption": "line."
        }
    ]
]

Here, timestamps are in milliseconds from the start of the song, each array describes a line of lyrics and each object in those arrays a word/phrase/syllable in the lyrics.

Then you can start a local music-sync-server using music-sync-server. By default, this server listens on 127.0.0.1:13333 (--address, --port) for clients and provides a ssh terminal on 127.0.0.1:13334 (--ssh-address, --ssh-port) to control the server. By default, the server checks in it's working directory for a file called id_rsa to use as a host key (--host-key-file). If this file is not found a new host key is generated on every startup. For more options check music-sync-server --help.

To start a player use music-sync-player. By default this tries to connect to a server at 127.0.0.1:1333 (--address, --port). For more options check music-sync-player --help.

To get information about the current song playing and lyrics (if provided) in a terminal UI, you can use music-sync-infoer. By default this tries to connect to a server at 127.0.0.1:1333 (--address, --port). For more options check music-sync-infoer --help.

The ssh terminal on the server is used to control the server. The usernames and passwords are read from users.json (--users-file). You can manage the current playlist, pause and resume playback and set the playback volume for all clients. These commands are available:

  • queue filename [position] - Adds filename to the playlist at position or the end. You can use glob patterns to add multiple files.
  • remove position - Removes the song at position from the playlist
  • jump position - Jumps to position in the playlist, interrupting the current song
  • playlist - Prints the current playlist
  • pause - Pauses playback
  • resume - Resumes playback
  • volume volume - Sets the playback volume for all clients (volume should be between 0 and 1)
  • help [command] - Prints all commands or information and usage of command
  • ls [sub-directory] - Lists all songs in the music (sub-)directory
  • clear - Clears the terminal
  • exit - Closes the connection

Spaces in commands can be escaped using \ . To escape a backslash before a space use \\ , otherwise the backslash does not need to be escaped.