TextGridTools
TextGridTools copied to clipboard
Problem with shifting
If I run this script with last line commented I dont get an error.
The error seems to be raised on tgt.write_to_file
. which is confusing. I guess it should be raised already on tier.add_interval()
Could you please provide more information about this bug? What code triggered it? The traceback you have provided mentions write_to_file
, not shift
.
This error is not caused directly by add_tier
but by the fact that you are both modifying (in place) start and end times and adding the modified interval to the same tier.
Arguably, that is not something that you should be doing but the error message is indeed confusing. The problem is two-fold: (1) modifying start and end times does not actually move the interval up or down the tier, which (2) confuses add_interval
which uses bisect.bisect_left
.
We are currently working on an improved representation of Annotations that prevents these kind of problems.
For the moment I would recommend to create a new Tier and to add Annotation 0-50 (in your script) as well as the shifted Annotations to this new Tier. Then remove the old Tier and add the new Tier to the TextGrid object.
Thank you guys for the feedback.
The use case I had in mind is:
I am doing annotations on word boundaries on a given tier. I annotate a song, in which the chorus repeats. When doing chorus for the second time Instead of retyping the words, I would like to copy the words and their respective timestamps form chorus 1; everything being same, just shifted by an time (chorus2.beginTs-chorus1.endTs)
Do you know how can I do this maybe with another Praat script?
@hbuschme the suggestion is fine, but somewhat cumbersome, if I have to do it each repetition in a highly repetitive song, maybe I would type the words in the end :(
I see. I think what you are trying to achieve should be perfectly possible with tgt as long as you do not modify the existing annotation (which, as far as I can see, is not what you want since you want the original chorus to remain in its original place). In other words, instead of saying:
for anno in a[51:-1]:
anno.end_time += shiftTime
anno.start_time += shiftTime
tier.add_interval(anno)
create a new shifted annotation like this:
for anno in a[51:-1]:
anno_shifted = tgt.Interval(anno.start_time + shiftTime,
anno.end_time + shiftTime,
anno.text)
tier.add_interval(anno_shifted)
Hope this helps! Marcin