Code used in the research of English dialect classification.
These files have the goal of taking .wav audio files, generating force-aligned phoneme transcriptions, and outputting sound metrics into a .csv file. This data can then be analyzed using a series of Python classes and methods.
- note - before the process begins labeled audio files must be put into the montreal-input and montreal-output directories
- wav_conversion.py - a Python script with a single function
convert_mp3_to_wav()used to convert a directory of .mp3 files into .wav files (only necessary if this is not already the case) - textgrid_creation.py - a Python script with a single function
create_textgrids()used to generate a series of textgrids in the specified directory that have the specified text as a single interval - custom_mfa_align.py - a Python script with a single function
align()that runs a series of Montreal Forced Aligner terminal operations to align the textgrids in a specified directory - formant-extraction.py - a Praat script which extracts formant measurements and other sound metrics from each phoneme in the textgrids of the specified directory, outputting results
into a spreadsheet named formants.csv
A Python script with two classes.
- h_input
- is initialized with the arguments
raw_datawhich should be a pandas dataframe produced from the output of formant_extraction.py andid_varswhich are non-value features of the output produced by formant_extraction.py - the instance variable
self.input_dfrepresents the processed dataframe processmethod takes argumentslocation_specificity="country"andvowels_only=Trueselect_featuresmethod takes the argumentselected_features=['F1']and drops other features fromself.input_dfnormalizemethod takes the argumentmethod='z'- if
method=='z'then features will be normalized using standardization, ifmethod=='minmax'then features will be normalized using min-max normalization select_placesmethod takes the argumentplaces=["uk", "usa"]and drops samples that aren't labeled with these locationsrevertmethod removes previous processing and brings the input dataframe back to its original stateoutput_input_dfmethod takes the argumentfilename="input_df.csv"
- is initialized with the arguments
- h_model
- takes the dataframe from the processed
self.input_dfto be used in the implementation of different statistical models - is initialized with the arguments
datawhich should be a copy ofself.input_df,model_featureswhich should be a list of features in this dataframe to be modeled,y_featurewhich should be the feature to be predicted (likely location), andy_mainwhich should be the particular value ofy_featurewhich will be separated from the rest (these models perform binary classification, predicting whether a sample is labeled withy_mainor any other label) - the
fitmethod takes argumentsmodel_type="rforest",cv_method="LOO",test_size=0.30if the"train-test"cross validation method is being used, andvar_imp_type="mdi"which specifies the type of variable importance metric to be calculated
- takes the dataframe from the processed
- gmu_scraping.py - this file scrapes from the GMU Archive all of the English language files and their demographic information as .wav files as seen in the specified directory
- LICENSE - basic MIT License
- README - this file
- gmu-modeling.ipynb - jupyter notebook used for modeling the GMU Archive data
- data - all of the audio tracks, aligned textgrids, and output .csv files from all of the English language samples in the two example datasets
These files correspond to Python files but with less functionality and running in Praat.
- wav-conversion.praat
- textgrid-creation.praat
- formant-extraction-praat
- Text alignment can be done without the custom_mfa_align.py file using the Montreal Forced Aligner directly in the terminal.
- The following lines of code download the models necessary for forced alignment. Other models may be used.
mfa model download acoustic english_us_arpa
mfa model download dictionary english_us_arpa
mfa align --clean CORPUS_DIRECTORY DICTIONARY_PATH ACOUSTIC_MODEL_PATH OUTPUT_DIRECTORYimplements the forced aligner
mfa align --clean /home/user/montreal-input english_us_arpa english_us_arpa /home/user/montreal-output(example) - adapted from this tutorial by Eleanor Chodroff