12345678910111213141516171819202122232425262728293031323334353637 |
- import pandas as pd
- import pympi.Praat as pr
- #open csv as pandas dataframe
- df = pd.read_csv(r"C:\Users\Martin\Desktop\LAAC\alignment-project\inputs\testCHA.csv")
- #create textgrid
- grid = pr.TextGrid(xmax = 300)
- #specify number of rows
- rows = 9000
- #iterate through each row
- for i in range(rows):
- #load data from dataframe
- speaker = df.iloc[i, 0]
- transcription = df.iloc[i, 3]
-
- #loads onset and offset and converts from milliseconds to seconds
- onset = df.iloc[i,5]/1000
- offset = df.iloc[i, 1]/1000
- #checks if tier already exists. If not, create a new tier
- try:
- aTier = grid.get_tier(speaker)
- except IndexError:
- aTier = grid.add_tier(speaker)
- #creates interval and adds it to the tier
- pr.Tier.add_interval(aTier, onset, offset, transcription, False)
- print(list(pr.TextGrid.get_tier_name_num(grid)))
- grid.to_file(r"C:\Users\Martin\Desktop\LAAC\alignment-project\outputs\converterTest.txt")
|