简体   繁体   中英

batch trim wav files using sox

I am trying to batch trim audio files (wav) using sox, trimming first 15 seconds

When I run the following on a single file, it works, by creating a file 'snipped.wav' minus first 15 seconds, in the same folder

@echo off
cd E:\trim\singlefile
sox original.wav snipped.wav trim 15

However, when I try the following on multiple files (with processed files after trim should move to 'trimmed' folder), it does not work:

@echo off
cd E:\trim\multiplefiles
mkdir trimmed
FOR %%A IN (%*) DO sox "%%A" "trimmed/%%~nA" trim 15

I guess I am (awfully) wrong somewhere. Please suggest.

You are using the for-loop on a wrong way. You have to provide the files you want to iterate through between the parenthesis. %* actually means "all arguments". You need something like *.wav (which means all files in the current folder ending with ".wav") or * (meaning all files in current folder). You also may want to use %%~A inside your double quotes too. It will remove surrounding double quotes if they already were present in %%A , else you may have double pairs of double quotes (for eg ""this should be one string"" ) and the effect of the double quotes will be undone. And are you sure about the "trimmed\\%%~nA" part? With the ~n you're leaving out the extension of the filename (if %%A would be original.wav , %%~nA will become original ). Use ~nx if you want filename and the extension at the end (see link at the end).
Here is the loop you should have:

FOR %%A IN (*.wav) DO sox "%%~A" "trimmed\%%~nA" trim 15

if you do want to have the extension in the "trimmed\\%%~nA" part, replace it with "trimmed\\%%~nxA"

This link talks about the different for-loops in batch.
This link talks about the different path manipulation techniques you can use on arguments and loop-variables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM