I'm new to Praat scripting, and I was wondering if there was a way to "find" a word in a text grid tier and then find a sound in a different tier. I want praat to measure the last vowel in selected words in a large corpus (for which I have text grids). I've googled this but can't seem to find anything. If this isn't possible, would it be possible to find this in perl and then use Praat to find formants? Thanks!
As I understand your question, there are four different tasks:
Look for a word in a TextGrid tier
Find its last vowel
Look for the interval labelled with that vowel in the segment tier
Measure something on that interval
The first and the third seem to me to be on-topic for this question.
1. Find a label in a tier
This is pretty straightforward. The most naive way to do this would be
n = Get number of intervals: word_tier for i to n label$ = Get label of interval: word_tier, i if label$ == target$ index = i i += n ; break from the loop endif endfor appendInfoLine: "My label is on interval ", index
Alternatively, you could use the commands provided in the "tgutils" plugin distributed through CPrAN (full disclaimer: I wrote it). With it, you can include the procedures in
find_labels.proc (or just copy the contents of that file into your script) and write
selected("TextGrid") @findLabel: word_tier, target$ word_index = findLabel.return appendInfoLine: "My word is on interval ", word_index
3. Finding the vowel interval
You'd then have to do the same but looking only among the intervals that fall within the boundaries of that word for the one that is labelled like the vowel you want.
For this, you can once again use the procedures from the "tgutils" plugin to look backwards for the first interval labelled with that vowel:
# Find the interval number in the segment tier at the end # of the matching word in the word tier word_end = Get end point: word_tier, word_index last_segment = Get low interval at time: segment_tier, word_end @findLabelBehind: segment_tier, last_vowel$, last_segment segment_index = findLabelBehind.return appendInfoLine: "My segment is on interval ", segment_index
The other tasks
Finding the last vowel, and running your analyses, are not within the scope of this question, based on your title. Feel free to create new questions to cover those, or to rephrase the scope of this one!