使用Sox开始和结束音频批量修剪

时间:2016-11-26 14:24:57

标签: batch-file

如何合并两者,因此可以处理多个文件,每个文件从开始15秒后修剪,最后15秒:

@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

@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

2 个答案:

答案 0 :(得分:2)

SoX修剪效果允许您指定开始和持续时间,负持续时间指定从文件末尾开始测量的结束点。因此sox infile outfile trim 15 -15将从文件中删除前15秒和最后15秒。

@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

请注意,输出规范中不需要~nx

答案 1 :(得分:1)

我假设您可以先从文件末尾修剪15秒,然后从结果开始15秒后修剪。然后你可以将所有内容放在一个循环中并使用这样的临时文件:

@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"
)