Beispiel #1
0
def fill_gaps(tier, mark):
    '''For a given tier, add an interval with a given mark to all unfilled intervals'''
    old_time = tier.minTime
    for interval in tier.intervals:
        if old_time < interval.minTime:
            tier.addInterval(textgrid.Interval(old_time, interval.minTime, mark))
        old_time = interval.maxTime
    if tier.maxTime is not None and old_time < tier.maxTime:
        tier.addInterval(textgrid.Interval(old_time, tier.maxTime, mark))
Beispiel #2
0
def overwrite_interval(int_tier, start, stop, mark):
    '''Given an interval, add it to the interval
       overwriting anything within that time span '''
    min_ind = int_tier.indexContaining(start)
    max_ind = int_tier.indexContaining(stop)
    #Get rid of anything in between
    del int_tier.intervals[min_ind + 1:max_ind]

    min_ind = int_tier.indexContaining(start)
    max_ind = int_tier.indexContaining(stop)
    minOverlap = int_tier[min_ind]
    maxOverlap = int_tier[max_ind]

    if minOverlap == maxOverlap:
        if stop != minOverlap.maxTime:
            newOver = textgrid.Interval(stop, minOverlap.maxTime,
                                        minOverlap.mark)
            minOverlap.maxTime = start
            int_tier.addInterval(newOver)
        else:
            minOverlap.maxTime = sp.minTime
    else:
        minOverlap.maxTime = start
        maxOverlap.minTime = stop

    int_tier.add(start, stop, mark)
        transcr_ph_txt = endpoints[5]

        offsets = decoded_results["output"][0]["offsets"]

        txg.endTime = offsets[len(offsets) - 1]

        words_tier = textgrid.IntervalTier("words", 0,
                                           offsets[len(offsets) - 1])
        phones_tier = textgrid.IntervalTier("phones", 0,
                                            offsets[len(offsets) - 1])

        for jx in range(0, len(transcr_wrd_txt) - 1):
            #print(transcr_wrd_txt[jx]+" "+str(transcr_wrd_starts[jx])+" "+str(transcr_wrd_ends[jx]))
            #if transcr_wrd_starts[jx] == transcr_wrd_ends[jx]: transcr_wrd_ends[jx] += 0.01
            words_tier.addInterval(
                textgrid.Interval(transcr_wrd_starts[jx], transcr_wrd_ends[jx],
                                  transcr_wrd_txt[jx]))

        for px in range(0, len(transcr_ph_txt) - 1):
            #print(transcr_ph_txt[px]+" "+str(transcr_ph_starts[px])+" "+str(transcr_ph_ends[px]))
            #if transcr_ph_starts[jx] == transcr_ph_ends[jx]: transcr_ph_ends[jx] += 0.01
            #if transcr_ph_txt[px] == " ": transcr_ph_txt[px] = "SIL"
            phones_tier.addInterval(
                textgrid.Interval(transcr_ph_starts[px], transcr_ph_ends[px],
                                  transcr_ph_txt[px]))
            #print(transcr[ix] + " " + str(offs[ix]))

        txg.append(words_tier)
        txg.append(phones_tier)

        txg.write(args.outputfile)
Beispiel #4
0
import textgrid

f = textgrid.TextGrid()
f.read("A_man_bought_a_car_in_Paris-DC-5.TextGrid")

print(f.getNames())
print(f.getFirst("stress"))

for y in f.getList("stress"):
    for x in y:
        print(x)
        print("Duration:", x.duration())
        print("Bounds:", x.bounds())
        print("Overlaps:", x.overlaps(textgrid.Interval(0.0, 1.89568, "a")))
Beispiel #5
0
                        romajiTier.name = path
                    else:
                        romajiTier.name = os.path.splitext(name)[0]

                    # convert kanji to romaji
                    for interval in Tier.intervals:

                        # skip intervals with dummy silence
                        if interval.mark == "#":
                            continue

                        # take interval information from original
                        # and apply convertor to the interval name
                        else:
                            romajiInt = textgrid.Interval(
                                minTime=interval.minTime,
                                maxTime=interval.maxTime,
                                mark=conv.do(interval.mark))

                        # convert long chounpu with the preceding vowel
                        romajiInt.mark = re.sub("([a-z])\s*-", "\1\1",
                                                romajiInt.mark)

                        romajiTier.addInterval(romajiInt)

            # create an empty TextGrid object to write romaji tier to
            newTg = textgrid.TextGrid()
            newTg.append(romajiTier)

            # write textgrid to file
            print("saving to {}".format(os.path.join(args.outputDir, name)))
            newTg.write(os.path.join(args.outputDir, name))