简体   繁体   English

使用sox批量修剪wav文件

[英]batch trim wav files using sox

I am trying to batch trim audio files (wav) using sox, trimming first 15 seconds 我正在尝试使用sox批处理音频文件(wav),在前15秒内进行修剪

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 当我在单个文件上运行以下命令时,它会通过在同一文件夹中创建文件“ snipped.wav”减去前15秒而起作用

@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. 您以错误的方式使用了for循环。 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). 您需要使用*.wav (表示当前文件夹中所有以“ .wav”结尾的文件)或* (表示当前文件夹中的所有文件)之类的东西。 You also may want to use %%~A inside your double quotes too. 您可能还希望在双引号中使用%%~A 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. 如果周围的双引号已经出现在%%A ,它将删除双引号,否则您可能会有双双引号(例如, ""this should be one string"" ),并且双引号的作用也将被撤消。 And are you sure about the "trimmed\\%%~nA" part? 您确定"trimmed\\%%~nA"部分吗? With the ~n you're leaving out the extension of the filename (if %%A would be original.wav , %%~nA will become original ). 使用~n您将省略文件名的扩展名(如果%%A将是original.wav ,则%%~nA将成为original )。 Use ~nx if you want filename and the extension at the end (see link at the end). 如果要在结尾加上文件名和扩展名,请使用~nx (请参阅结尾处的链接)。
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" 如果您确实希望将扩展名包含在"trimmed\\%%~nA" "trimmed\\%%~nxA"部分中,请替换为"trimmed\\%%~nxA"

This link talks about the different for-loops in batch. 此链接批量讨论了不同的for循环。
This link talks about the different path manipulation techniques you can use on arguments and loop-variables 该链接讨论了可以在参数和循环变量上使用的不同路径操作技术

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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