0

I am new to Praat scripting but I want to write a Praat script to give me the formant values of a vowel at the midpoint and at the last point (99%) of the vowel. I want to be able to select the vowel and then run the script. Here is what I have so far:

begin_vowel = Get start point... tier interval
end_vowel = Get end point... tier interval
duration_vowel = end_vowel - begin_vowel

midway = begin_vowel + duration_vowel/2
ninetynine = .99 * duration_vowel               

# for men
# To Formant (burg)... 0 5 4500 0.025 50
# for women
To Formant (burg)... 0 5 5500 0.025 50

select Formant
f2_mid = Get value at time... 2 midway Hertz Linear
f3_mid = Get value at time... 3 midway Hertz Linear

f2_end = Get value at time... 2 ninetynine Hertz Linear
f3_end = Get value at time... 3 ninetynine Hertz Linear

outfile$ = "formants.txt"
fileappend 'f2_mid' 'f3_mid' 'f2_end' 'f3_end'

When I select the vowel in a text grid tier and try to run it, I just get "Command 'Get start point...' not available for this selection." Can anyone tell me what I'm doing wrong? Thanks!

1 Answer 1

2

I figured it out. I'm sure this seems not very automatic, but it's good for if you want to only measure specific things. Here's the code if this will help anyone else.

##################################
#   Input sound file name here   #
##################################

.sound$ = "*INSERT SOUND NAME HERE*"

select Sound '.sound$'

#################################################
#   Select correct formant values based on sex  #
#################################################

# for men
# To Formant (burg)... 0 5 4500 0.025 50
# for women
To Formant (burg)... 0 5 5500 0.025 50

#######################
#   Input times here  #
#######################

begin_vowel = *INSERT START TIME OF SEGMENT*
end_vowel = *INSERT END TIME OF SEGMENT*

duration_vowel = end_vowel - begin_vowel

midway = begin_vowel + duration_vowel/2
ninetynine = begin_vowel + 0.99 * duration_vowel


select Formant '.sound$'
f2_mid = Get value at time... 2 midway Hertz Linear
f3_mid = Get value at time... 3 midway Hertz Linear

f2_end = Get value at time... 2 ninetynine Hertz Linear
f3_end = Get value at time... 3 ninetynine Hertz Linear


# creates csv text file
appendFileLine: "formants.txt", "'f2_mid', 'f3_mid', 'f2_end', 'f3_end'"

Edit: You can also do this for multiple things using a procedure.

    ############################################
    #   Input vowel, sound file name, start time, end time, formant values, number of formants  #
    ############################################    
@instance: "ae", "sbc006_1441_88_1443_71", 1.185, 1.251820, 5500, 5

    procedure instance: .vowel$, .sound$, .start, .end, .hertz, .num

select Sound '.sound$'

#################################################
#   Select correct formant values based on sex  #
#################################################

To Formant (burg)... 0 .num .hertz 0.025 50

begin_vowel = .start
end_vowel = .end

duration_vowel = end_vowel - begin_vowel

midway = begin_vowel + duration_vowel/2
ninetynine = begin_vowel + 0.99 * duration_vowel


select Formant '.sound$'
f2_mid = Get value at time... 2 midway Hertz Linear
f3_mid = Get value at time... 3 midway Hertz Linear

f2_end = Get value at time... 2 ninetynine Hertz Linear
f3_end = Get value at time... 3 ninetynine Hertz Linear


# creates tab delimited text file
appendFileLine: "sbc006formants.txt", "'.sound$' 'tab$' '.vowel$' 'tab$' 'f2_mid' 'tab$' 'f3_mid' 'tab$' 'f2_end' 'tab$' 'f3_end'"

endproc


writeInfoLine: "Finished!"

Your Answer

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

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