Audacity tsv to textgrid
For HSI project
%%capture
%pip install praatio
from praatio import textgrid
from praatio.utilities.constants import Interval
input_file = "/tmp/hsi_5_0718_209_002_inter.tsv"
output_file = '/tmp/out.TextGrid'
input_file = "/Users/joregan/Playing/irish-asr-data/audacity/MSF_chapter_1.aud"
output_file = "/tmp/out.textgrid"
out = []
with open(input_file) as inf:
for line in inf.readlines():
line = line.strip()
if line == "":
continue
if line == "0.0\t0.1\t[-]":
continue
parts = line.split("\t")
out.append(Interval(float(parts[0]), float(parts[1]), parts[2]))
tier_start = out[0][0]
tier_end = out[-1][1]
tg = textgrid.Textgrid()
word_tier = textgrid.IntervalTier('words', out, tier_start, tier_end)
tg.addTier(word_tier)
tg.save(output_file, format="long_textgrid", includeBlankSpaces=False)