The only command line solution for gapless playback I found so far (working with ALSA and JACK) is moc (»music on console«). While I'm still searching for a simpler way I was wondering if it is possible to loop an audio file into a new file for a given number of times?

Something like:

loop-audio infile.flac --loop 32 outfile.flac

for repeating infile.flac 32 times into outfile.flac

2 Answers 2


Sometimes it is just good to know that linux-life can be as easy as imagined, in this case by using SoX (Sound eXchange):

sox infile.flac outfile.flac repeat 32

this even works with different file formats like:

sox infile.flac outfile.mp3 repeat 32

would loop into a 128 kbps MP3

other bit rates can be set using the option:

-C|--compression FACTOR  Compression factor for output format

getting an 320 kbps MP3 would be obtained with this command:

sox infile.flac -C 320 outfile.mp3 repeat 32

and finally a simple gapless playback from the command line with mpv:

mpv --loop-file infile.flac

or the same even simpler:

mpv --loop infile.flac
  • 2
    Or even simplier just in one line: play test.wav repeat 15
    – JavaRunner
    Apr 23, 2021 at 7:04
  • 1
    mpv is not gapless. Oct 31, 2021 at 12:19
  • play is a bit better, but still not perfect. Oct 31, 2021 at 12:21

I had the same question and wanted actual gapless. I use this solution:

  1. download and use Music On Consol (moc)
  2. mocp -S && sleep 5s && mocp -o r -u s,n && mocp -l /path/to/your.file

adapted from this moc forum answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .