import subprocess import os.path import os from glob import glob open("./listofwavs.txt", 'a').close() with open("listofwavs.txt", "a+") as f: for w in glob('./tp???.wav'): try: tGrid = w.replace('.wav', '.TextGrid') if os.path.isfile(tGrid): write = w.replace('./','') f.write(write); f.write("\n") except OSError: print('cannot open', w) open("./start", 'a').close() with open("start", "a+") as n: n.write("1") open("./rapidEditSp17", 'a').close() with open("rapidEditSp17", "a+") as f: f.write("# This script opens all sound files in the specified text file and associated TextGrids,\n") f.write("# pauses for the user to check and possibly alter the TextGrid,\n") f.write("# then saves the new TextGrid in the same directory if applicable.\n\n") f.write("# Jevon Heath, 5/6/15\n") f.write("#Script adapted by Steven Ho\n") f.write("# Create a list of all sound files in the directory.\n\n") f.write("form Check Textgrids for .wav files listed in this file\n") f.write("\tcomment Name of directory:\n") wd = os.path.dirname(os.path.realpath(__file__)) f.write("\ttext directory " + wd+ "\n") f.write("\tcomment Name of text file:\n") f.write("\ttext textfile listofwavs.txt\n") f.write("endform\n\n") f.write("Read Strings from raw text file... 'directory$'/'textfile$'\n") f.write("fileList$ = selected$ (\"Strings\")\n") f.write("n = Get number of strings\n") f.write("history$ = \"start\"\n") f.write("start = readFile (history$)\n\n") f.write("# Open each sound file and its associated TextGrid so the TextGrid can be manipulated.\n") f.write("# Once the user clicks \"Continue\", the TextGrid is saved and the next soundfile is opened.\n\n") f.write("for i from start to n\n") f.write("\tselect Strings 'fileList$'\n") f.write("\tsoundfile$ = Get string... i\n") f.write("\tRead from file... 'directory$'/'soundfile$'\n") f.write("\tsoundname$ = selected$ (\"Sound\")\n") f.write("\ttgname$ = soundname$\n") f.write("\tRead from file... 'directory$'/'tgname$'.TextGrid\n") f.write("\tplus Sound 'soundname$'\n") f.write("\tdo(\"View & Edit\")\n") f.write("\tbeginPause(\"Any edits?\")\n") f.write("\tclicked = endPause(\"Continue\", \"Save and Continue\", 1)\n") f.write("\tselect TextGrid 'tgname$'\n") f.write("\tif clicked = 2\n") f.write("\t\tSave as text file... 'directory$'/'tgname$'.TextGrid\n") f.write("\tendif\n") f.write("\tplus Sound 'soundname$'\n") f.write("\tRemove\n") f.write("\tdeleteFile: history$\n") f.write("\twriteFile: history$, i+1\n") f.write("endfor")