Sox and pitch shifting of multiple audio files

I want to change the pitch using sox, of each mp3 in every music folder I have. I wrote this in bash:

function pitch_mp3 { for mp3 in /home/mp3s/*/*.mp3 do cd "$(dirname "$mp3")" output=$(basename "$mp3" .mp3)PITCHED.mp3 sox -S "$mp3" -C 192 "$output" pitch 50 done } 

It adds a step to the example 01song.mp3, and the output file is 01songPITCHED.mp3. But it so happens that sox does the work for the first time, but then it goes by bicycle again to the folders and adds a step to the already laid out mp3 files, so the file name turned out to be 01songPITCHEDPITCHED.mp3. I stopped him when I noticed, so I donโ€™t know if he will add a step a third time, etc.

Why and how to fix it?

+4
source share
2 answers

If you just want to skip any file ending in PITCHED.mp3 , I would use the case statement

 case "$mp3" in *PITCHED.mp3) echo skipping "$mp3" ;; *) #repitch as before ;; esac 
+3
source
 function pitch_mp3 { for mp3 in /home/mp3s/*/*.mp3 do [[ "$mp3" = *PITCHED.mp3 ]] && continue cd "$(dirname "$mp3")" output=$(basename "$mp3" .mp3)PITCHED.mp3 sox -S "$mp3" -C 192 "$output" pitch 50 done } 

I would also do a variable extension, so I didn't have to repeat it, but that's just me.

0
source

Source: https://habr.com/ru/post/1445860/


All Articles