# Sources:# voiced_extract_auto.txt# v 20020423 John Tøndering, modified quite a lot by Niels Reinholt Petersen# v 20200817 modified by Eric Jackson to run in Praat 6.0.04 (2015-11-01)## CONSTANTS# Formant analysis parameters# FOR A WOMAN:# To Formant (burg)... 0.005 5.0 5500.0 0.025 50.0# FOR A MAN:# To Formant (burg)... 0.005 5.0 5000.0 0.025 50.0time_step = 0.005max_formant_num = 5max_formant_freq = 5500window_length = 0.025preemphasis = 50# Pitch analysis parameterspitch_time_step = 0.005pitch_floor = 60max_candidates = 15very_accurate = 0silence_thresh = 0.03voicing_thresh = 0.7octave_cost = 0.01oct_jump_cost = 0.35vuv_cost = 0.14pitch_ceiling = 600.0max_period = 0.02# Other constantstier = 1outfile_vuv$ = "/home/emj/ActiveFiles/Personal Development/Personal projects/Vocoid heatmap/Q0 - Getting formant traces/voiced_intervals.csv"# SCRIPT START# 1. Check whether the result file exists:if fileReadable (outfile_vuv$)pause The file 'outfile_vuv$' already exists! Do you want to overwrite it?filedelete 'outfile_vuv$'endif# Create a header row for the result file: (remember to edit this if you add or change the analyses!)header$ = "interval start finish'newline$'"fileappend "'outfile_vuv$'" 'header$'# 2. Generate pitch track from sound, use that to find Voiced / Unvoiced intervalsname$ = selected$("Sound")select Sound 'name$'To Pitch (ac)... pitch_time_step pitch_floor max_candidates very_accurate silence_thresh voicing_thresh octave_cost oct_jump_cost vuv_cost pitch_ceilingmedian_f0 = Get quantile... 0 0 0.5 Hertzmean_period = 1/median_f0select Sound 'name$'plus Pitch 'name$'To PointProcess (cc)To TextGrid (vuv)... max_period mean_period# 3. For each interval, output start and end time to filenumberOfIntervals = Get number of intervals... tier# Pass through all intervals in the designated tier, and if they are voiced, find the start and end timefor interval to numberOfIntervalslabel$ = Get label of interval... tier intervalif label$ == "V"interval$ = string$: intervalstart = Get starting point... tier intervalstart$ = string$: startend = Get end point... tier intervalend$ = string$: end# Save result to text file:resultline$ = interval$ + tab$ + start$ + tab$ + end$ + newline$fileappend "'outfile_vuv$'" 'resultline$'# select the TextGrid so we can iterate to the next interval:select TextGrid 'name$'_'name$'endifendfor# 4. Calculate and write out formants for this Sound objectselect Sound 'name$'To Formant (burg)... time_step max_formant_num max_formant_freq window_length preemphasisDown to Table... no yes 6 no 3 yes 3 noSave as tab-separated file: name$ + "_formants.csv"


# CONSTANTS# Formant analysis parameters# FOR A WOMAN:# To Formant (burg)... 0.005 5.0 5500.0 0.025 50.0# FOR A MAN:# To Formant (burg)... 0.005 5.0 5000.0 0.025 50.0time_step = 0.005max_formant_num = 5max_formant_freq = 5500window_length = 0.025preemphasis = 50# Pitch analysis parameterspitch_time_step = 0.005pitch_floor = 60max_candidates = 15very_accurate = Falsesilence_thresh = 0.03voicing_thresh = 0.7octave_cost = 0.01oct_jump_cost = 0.35vuv_cost = 0.14pitch_ceiling = 600.0max_period = 0.02# Other constantstier = 1outfile = "voiced_intervals.csv"path = "test1.wav"# 1. Calculate formants for the Sound objectsound = parselmouth.Sound(path)formants = sound.to_formant_burg(time_step,
max_formant_num,
max_formant_freq,
window_length,
preemphasis)
data_table = parselmouth.praat.call(formants,"Down to Table...",False, True, 6,False, 3, True, 3, False)# 2. Generate pitch track from sound, use that to find Voiced / Unvoiced intervalspitch = sound.to_pitch_ac(pitch_time_step,
pitch_floor,
max_candidates,
very_accurate,
silence_thresh,
voicing_thresh,
octave_cost,
oct_jump_cost,
vuv_cost,
pitch_ceiling)
mean_period = 1/parselmouth.praat.call(pitch, "Get quantile", 0.0, 0.0, 0.5, "Hertz")
pulses = parselmouth.praat.call([sound, pitch], "To PointProcess (cc)")
tgrid = parselmouth.praat.call(pulses, "To TextGrid (vuv)", 0.02, mean_period)
First of all about the TextGrid: Parselmouth doesn't have a full TextGrid interface (yet), but since version 0.4.0, there is the integration with TextGridTools (`TextGrid.to_tgt()`, I believe).
Formant values, you should be able to extract with `formants.get_value_at_time` or formants.get_value_at_sample` (and maybe use `formants.xs()` or `formants.ts()` to get the time stamps).
And yes, the documentation is severely lacking, indeed. Hopefully this will get better, bit by little bit. So anyway, I don't mind answering a question here, then; you didn't miss anything in the docs.If I misunderstood or missed some of your questions, or you have follow-up questions, please don't hesitate to get back to me!