简体   繁体   中英

Audio batch trim beginning and end using Sox

How do I merge the two, so multiple files can be processed, with each file trimmed 15 seconds from beginning, and 15 seconds at the end:

@echo off
cd E:\trim\multiplefiles
mkdir trimmed

rem trims 15 seconds from end of each file, and creates a snipped file in 
rem trimmed folder

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

and

@echo off
cd E:\trim\multiplefiles
mkdir trimmed

rem trims 15 seconds from beginning of each file, and creates a snipped file in rem trimmed folder

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

The SoX trim effect allows you to specify both start and duration, and a negative duration specifies an end point measured from the end of the file. So sox infile outfile trim 15 -15 will remove the first 15 seconds and the last 15 seconds from the file.

@echo off
cd E:\trim\multiplefiles
mkdir trimmed

rem trims 15 seconds from beginning and end of each file, putting result in trimmed folder

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

Note that ~nx is not needed in the output specification.

I will assume you can first trim 15 seconds from end of a file, and after that trim 15 seconds from the beginning of the result. Then you can put everything in one loop and use a temporary file like this:

@echo off

cd E:\trim\multiplefiles
mkdir trimmed

FOR %%A IN (*.wav) DO (
    rem trim 15 seconds from end and put it in temporary file
    sox "%%A" "trimmed\temp_%%~nxA" reverse trim 15 reverse
    rem trim 15 seconds from beginning of the temporary file
    sox "trimmed\temp_%%~nxA" "trimmed\%%~nxA" trim 15
    rem delete temporary file
    del "trimmed\temp_%%~nxA"
)

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