I have a folder with several MP3 files that I need to extract 10-15 seconds of audio from. I would also like to rename these by appending sample-(name).mp3 to the converted files.How can I do this via Shell Script?
Create SOX batch script to extract first 15 seconds and rename multiple files in folder
shell script;audio;mp3;sox
If you want/need to use sox for this you can use its trim command:for i in *.mp3do   sox $i sample-$i trim 0 10doneThe splitting you can also do with the commandline utility that is part of mp3splt. You explicitly set the output file with -o, so the originals are not touched, just remove them after you are done with them. This allows you to incorporate tags defined in the file in the output name than sox does (what you don't seem to need right now):for i in *.mp3do   mp3splt $i 00.00.00 00.10.00 -o sample-${i%.mp3}doneNote that -o normally works with @ based directives to include tag elements in the output name and appends .mp3. Without ${i%.mp3} you would get .mp3.mp3 files.Times are dot separated, don't try to use : instead, you get a less than useful error message that you don't have enough split points.I would not remove the input files until you have tested that the scripts works. Also note that if you stop it halfway, or add files later, that you cannot re-run it without removing any sample- files first. You might want to specify a directory before sample-..., to keep things apart.