|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
form Extract formant values: |
|
|
comment Basic settings: |
|
|
sentence Directory_name: /Users/miaozhang/Downloads/MFA_tutorial_MZ_2025/hsb_v21/validated |
|
|
sentence Output_name: /Users/miaozhang/Downloads/MFA_tutorial_MZ_2025/hsb_v21/output |
|
|
sentence Log_file _i |
|
|
sentence Interval_label i |
|
|
positive Labeled_tier_number 2 |
|
|
positive Number_of_chunks 3 |
|
|
|
|
|
comment Formant extracing settings: |
|
|
positive Analysis_points_time_step 0.005 |
|
|
positive Formant_ceiling 4000 |
|
|
positive Number_of_formants 4 |
|
|
positive Window_length 0.025 |
|
|
positive Preemphasis_from 50 |
|
|
positive Buffer_window_length 0.04 |
|
|
|
|
|
comment Reference formant values: |
|
|
positive F1_ref 250 |
|
|
positive F2_ref 2000 |
|
|
positive F3_ref 2800 |
|
|
positive F4_ref 3600 |
|
|
positive F5_ref 4660 |
|
|
endform |
|
|
|
|
|
|
|
|
fileappend 'directory_name$''log_file$'.txt File_name'tab$'Intv_id'tab$'Seg'tab$'t'tab$'t_m'tab$'F1'tab$'F2'tab$'F3'tab$'F4'newline$' |
|
|
|
|
|
|
|
|
Create Strings as file list: "fileList", output_name$ + "/*.TextGrid" |
|
|
selectObject: "Strings fileList" |
|
|
num_file = Get number of strings |
|
|
|
|
|
|
|
|
for i_file from 1 to num_file |
|
|
selectObject: "Strings fileList" |
|
|
file_name$ = Get string: i_file |
|
|
Read from file: output_name$ + "/" + file_name$ |
|
|
|
|
|
|
|
|
sound_name$ = selected$("TextGrid") |
|
|
tg_file = selected("TextGrid") |
|
|
|
|
|
|
|
|
Read from file: directory_name$ + "/" + sound_name$ + ".TextGrid" |
|
|
sound_file = selected("Sound") |
|
|
|
|
|
|
|
|
selectObject: tg_file |
|
|
num_labels = Get number of intervals: labeled_tier_number |
|
|
|
|
|
|
|
|
for i_label from 1 to num_labels |
|
|
|
|
|
|
|
|
selectObject: tg_file |
|
|
label$ = Get label of interval: labeled_tier_number, i_label |
|
|
|
|
|
|
|
|
if label$ = interval_label$ |
|
|
|
|
|
writeInfoLine: "Extracting formants from..." |
|
|
appendInfoLine: " Sound file < 'i_file' of 'num_file'>: < 'sound_name$' >." |
|
|
appendInfoLine: " Interval ['i_label']: <'label$'>." |
|
|
|
|
|
|
|
|
label_start = Get starting point: labeled_tier_number, i_label |
|
|
label_end = Get end point: labeled_tier_number, i_label |
|
|
|
|
|
dur = label_end - label_start |
|
|
|
|
|
|
|
|
|
|
|
fstart = label_start - buffer_window_length |
|
|
fend = label_end + buffer_window_length |
|
|
|
|
|
|
|
|
selectObject: sound_file |
|
|
Extract part: fstart, fend, "rectangular", 1, "no" |
|
|
extracted = selected("Sound") |
|
|
|
|
|
|
|
|
chunk_length = dur/number_of_chunks |
|
|
|
|
|
|
|
|
selectObject: extracted |
|
|
To Formant (burg): analysis_points_time_step, number_of_formants, formant_ceiling, window_length, preemphasis_from |
|
|
formant_burg = selected("Formant") |
|
|
num_form = Get minimum number of formants |
|
|
|
|
|
|
|
|
if num_form = 2 |
|
|
number_tracks = 2 |
|
|
elif num_form = 3 |
|
|
number_tracks = 3 |
|
|
else |
|
|
number_tracks = 4 |
|
|
endif |
|
|
|
|
|
|
|
|
select 'formant_burg' |
|
|
Track: number_tracks, f1_ref, f2_ref, f3_ref, f4_ref, f5_ref, 1, 1, 1 |
|
|
formant_tracked = selected("Formant") |
|
|
|
|
|
for i_chunk from 1 to number_of_chunks |
|
|
appendInfoLine: " chunk ['i_chunk']..." |
|
|
|
|
|
|
|
|
chunk_start = buffer_window_length + (i_chunk - 1) * chunk_length |
|
|
chunk_end = buffer_window_length + i_chunk * chunk_length |
|
|
chunk_mid = buffer_window_length + chunk_length/2 + (i_chunk - 1) * chunk_length |
|
|
|
|
|
|
|
|
fileappend 'directory_name$''log_file$'.txt 'file_name$''tab$''i_label''tab$''label$''tab$''i_chunk''tab$''chunk_mid:3''tab$' |
|
|
|
|
|
|
|
|
select 'formant_tracked' |
|
|
|
|
|
f1 = Get mean: 1, chunk_start, chunk_end, "hertz" |
|
|
if f1 = undefined |
|
|
f1 = 0 |
|
|
endif |
|
|
|
|
|
|
|
|
f2 = Get mean: 2, chunk_start, chunk_end, "hertz" |
|
|
if f2 = undefined |
|
|
f2 = 0 |
|
|
endif |
|
|
|
|
|
|
|
|
f3 = Get mean: 3, chunk_start, chunk_end, "hertz" |
|
|
if f3 = undefined |
|
|
f3 = 0 |
|
|
endif |
|
|
|
|
|
|
|
|
f4 = Get mean: 4, chunk_start, chunk_end, "hertz" |
|
|
if f4 = undefined |
|
|
f4 = 0 |
|
|
endif |
|
|
|
|
|
|
|
|
fileappend 'directory_name$''log_file$'.txt 'f1:0''tab$''f2:0''tab$''f3:0''tab$''f4:0''newline$' |
|
|
endfor |
|
|
|
|
|
removeObject: formant_tracked, formant_burg, extracted |
|
|
|
|
|
else |
|
|
|
|
|
endif |
|
|
endfor |
|
|
|
|
|
removeObject: sound_file, tg_file |
|
|
|
|
|
endfor |
|
|
|
|
|
select all |
|
|
Remove |
|
|
|
|
|
writeInfo: "All done!" |
|
|
|