【问题标题】:Batch process two WAV files with one letter difference?批处理两个有一个字母差异的WAV文件?
【发布时间】:2019-01-30 07:56:17
【问题描述】:

如何批量处理名称相同但减去一个字母差异(ct)的文件?

BML201_solohorn_longs_legato_ff_RR1_c_G4.wav
BML201_solohorn_longs_legato_ff_RR1_t_G4.wav
BML201_solohorn_shorts_staccato_ff_RR2_c_C#3.wav
BML201_solohorn_shorts_staccato_ff_RR2_t_C#3.wav

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

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

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

【问题讨论】:

  • 你试过什么?这不是代码请求站点。你需要帮助我们,帮助你。
  • 老实说,我不知道你在说什么。您的示例甚至与您的文件名不匹配。
  • 您希望子文件夹的名称是什么?编辑问题并举个例子。 BML201_solohorn_longs_legato_ff_RR1_G4 可以吗?您希望输出文件的名称是什么? BML201_solohorn_longs_legato_ff_RR1_G4\BML201_solohorn_longs_legato_ff_RR1_G4.wav 可以吗?
  • @Stephan 我很抱歉。希望这可能有助于澄清:sox -v 0.43 *_c_*.wav -m *_t_*.wav output.wav 我在一个文件夹中有数千个文件。一半有_c_,另一半有_t_。我正在尝试将其他相同的文件名合并到“合并”子目录中。如果有助于理解,_t__c_ 代表来自同一录音会话的不同麦克风。我正在降低“树”文件的音量,然后与“关闭”文件合并(或混合)。这是一个采样乐器,一个虚拟圆号。如果我还是太含糊,我很抱歉。

标签: batch-file cmd filenames sox


【解决方案1】:

@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

很抱歉成为那个讨厌的害​​虫。我通常讨厌人们不使用我半懂的另一种语言来帮助自己。所以我明白了。我只是不知道从哪里开始,阅读 Batch 正在谋杀我的大脑。无论如何,感谢大家的帮助,感谢 AlexP 的解决方案! :) -肖恩

【讨论】:

    【解决方案2】:
        @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
    

    【讨论】:

    • 感谢您的帮助。所有文件都可以进入同一个名为“merged”的子文件夹。将始终找到这两个文件。我尝试编辑您的代码,但运行它时没有任何反应。我知道一种晦涩的脚本语言,所以我很抱歉,这对我来说非常原始。我试图绕过它,与其他代码进行比较,并至少进行编辑。我只是一无所知。我将在另一个答案中发布我的尝试。
    【解决方案3】:

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

    @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
    

    抱歉,原始问题不够明确。我用一些澄清的评论回答了第一个答案。我希望这有帮助。如果需要,我很乐意澄清更多。 -肖恩

    【讨论】:

    • Am I correct in using "merged\" if I just want to put all files in the same subdirectory at least? 取决于sox 是否接受 - 试试吧。 PS:这似乎是一个附加问题,而不是答案,很可能会被删除。请在问题本身中包含代码和其他问题(使其真正成为主题)
    • 你编辑的太多了。我已经编辑了你的答案。如果您在原始文件所在的目录中运行此代码,您应该至少看到- Looking at BML201_solohorn_longs_legato_ff_RR1_c_G4.wavFound BML201_solohorn_longs_legato_ff_RR1_t_G4.wav 以及sox 显示的任何消息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多