1

I'm running this command on terminal:

for i in $(ls -1 /home/pi/Desktop/Music/Acapella/*.mp3|sort -R); do sox -t mp3 $i -t wav - ; done | sudo ./pi_fm_rds -freq 102.1 -audio - -ps ZSFM -rt "ZSFM" 

Basically, it uses a forloop to go through all the files in a dir and convert them into wav files on-the-fly, and then pipe it into the pifm command. The only problem is, though, after the first file it says:

sox WARN sox: `-' output clipped 773 samples; decrease volume? Could not rewind in audio file, terminating Terminating: cleanly deactivated the DMA engine and killed the carrier 

I'm not sure if its a sox problem or a terminal problem. what does it mean (and how do I fix it)?

I did put 'done' after the pifm command, but then it runs the pifm command once for every file, but I want the pifm command to be constantly running, and the forloop will only go on the file its playing.

1 Answer 1

0

You are giving sox one file. It converts and stream, then ends before getting next file.

You could do it in various of ways. And, no, do not use ls like that

I'm using play for test purpose:

#! /bin/sh - path="/home/pi/Desktop/Music/Acapella/" find "$path" -name '*.mp3' -print0 | sort -z -R | xargs -0 cat | sox -t mp3 - -t wav - | play - 

Here one say

  • find files in $path where -name ends with .mp3 and print file-names separated with \0 zero byte.
  • sort random -R input from pipe / find which is -z zero separated. (Aka shuffle)
  • xargs concatenate files given by -0 zero delimited filenames.
  • sox
    • -t mp3 -: Type mp3 read from stdin (standard in)
    • -t wav -: Type wav write to stdout (standard out)
  • play data from stdin -

If you can guarantee no new-lines in filenames you could also use a temporary playlist. Here M3U, se wiki if you want to go fancy.

#! /bin/sh - # ARG 1 is path path="$1" # Create temporary file to use as playlist playlist="$(mktemp /tmp/sox.XXXXXXXX.m3u)" # Delete playlist on exit trap 'rm "$playlist"' EXIT #Create playlist find "$path" -name '*.mp3' -print | sort -R >"$playlist" sox "$playlist" -t wav - | play - 
2
  • How can I have it shufle the files in the dir without using the ls thing? Commented Jul 5, 2021 at 6:02
  • @horace The files are shuffled using sort -R. In both examples. Commented Jul 5, 2021 at 6:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.