Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 批处理两个有一个字母差异的WAV文件?_Batch File_Cmd_Filenames_Sox - Fatal编程技术网

Batch file 批处理两个有一个字母差异的WAV文件?

Batch file 批处理两个有一个字母差异的WAV文件?,batch-file,cmd,filenames,sox,Batch File,Cmd,Filenames,Sox,如何批处理名称相同的文件,减去单个字母的差异(c或t) 使用sox,此代码会降低一个麦克风文件的音量,然后将两个文件合并到一个新文件中: sox -v 0.43 tree.wav -m close.wav output.wav 我需要使用原始文件名输出到子文件夹,或者更糟的情况是只覆盖原始c文件。这是我对AlexP代码的编辑。它对文件没有任何作用(可能是我的错)。如果我只想将所有文件至少放在同一个子目录中,那么使用“merged\”是否正确 @echo off setlocal

如何批处理名称相同的文件,减去单个字母的差异(
c
t

使用
sox
,此代码会降低一个麦克风文件的音量,然后将两个文件合并到一个新文件中:

sox -v 0.43 tree.wav -m close.wav output.wav

我需要使用原始文件名输出到子文件夹,或者更糟的情况是只覆盖原始
c
文件。

这是我对AlexP代码的编辑。它对文件没有任何作用(可能是我的错)。如果我只想将所有文件至少放在同一个子目录中,那么使用“merged\”是否正确

    @echo off
    setlocal enableextensions disabledelayedexpansion
    rem
    rem Run this script in the directory where the _c_ and _t_ files reside.
    rem
    for %%f in (*_c_*.wav) do call :processOneFile "%%~f"
    exit /b

:processOneFile

    setlocal
    echo;- Looking at "%~nx1"
    cd /d "%~dp1"
    set "fileNameC=%~nx1"
    rem
    rem Now %fileNameC% is the name of the file with _c_. Calculate the name
    rem of the corresponding file with _t_ and check that it actually exists.
    rem
    set "fileNameT=%fileNameC:_c_=_t_%"
    if not exist "%fileNameT%" (
      echo;  Cannot find "%fileNameT%"
      echo;
      exit /b
    )
    echo;  Found "%fileNameT%"
    rem
    rem Calculate the name of the output file and the name of the subdirectory.
    rem This example code makes the name of the output file by replacing
    rem _c_ with _ in the name of %fileNameC%, and makes the name of the
    rem subdirectory by deleting the extension .wav from the name of the output
    rem file. Adjust to suit your needs.
    rem
    set "fileNameOut=%fileNameC:_c_=_%"
    for %%d in ("%fileNameOut%") do set "subDirName=%%~nd"
    rem
    rem Create the subdirectory %subDirName% if it does not exist. If the
    rem subdirectory already contains a file named %fileNameOut% delete it.
    rem
    mkdir "%subDirName%" >nul 2>nul
    del "%subDirName%\%fileNameOut%" >nul 2>&1
    rem
    rem Do something with "%fileNameC%" and "%fileNameT%" producing an output
    rem file %subDirName%\%fileNameOut%.
    rem I don't know what you want to do with them, maybe
    rem sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "%subDirName%\%fileNameOut%"
    rem
    rem Insert your command here.
    rem
    echo;
    rem
    rem All done with these two files, return to the main loop to process the
    rem next two.
    rem
    exit /b
@echo off
  setlocal enableextensions disabledelayedexpansion
  for %%f in (*_c_*.wav) do call :processOneFile "%%~f"
  exit /b

:processOneFile

  setlocal
  echo;- Looking at "%~nx1"
  cd /d "%~dp1"
  set "fileNameC=%~nx1"

  set "fileNameT=%fileNameC:_c_=_t_%"
  echo;  Found "%fileNameT%"

  mkdir mixed >nul 2>&1

  set "fileNameOut=%fileNameC:_c_=_%"
  echo;  Running sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "mixed\%fileNameOut%"
  sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "mixed\%fileNameOut%"
  echo;
  exit /b
对不起,原来的问题不够清楚。我对第一个回答作了一些澄清性的评论。我希望这有帮助。如果需要的话,我很乐意澄清更多-肖恩

@AlexP @斯蒂芬

它工作得很好!:)

无论出于什么原因,它都无法与自定义文件名一起工作。无论如何我都不想删除分隔符(说来话长),所以我只使用了相同的文件名,现在它可以工作了。这是代码,如果其他人可以使用它

@echo off
  setlocal enableextensions disabledelayedexpansion
  for %%f in (*_c_*.wav) do call :processOneFile "%%~f"
  exit /b

:processOneFile

  setlocal
  echo;- Looking at "%~nx1"
  cd /d "%~dp1"
  set "fileNameC=%~nx1"

  set "fileNameT=%fileNameC:_c_=_t_%"
  echo;  Found "%fileNameT%"

  mkdir mixed >nul 2>&1

  echo;  Running sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "mixed\%fileNameOut%"
  sox -v 0.43 "%fileNameT%" -m "%fileNameC%" "mixed\%fileNameC%"
  echo;
  exit /b

对不起,那个讨厌的家伙。我通常讨厌人们不使用另一种我不太懂的语言。所以我明白了。我只是不知道从哪里开始,读这本书简直是在折磨我的大脑。无论如何,感谢大家的帮助,也感谢AlexP提供的解决方案!:)-肖恩

你试过什么?这不是代码请求站点。你需要帮助我们,帮助你。老实说,我不知道你在说什么。您的示例甚至与文件名不匹配。您希望子文件夹的名称是什么?编辑问题并举例说明。
BML201\u solohorn\u longs\u legato\u ff\u RR1\u G4
可以吗?您希望输出文件的名称是什么?
BML201_solohorn_longs_legato_ff_RR1_G4\BML201_solohorn_longs_legato_ff_RR1_G4.wav
可以吗?@Stephan我道歉。希望这有助于澄清:
sox-v0.43*\u c_*.wav-m*\u t_*.wav output.wav
I在一个文件夹中有数千个文件。一半有
\u c\u
,另一半有
\u t\u
。我正在尝试将其他相同的文件名合并到“合并”子目录中。如果有助于理解,则
\u t\u
\u c\u
表示来自同一录音会话的不同话筒。我正在降低“树”文件的体积,然后与“关闭”文件合并(或混合)。这是一个采样仪器,一个虚拟的法国喇叭。如果我还是太含糊,我很抱歉。谢谢你的帮助。所有文件都可以进入名为“合并”的同一子文件夹。两个文件都将始终被找到。我试着编辑你的代码,但运行时什么也没发生。我知道一种晦涩难懂的脚本语言,所以我很抱歉,这对我来说太粗糙了。我试着把我的脑袋绕到它周围,与其他代码进行比较,并至少进行编辑。我就是不懂。我将在另一个答案中发布我的尝试。
如果我只想将所有文件至少放在同一子目录中,我使用“merged\”是否正确?
取决于
sox
是否接受它-请尝试。附言:这似乎是一个附加问题,而不是答案,很可能会被删除。请将代码和附加问题包含在问题本身中(使其实际与主题相关),您编辑的内容太多。我已经编辑了你的答案。如果您在原始文件所在的目录中运行此代码,您应该至少会看到
-查看BML201_solohorn_longs_legato_ff_RR1_c_G4.wav
找到BML201_solohorn_longs_legato_ff_RR1_t_G4.wav
以及显示的任何消息
sox
@echo off
  setlocal enableextensions disabledelayedexpansion
  for %%f in (*_c_*.wav) do call :processOneFile "%%~f"
  exit /b

:processOneFile

  setlocal
  echo;- Looking at "%~nx1"
  cd /d "%~dp1"
  set "fileNameC=%~nx1"

  set "fileNameT=%fileNameC:_c_=_t_%"
  echo;  Found "%fileNameT%"

  mkdir mixed >nul 2>&1

  echo;  Running sox -v 0.43 "%fileNameC%" -m "%fileNameT%" "mixed\%fileNameOut%"
  sox -v 0.43 "%fileNameT%" -m "%fileNameC%" "mixed\%fileNameC%"
  echo;
  exit /b