#Initialization ends
#-------------------

# path that contains all the annotated wave files
path = '/Users/ch/data/programming/python/lib/demo/'
csvFileName = 'TextGridAnalysis.csv'

# open the output file
csvFile = open(path + csvFileName, 'w')
csvFile.write("file, tStart, tEnd, label\n")

# look for all TextGrids in the directory
for fName in os.listdir(path):
    if fName.split('.')[-1] == 'TextGrid':
        fileNameOnly = generalUtility.getFileNameOnly(fName)
        print fileNameOnly
        
        # instantiate a new TextGrid object
        textGrid = praatTextGrid.PraatTextGrid(0, 0)
        # initialize the TextGrid object from the TextGrid file
        # arrTiers is an array of objects (either PraatIntervalTier or 
        # PraatPointTier)
        arrTiers = textGrid.readFromFile(fName)
        numTiers = len(arrTiers)
        if numTiers != 1:
            raise Exception("we expect exactly one Tier in this file")
            
        # get the first tier in the file and check it's name (and we assume that 
        # there's exactly one tier in the file
        tier = arrTiers[0]