Ejemplo n.º 1
0
def processFromPath(filename, filepath):
    tg = ExtendedTextGrid(f=filepath)
    tg.oprint = False

    wtier = findWordsTier(tg, filename)

    # saveTierAsLM(wtier,"words", filepath)

    # lexiconFromTier(wtier, filepath)

    tg.predictPhns(wtier.name, "gen_phones")

    saveTierAsLM(generateLandmarkTier(tg.get_tier("gen_phones")), "landmarks", filepath)
Ejemplo n.º 2
0
def processFromPath(filename, filepath):
    tg = ExtendedTextGrid(f=filepath)
    tg.oprint = False

    wtier = findWordsTier(tg, filename)

    saveTierAsLM(wtier, "words", filepath)

    lexiconFromTier(wtier, filepath)

    tg.predictPhns(wtier.name, "gen_phones")

    saveTierAsLM(generateLandmarkTier(tg.get_tier("gen_phones")), "landmarks",
                 filepath)

    saveTierAsLM(tg.get_tier("gen_phones"), "phones", filepath)
Ejemplo n.º 3
0
BEFORE YOU RUN, PLEASE READ:

 * FIRST, move your textgrid files to data/source folder. Work out of that folder.

REQUIRED TIER NAMES:
 * "words": interval tier with full words
 * either "landmarks" or "LM": point tier with t-cl style landmarks
 * either "LMmod" or "LMmods" or "comments": point tier with t-cl-x style landmarks

NOTE: If a tier named "phones" exists, it will be renamed to "phones_prev" and a
	  new, generated "phones" tier will be used.
"""

TEXTGRID_FILES = ["Gabrieli/ASDH_SLI_3126_allison.TextGrid",
				  "Gabrieli/ASDL_BILDC3099_allison.TextGrid",
				  "Gabrieli/SLI_SLI3086_allison.TextGrid",
				  "Gabrieli/SLI3084_allison.TextGrid"]

from ExtendedTextGrid import *

for TEXTGRID_FILE in TEXTGRID_FILES:
	print(TEXTGRID_FILE)
	src = "data/source/" + TEXTGRID_FILE
	print("Creating .tab from "+src+"...")
	tg = ExtendedTextGrid(src)
	tg.prepare()
	tg.extractContext()
	tg.saveTab()
	print("Saved as "+tg.fname+".tab")

Ejemplo n.º 4
0
convProcess.py
Combines the functionality of generatePhonesTier.py, saveTierAsLM.py, and LexiconExtract.py, used for batch processing 16 textgrids at once.
"""
import sys, logging
# Require Python 3.x
if sys.version_info[0] < 3:
    print("Error: The TextGrid processor requires Python 3.0 or above. Exiting.\n")
    sys.exit(1)

#This will crash on python 2.x so it has to go below the version test
from ExtendedTextGrid import *

for i in range(1, 17):
    filename = "conv{num:02d}g".format(num=i)
    filepath = "../landmarks/matcher-data/"+filename+".TextGrid"
    tg = ExtendedTextGrid(f=filepath)
    tg.oprint = False

    wtier = None
    tier_names = [tier.name for tier in tg]
    for pn in ["word", "words", "Word", "Words", filename, filename[:-1]]:
        if pn in tier_names:
            wtier = tg.get_tier(pn)

    if wtier == None:
        print(filename)
        for i, tier in zip(range(len(tg)), tg):
            print(str(i) + " " + tier.name)
        wt = int(input("Words tier: "))
        wtier = tg[wt]
Ejemplo n.º 5
0
from ExtendedTextGrid import *

# [Data Preparation]
# Define file path here
sourcetg = "C:\\Users\mz\Documents\\landmark\conv07.TextGrid"
sourcepd = "C:\\Users\mz\Documents\\landmark\data\conv07g_RS.TextGrid"
fname = "C:\\Users\mz\Documents\\landmark\data\conv07_ext.TextGrid"

# Load file
tg = ExtendedTextGrid(f=sourcetg)
tg.saveAs(fname)
### Apply lexicon, predict landmarks, and unify landmark label format
##tg.putPhns()
##tg.predictLM()
e = tg.convertLM(True)
### Convert words tier to context-rich objects
##tg.extendWords()
### Match landmarks with corresponding phones
##tg.linkLMtoWords("pred. LM")
##tg.linkLMtoWords("act. LM")
##tg.linkLMtoPhones()
### Align predicted and observed landmarks
##tg.alignLM()
### Adjust position of each predicted landmark to the aligned observed landmark
##lm_tier = tg.get_tier("pred. lm")
### Create a new tier to display landmark modifications
##tg.append(lm_tier.aligned())
##
### Convert textgrid into table
##tg.saveTab()
Ejemplo n.º 6
0
    while not f:
        path = input("Enter TextGrid file path: ")
        if not path.lower().endswith(".textgrid"):
            print("File must end with .textgrid")
            continue
        try:
            f = open(path)
            f.close()
        except IOError:
            print("File does not exist")
            continue
    return path


while 1:  #Loop until putPhns() runs sucessfully, then break & save
    tg = ExtendedTextGrid(pathFromInput())
    try:
        tg.putPhns()
        break
    except Exception:
        print("There must be a tier named \"words\".")

lm = input("Do you want to generate a landmark tier (yes/no)? ").lower()
if lm == "yes" or lm == "y":
    import phones_to_landmarks_dict
    d = phones_to_landmarks_dict.d
    phonetier = tg.get_tier("phones")
    # Initiate new textgrid tiers for predicted landmarks, phonemes, voicing, and nosal info
    lmtier = PointTier(name="LM", xmin=0, xmax=phonetier.xmax)

    for interval in phonetier:
            continue
    return path

# while 1: #Loop until putPhns() runs sucessfully, then break & save
#     tg = ExtendedTextGrid(pathFromInput())
#     try:
#         tg.putPhns()
#         break
#     except Exception:
#         print("There must be a tier named \"words\".")

# lm = input("Do you want to generate a landmark tier (yes/no)? ").lower()
# if lm=="yes" or lm=="y":
from phones_to_landmarks_dict import d #Dictionary of phone -> landmark 

tg = ExtendedTextGrid(pathFromInput())
phonetier = tg.get_tier("phones")
if not phonetier:
    print("TextGrid must contain a tier named 'phones'")
    sys.exit()
# Initiate new textgrid tiers for predicted landmarks, phonemes, voicing, and nosal info
lmtier = PointTier(name="LM", xmin = 0, xmax=phonetier.xmax)

for interval in phonetier:
    try:    
        # non-words
        phone = interval.text.lower().strip("\t \" +?.'[],012")     # ignore uncertainty marks
        if not ('<' in phone or '>' in phone or phone=='' or phone=="#"):    
            lms=d[phone]
            duration = (interval.xmax-interval.xmin)/len(lms)    # duration of each phoneme
            
Ejemplo n.º 8
0
from ExtendedTextGrid import *

# [Data Preparation]
# Define file path here
sourcetg = "C:\\Users\mz\Documents\\landmark\conv07.TextGrid"
sourcepd = "C:\\Users\mz\Documents\\landmark\data\conv07g_RS.TextGrid"
fname = "C:\\Users\mz\Documents\\landmark\data\conv07_ext.TextGrid"

# Load file
tg = ExtendedTextGrid(f=sourcetg)
tg.saveAs(fname)
### Apply lexicon, predict landmarks, and unify landmark label format
##tg.putPhns()
##tg.predictLM()
e=tg.convertLM(True)
### Convert words tier to context-rich objects
##tg.extendWords()
### Match landmarks with corresponding phones
##tg.linkLMtoWords("pred. LM")
##tg.linkLMtoWords("act. LM")
##tg.linkLMtoPhones()
### Align predicted and observed landmarks
##tg.alignLM()
### Adjust position of each predicted landmark to the aligned observed landmark 
##lm_tier = tg.get_tier("pred. lm")
### Create a new tier to display landmark modifications
##tg.append(lm_tier.aligned())
##
### Convert textgrid into table
##tg.saveTab()
Ejemplo n.º 9
0
        if not path.lower().endswith(".textgrid"):
            print("File must end with .textgrid")
            continue
        try:
            f = open(path)
            f.close()
        except IOError:
            print("File does not exist")
            continue
    return path


if len(sys.argv) == 2:
    try:
        path = sys.argv[1]
        f = open(path)
        f.close()
    except IOError:
        path = pathFromInput()
else:
    path = pathFromInput()

tg = ExtendedTextGrid(path)
for tier in tg:
    if type(tier) == IntervalTier:
        print("running on tier " + tier.name)
        tier.fixIntervalSpaces()

tg.save()

print("Saved as " + tg.fname + ".TextGrid.")
Ejemplo n.º 10
0
    while not f:
        path = input("Enter TextGrid file path: ")
        if not path.lower().endswith(".textgrid"):
            print("File must end with .textgrid")
            continue
        try: 
            f = open(path)
            f.close()
        except IOError:
            print("File does not exist")
            continue
    return path
if len(sys.argv) == 2:
    try: 
        path = sys.argv[1]
        f = open(path)
        f.close()
    except IOError:
        path = pathFromInput()
else:
    path = pathFromInput()

tg = ExtendedTextGrid(path)
for tier in tg:
    if type(tier) == IntervalTier:
        print("running on tier "+tier.name)
        tier.fixIntervalSpaces()

tg.save()

print("Saved as "+tg.fname+".TextGrid.")