timmahrt / praatIO

A python library for working with praat, textgrids, time aligned audio transcripts, and audio files. It is primarily used for extracting features from and making manipulations on audio files given hierarchical time-aligned transcriptions (utterance > word > syllable > phone, etc).
MIT License
299 stars 32 forks source link

Editing timestamps to obtain new features #14

Closed warrenfarrugia closed 4 years ago

warrenfarrugia commented 5 years ago

Hi,

I am new to Praatio and have been using it in the last few weeks for a project I am currently carrying out. What I am trying to do is to edit the timestamps of all the boundaries within a particular interval tier by 1.5 seconds from before the start time and 1.5 seconds after the end time, effectively expanding my boundaries by a maximum of 3 seconds. After which I want to extract a set of prosodic features for the new boundary.

I see that there is a means of editing the time stamps but not entirely sure how to go about it. The tutorial provided only mentions it without giving a working example. Any suggestions as to how I can make this work?

n.b. I am a novice when it comes to Python (and coding in general) so sorry in advance if my question is too overgeneralized and/or easily solvable.

Thank you in advance :D

timmahrt commented 5 years ago

I can look at this more closely later today.

In your case, what happens to two intervals if the expansion causes them to overlap?

E.g. 1.0, 1.2 2.0, 2.0

After expansion? Do you have one interval (the two merge) or they would share a boundary? Or are all your intervals separated by 3 seconds or more?

On Tue, May 14, 2019, 09:55 warrenfarrugia notifications@github.com wrote:

Hi,

I am new to Praatio and have been using it in the last few weeks for a project I am currently carrying out. What I am trying to do is to edit the timestamps of all the boundaries within a particular interval tier by 1.5 seconds from before the start time and 1.5 seconds after the end time, effectively expanding my boundaries by a maximum of 3 seconds. After which I want to extract a set of prosodic features for the new boundary.

I see that there is a means of editing the time stamps but not entirely sure how to go about it. The tutorial provided only mentions it without giving a working example. Any suggestions as to how I can make this work?

n.b. I am a novice when it comes to Python (and coding in general) so sorry in advance if my question is too overgeneralized and/or easily solvable.

Thank you in advance :D

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/timmahrt/praatIO/issues/14?email_source=notifications&email_token=AAUG7UAQMCMAWNENQ4R5CADPVIEZVA5CNFSM4HMURCZKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GTRYF7A, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUG7UCN3RLMGUBEVDFVFS3PVIEZVANCNFSM4HMURCZA .

timmahrt commented 5 years ago

I'm not sure that this is 100% what you're looking for, but here is the code to expand all of your intervals by 1.5s If you have other questions, just let me know.

from praatio import tgio

# Open textgrid and expand tiers
tierName = "words"
fn = 'myTextgrid.TextGrid'
tg = tgio.openTextgrid(fn)
newEntryList = []
for start, stop, label in tg.tierDict[tierName].entryList:
  newEntryList.append([start - 1.5, stop + 1.5, label])

# If you want to extract acoustic measures, you could do that here:
for start, stop, label in newEntryList:
  pass

# If you want to save a new textgrid for later
# AND your intervals don't overlap
# If they do overlap, praat can still open the Textgrid but you'll get weird behaviour
# (entries will overlap but the boundaries won't be visible, etc)
outputTg = tgio.Textgrid()
tier = tgio.IntervalTier('expanded_words', newEntryList)
outputTg.addTier(tier)
outputTg.save('myExpandedTextgrid.TextGrid')
timmahrt commented 4 years ago

This issue has been inactive so I'm closing it. If you have more questions, please feel free to reopen it.