<jupyter_start><jupyter_text>Formant Frequencies  Measuring Formants  Import modules<jupyter_code>import parselmouth
from parselmouth.praat import call
from glob import glob
import os
import pandas as pd<jupyter_output><empty_output><jupyter_text>Create list of files<jupyter_code>file_list = sorted(glob("/home/david/Sharing/fromant_check_for_averageness/new_voices/new_voices/*.wav"))
basename_list = [os.path.splitext(os.path.basename(filename))[0] for filename in file_list]
basename_list[:5]<jupyter_output><empty_output><jupyter_text>Load the sounds into Parselmouth-Praat<jupyter_code>sounds = [parselmouth.Sound(sound_file) for sound_file in file_list]
sounds[:5]<jupyter_output><empty_output><jupyter_text>Measure the formants  Analysis parameters matter- Maximum Formant    - This is the highest frequency a formant could be    - Children's voices - 7000 Hz, 8000 Hz    - Adult voices        - Lower pitched voices use 5000        - Higher pitched voices use 5500    - Our cutoff will be 170 Hz or about the average difference between female and male voice pitch  `if` the voice pitch is low, use `5000`; `elif` the voice pitch is high, use `5500`<jupyter_code>def measure_formants(sound):
    pitch = sound.to_pitch()
    mean_pitch = call(pitch, "Get mean", 0, 0, "Hertz")
    if mean_pitch < 170:
        max_formant = 5000
    elif mean_pitch >= 170:
        max_formant = 5500
    else:
        max_formant = 5500  # It's always good to have a fallback value just in case
    formants = sound.to_formant_burg(maximum_formant=max_formant)
    t0 = formants.xs()[0]
    t1 = formants.xs()[-1]
    t0_f1 = call(formants, "Get value at time", 1, formants.xs()[0], "Hertz", "Linear")
    t1_f1 = call(formants, "Get value at time", 1, formants.xs()[1], "Hertz", "Linear")
    t0_f2 = call(formants, "Get value at time", 2, formants.xs()[0], "Hertz", "Linear")
    t1_f2 = call(formants, "Get value at time", 2, formants.xs()[1], "Hertz", "Linear")
    t0_f3 = call(formants, "Get value at time", 3, formants.xs()[3], "Hertz", "Linear")
    t1_f3 = call(formants, "Get value at time", 3, formants.xs()[3], "Hertz", "Linear")
    t0_f4 = call(formants, "Get value at time", 4, formants.xs()[4], "Hertz", "Linear")
    t1_f4 = call(formants, "Get value at time", 4, formants.xs()[4], "Hertz", "Linear")
    return t0, t1, t0_f1, t1_f1, t0_f2, t1_f2, t0_f3, t1_f3, t0_f4, t1_f4<jupyter_output><empty_output><jupyter_text>Take the first and last formant value for each file and save the times and values<jupyter_code>t0_list = []
t1_list = []
t0_f1_list = []
t1_f1_list = []
t0_f2_list = []
t1_f2_list = []
t0_f3_list = []
t1_f3_list = []
t0_f4_list = []
t1_f4_list = []
for sound in sounds:
    t0, t1, t0_f1, t1_f1, t0_f2, t1_f2, t0_f3, t1_f3, t0_f4, t1_f4 = measure_formants(sound)
    t0_list.append(t0)
    t1_list.append(t1)
    t0_f1_list.append(t0_f1)
    t1_f1_list.append(t1_f1)
    t0_f2_list.append(t0_f2)
    t1_f2_list.append(t1_f2)
    t0_f3_list.append(t0_f3)
    t1_f3_list.append(t1_f3)
    t0_f4_list.append(t0_f4)
    t1_f4_list.append(t1_f4)<jupyter_output><empty_output><jupyter_text>Put Data into Pandas Dataframe<jupyter_code>df = pd.DataFrame({
    "filename":file_list,
    "file": basename_list,
    "t0":t0_list,
    "t1":t1_list,
    "t0_f1":t0_f1_list,
    "t1_f1":t1_f1_list,
    "t0_f2":t0_f2_list,
    "t1_f2":t1_f2_list,
    "t0_f3":t0_f3_list,
    "t1_f3":t1_f3_list,
    "t0_f4":t0_f4_list,
    "t1_f4":t1_f4_list,
})
df.head()<jupyter_output><empty_output><jupyter_text>Save Data<jupyter_code>df.to_csv('/home/david/Sharing/fromant_check_for_averageness/new_voices/new_voices/formant_measures_straight.csv', index=0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12879609544468545, 'fraction_numerical': 0.05775488069414317, 'mean_word_length': 4.818611987381703, 'pattern_counts': {'":': 12, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '163879', 'license': 'MIT', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1558, 'n_words': 310, 'path': 'Formant Frequencies STRAIGHT.ipynb', 'repo_name': 'drfeinberg/STRAIGHT-AutoDelineation', 'size': '3688'}