1

If you answer I'll give you a cookie!

I am using sox to convert MP3 files to a WAV on the fly for pifm. The only thing is, I am doing it to a whole directory of MP3s, and because not all of them have the same sample rate the command fails.

Is there a way to resample the audio files, pipe it into the convert-to-wav-on-the-fly, and then pipe it into pifm?

My current command is:

sox -t mp3 /home/pi/Desktop/music/*.mp3 -t wav - |
sudo ./pi_fm_rds -freq 94.5  -audio - -ps ZSFM -rt ZSFM

But this gives me:

sox WARN mp3-util: MAD lost sync
sox WARN mp3-util: MAD lost sync
sox FAIL sox: Input files must have the same sample-rate

So I want to have sox resample each file on the fly, then pipe it into sox to convert it on the fly.

Also, if I try:

sox -r 44100-t mp3 /home/pi/Desktop/music/*.mp3 -t wav - |
sudo ./pi_fm_rds -freq 94.5  -audio - -ps ZSFM -rt ZSFM

It still does not work, because the sampling rates for the files in that directory are not the same.

2
  • Not tested, but as man sox says, try putting the options for the outfile before the outfile: sox -t mp3 /home/pi/Desktop/music/*.mp3 -t wav -r 44100 -. If that doesn't work, you need an effect; the man page suggests rate.
    – dirkt
    Jun 17, 2021 at 10:01
  • @dirkt That worked. Thanks!
    – KJs
    Jun 18, 2021 at 6:47

2 Answers 2

1

Thanks @dirkt and @Thor

@dirkt answered:

sox -t mp3 /home/pi/Desktop/music/*.mp3 -t wav -r 44100 - | sudo ./pi_fm_rds -freq 94.5  -audio - -ps ZSFM -rt ZSFM

@Thor answered:

for tune in *.mp3; do 
  sox $tune -t wav - rate 44100
done |
sudo ./pi_fm_rds -freq 94.5  -audio - -ps ZSFM -rt ZSFM

Both worked!

0

Here is one workaround you could use (assuming your files are named sensibly):

for tune in *.mp3; do 
  sox $tune -t wav - rate 44100
done |
sudo ./pi_fm_rds -freq 94.5  -audio - -ps ZSFM -rt ZSFM
...
1
  • Thanks! That also worked, but I went with the other answer because I am a linux beginner and don't totally understand how that works. I will try to look inti it now!
    – KJs
    Jun 18, 2021 at 6:51

You must log in to answer this question.

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