1

I created an excel file with the following columns: start_time, end_time, transcript, quotative, tag. The start_time and end_time columns indicate the boundaries of each interval. I turned this excel file into a tab-delimited text file. What I'd like to do, based on this text file, is to generate a Textgrid in Praat (aligned with the audio), with three tiers : transcript, quotative, tag. There would be the same intervals across all tiers. The intervals on each tier would be populated with info coming from the corresponding columns in the text file (transcript, quotative, tag).

I've tried to find information on how to do that, but I don't manage. I find a lot of info on how to export data from a textgrid into a csv file, but I don't know how to import information into a textgrid, based on timestamps. Can someone help me?

Thanks!

4
  • 2
    This is not linguistics. You need an Excel expert.
    – Lambie
    Oct 8, 2023 at 15:55
  • 1
    I’m voting to close this question because it is off topic.
    – Lambie
    Oct 8, 2023 at 15:55
  • 2
    Praat is a software programme used by linguists. I'm not sure an Excel expert will be able to help...
    – pg900904
    Oct 8, 2023 at 16:01
  • 2
    That's strange because all questions related to Praat are to be found in "Linguistics", and that's actually how I ended up here.
    – pg900904
    Oct 8, 2023 at 16:27

2 Answers 2

0

This requires some programming: there is no general point-and-click Excel option. This may suffice for your purposes (i.e. if you can figure out what it does and what you are supposed to do to implement it). Otherwise, you would need to understand the structure of a textgrid file. Here is a description of a textgrid file. There are actually two forms, the full form and the short form. The short form is basically a cvs file with separate lines rather than tabs.

0

You can achieve this for instance using a Python script. I tested my script with Spyder in Anaconda.

Input TXT data: For this example, I have just created some (nonce) input TXT data in an Excel file, with the following contents:

start_time  end_time    transcript  quotative   tag
0.25    4.563   He said, "You're going to enjoy this script."   say historical
5.42    9.845   He was like, "I think this example is cool!"    be like colloquial

Python script that generates TextGrids from a TXT file: Assuming that you only have one audio file to align the TXT file contents with, and that you want to use UTF-8 encoding, you could do something like this:

import csv
import textgrid  # If missing, try 'pip install textgrid' in command prompt [Windows operating system]

# Load the tab-delimited data
with open("your_file.txt", "r", encoding="utf-8") as f:
    reader = csv.DictReader(f, delimiter="\t")
    data = [row for row in reader]

# Create a TextGrid object
tg = textgrid.TextGrid()

# Create IntervalTier objects
transcript_tier = textgrid.IntervalTier(name="transcript")
quotative_tier = textgrid.IntervalTier(name="quotative")
tag_tier = textgrid.IntervalTier(name="tag")

# Populate the interval tiers
for row in data:
    start_time = float(row["start_time"])
    end_time = float(row["end_time"])
    transcript_tier.add(start_time, end_time, row["transcript"])
    quotative_tier.add(start_time, end_time, row["quotative"])
    tag_tier.add(start_time, end_time, row["tag"])

# Add the interval tiers to the TextGrid
tg.append(transcript_tier)
tg.append(quotative_tier)
tg.append(tag_tier)

# Write the TextGrid to a file
with open("output.TextGrid", "w", encoding="utf-8") as f:
    tg.write(f)

Change the input and output paths if needed.

Adaptation to generate TextGrids from a CSV file: A CSV file could also be used, with minor changes to the code – like so:

# Load the CSV data
with open("your_file.csv",
          "r", encoding="utf-8") as f:
    reader = csv.DictReader(f,
                            delimiter=";"  # If semicolon separated, not comma
                            )
    data = [row for row in reader]

Output TextGrid: The script successfully outputs the following TextGrid:

File type = "ooTextFile"
Object class = "TextGrid"

xmin = 0.0
xmax = 9.845
tiers? <exists>
size = 3
item []:
    item [1]:
        class = "IntervalTier"
        name = "transcript"
        xmin = 0.0
        xmax = 9.845
        intervals: size = 4
            intervals [1]:
                xmin = 0.0
                xmax = 0.25
                text = ""
            intervals [2]:
                xmin = 0.25
                xmax = 4.563
                text = "He said, ""You're going to enjoy this script."""
            intervals [3]:
                xmin = 4.563
                xmax = 5.42
                text = ""
            intervals [4]:
                xmin = 5.42
                xmax = 9.845
                text = "He was like, ""I think this example is cool!"""
    item [2]:
        class = "IntervalTier"
        name = "quotative"
        xmin = 0.0
        xmax = 9.845
        intervals: size = 4
            intervals [1]:
                xmin = 0.0
                xmax = 0.25
                text = ""
            intervals [2]:
                xmin = 0.25
                xmax = 4.563
                text = "say"
            intervals [3]:
                xmin = 4.563
                xmax = 5.42
                text = ""
            intervals [4]:
                xmin = 5.42
                xmax = 9.845
                text = "be like"
    item [3]:
        class = "IntervalTier"
        name = "tag"
        xmin = 0.0
        xmax = 9.845
        intervals: size = 4
            intervals [1]:
                xmin = 0.0
                xmax = 0.25
                text = ""
            intervals [2]:
                xmin = 0.25
                xmax = 4.563
                text = "historical"
            intervals [3]:
                xmin = 4.563
                xmax = 5.42
                text = ""
            intervals [4]:
                xmin = 5.42
                xmax = 9.845
                text = "colloquial"
New contributor
Eirik Tengesdal is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.