praat script get pitch list for a certain word

906 views Asked by At

I am trying to write a script for Praat and am having difficulty doing it.

What I want is to have a result for a certain word in a sentence (and a sound), ex.: As you're not using your car at the moment, can I borrow it?

I want a pitch list for the word "moment". If I select the word "moment" and select pitch listing under the menu of pitch then it gives me the time and f0 for every 0.01 second (open both sound and TextGrid).

I have been searching and trying to script this but haven't succeeded yet.

Could you help me with this?


I have modified the upper question.

sentence: As you're not using your car at the moment, can I borrow it? (I have a mp3 file, text grid with 2 tiers for this sentence, tier 1 is the word and tier 2 is phone)

The following is my script. I want to have the f0 max and min for the last syllable part of the word "moment" but only succeeded in having the f0 max and min for the whole interval 10("moment" in tier 1).

I also have a phone tier for the word "moment" (in tier 2), which is the following:

phone tier for the word "moment" is M OW M AH N T

=> and I want [M AH N T] 's f0 max and f0 min excluding [M OW] which is the first syllable part.

the following is the script I have so far.


form Get F0 Min-Max
    sentence Directory ./
    word Base_file_name 
    comment The name of result file
    text textfile F0_list.txt
endform

# Create a header row for the result file:
header$ = "Filename TextGridLabel startTime endTime minTime f0min maxTime f0max'newline$'"
fileappend "'textfile$'" 'header$'

#Read all files in a folder
Create Strings as file list... mp3list 'directory$'/'base_file_name$'*.mp3
Create Strings as file list... gridlist 'directory$'/'base_file_name$'*.TextGrid
n = Get number of strings

for i to n
clearinfo
#We first extract pitch tiers
    select Strings mp3list
    filename$ = Get string... i
    Read from file... 'directory$'/'filename$'
    soundname$ = selected$ ("Sound")
    To Pitch... 0.01 75 600
    output$ = "'soundname$'.Pitch"
    # Write to binary file... 'output$'

# Read grid files and extract the selected intervals in them
    select Strings gridlist
    gridname$ = Get string... i
    Read from file... 'directory$'/'gridname$'
    int=Get number of intervals... 1

# Calculates F0 max, and F0 min (I need interval 10 to be analyzed for the word "moment" so have the 1 10 for the label) 
    select TextGrid 'soundname$'
    label$ = Get label of interval... 1 10 
    if label$ <> ""
        startTime = Get starting point... 1 10
        endTime = Get end point... 1 10 
        select Pitch 'soundname$'
        f0max = Get maximum... startTime endTime Hertz Parabolic
        maxTime = Get time of maximum... startTime endTime Hertz Parabolic
        f0min = Get minimum... startTime endTime Hertz Parabolic
        minTime = Get time of minimum... startTime endTime Hertz Parabolic
        resultline$ = 

"'soundname$''tab$''label$''tab$''syllableTime''tab$''endTime''tab$''minTime''tab$''f0min''tab$''maxTime''tab$''f0max'"
        fileappend "'textfile$'" 'resultline$'
    endif

fileappend "'textfile$'" 'newline$'

endfor

# clean up

select all
Remove

Could you help me with this? thank you so much.

1

There are 1 answers

0
Lisa On

Could you add a new tier to separate out just the part you are interested in? Are there any other sentences in your data?

# define your variables
phoneTier = 2
newTier = 3
name$ = "syllable"
regexFirst$ = "M"
regexLast$ = "T"

# use this to add a new tier in each text grid
select TextGrid 'soundname$'
Insert interval tier: newTier, name$

# loop through the phones to find the start time of the syllable
# put this in the for loop that loops through each textgrid
phoneInt = Get number of intervals... phoneTier
for i from 1 to phoneInt-3
    label$ = Get label of interval... i phoneTier
    labelNext$ = Get label of interval... i+3 phoneTier
    if index_regex(label$, regexFirst$) & index_regex(labelNext$, regexLast$)
        start = Get starting point... i phoneTier
        end = Get end point... i+3 phoneTier
        Insert boundary... newTier start
        Insert boundary... newTier end
        syllableInterval = Get low interval at time: newTier, end
        Set interval text... newTier syllableInterval "syllable"
    endif
endfor

then, take the measurement of the intervals you just created.