Dear all,
Thanks, Yannick, for making Parselmouth. It's really awesome.
I need to find the duration of the sound files for each syllable according to the annotated textgrid. I find the initial time (in my script, it is xmin), the final time (in my script, it is xmax), and the syllable label (in my script, it is text) according to the python script gien below. And, finally, I save the output as a .csv file.
The script is given below for your reference. Also, one of the sound files and the textgrids are attached. There is no problem, and it works absolutely fine.
I was just wondering if there is any way to also add the respective file name of the Textgrid (for example, s1_ba1_chase_iso.TextGrid) as an output along with xmin, xmax, and text.
Any suggestions would really be helpful.
Thanks,
Anu
#import libraries
import glob
import numpy as np
import pandas as pd
import parselmouth
import statistics
import textgrids
# create lists to put the results
xmin_list = []
xmax_list = []
text_list = []
for textgrid_file in glob.glob(r"C:\Users\anusu\Maram_Tone\ba\ba_chase\*.TextGrid"):
grid = textgrids.TextGrid(textgrid_file)
# Assume "syllables" is the name of the tier
# containing syllable information
for syll in grid["Mary"]:
if syll.containsvowel():
# Convert Praat to Unicode in the label
label = syll.text.transcode()
text_list.append(syll.text)
xmin_list.append(syll.xmin)
xmax_list.append(syll.xmax)
df = pd.DataFrame(np.column_stack([text_list, xmin_list, xmax_list]),columns=['text', 'xmin', 'xmax'])
df.to_csv("textgrid.csv", index=False)