|
| 1 | +import os |
| 2 | +import glob |
| 3 | +import copy |
| 4 | +import subprocess |
| 5 | + |
| 6 | +def getFilesInDirWithExt(dir, ext): |
| 7 | + toreturn = [] |
| 8 | + os.chdir(dir) |
| 9 | + for file in glob.glob(ext): |
| 10 | + toreturn.append(dir + file) |
| 11 | + return toreturn |
| 12 | + |
| 13 | +batchTemplate = [] |
| 14 | +with open('D:\\jAudio\\batchfiles\\template.xml') as f: |
| 15 | + batchTemplate = f.readlines() |
| 16 | + |
| 17 | +mainpath = "F:\\fma_large\\" |
| 18 | + |
| 19 | +allAudioFolders = os.listdir(mainpath) |
| 20 | + |
| 21 | +# Need to create all batch files first. |
| 22 | +for num in allAudioFolders: |
| 23 | + |
| 24 | + folder = mainpath + num + "\\" |
| 25 | + wavFilesInFolder = getFilesInDirWithExt(folder, "*.wav") |
| 26 | + |
| 27 | + output = batchTemplate[0:27] |
| 28 | + output.append("\t<batch ID=\"" + num + "\">\n") |
| 29 | + |
| 30 | + fileSetStrings = [] |
| 31 | + fileSetStrings.append("\t\t<fileSet>\n") |
| 32 | + for wavFile in wavFilesInFolder: |
| 33 | + fileSetStrings.append("\t\t\t<file>" + wavFile + "</file>\n") |
| 34 | + fileSetStrings.append("\t\t</fileSet>\n") |
| 35 | + output.extend(fileSetStrings) |
| 36 | + output.extend(batchTemplate[31:770]) |
| 37 | + output.append("\t\t<destination>" + "D:\\jAudio\\fma_large\\" + num + ".arff</destination>\n") |
| 38 | + output.append("\t\t<destination>" + "D:\\jAudio\\fma_large\\" + num + ".arff</destination>\n") |
| 39 | + output.extend(batchTemplate[772:775]) |
| 40 | + |
| 41 | + with open('D:\\jAudio\\batchfiles\\' + num + ".xml", 'w') as f: |
| 42 | + f.writelines(output) |
| 43 | + |
| 44 | + |
| 45 | +# run batch files! |
| 46 | +batchFileDir = "D:\\jAudio\\batchfiles\\" |
| 47 | +allBatchFiles = os.listdir(batchFileDir) |
| 48 | + |
| 49 | +for batchFile in allBatchFiles: |
| 50 | + if not (batchFile == "template"): |
| 51 | + thisBatchFile = batchFileDir + batchFile |
| 52 | + os.chdir("D:\\jAudio") |
| 53 | + FNULL = open(os.devnull, 'w') |
| 54 | + subprocess.call('java -mx500M -jar jAudio-1.0.4.jar -b ' + thisBatchFile, shell=True, stdout=FNULL, stderr=subprocess.STDOUT) |
| 55 | + |
| 56 | + |
| 57 | + |
0 commit comments