#! praat # # Load all MFCC reference files and compare the recorded test sound to them # Chose the reference file with the lowest distance # 'exclude$' contains a regexp pattern that deselects unwanted reference files # The number of coefficients should match those in the reference files # (which should be readable from a Praat script, but aren't) # # word pinyin duo1shao3 # word test_word wav/duo1shao3/duo1shao3_duo1shao3_F20DUTB1BS01_2006-12-11T2-00.wav # word reference_dir mfcc # word exclude F20DUTB1BS01 # positive number_of_Coefficients 12 procedure PronunciationRecognition pinyin$ test_word$ reference_dir$ exclude$ number_of_Coefficients referenceExt$ = "mfcc" debug = 1 Create Strings as file list... ReferenceList 'reference_dir$'/'pinyin$'/'pinyin$'*.'referenceExt$' numberOfReferences = Get number of strings for i from 1 to numberOfReferences select Strings ReferenceList inFile$ = Get string... 'i' if exclude$ = "" or rindex_regex(inFile$, exclude$) <= 0 referenceName$ = replace_regex$(inFile$, "."+referenceExt$+"$", "-'i'", 0) Read from file... 'reference_dir$'/'pinyin$'/'inFile$' Rename... 'referenceName$' endif endfor # Convert input to MFCC if test_word$ <> "" and test_word$ <> "REUSEMFCC" Read from file... 'test_word$' Rename... Source endif if test_word$ <> "REUSEMFCC" select Sound Source noprogress To MFCC... 'number_of_Coefficients' 0.015 0.005 100.0 100.0 0.0 Rename... Source endif smallestDistance=999999 choiceReference$ = "empty" for i from 1 to numberOfReferences select Strings ReferenceList inFile$ = Get string... 'i' if exclude$ = "" or rindex_regex(inFile$, exclude$) <= 0 referenceName$ = replace_regex$(inFile$, "."+referenceExt$+"$", "-'i'", 0) select MFCC 'referenceName$' plus MFCC Source noprogress To DTW... 1.0 0.0 0.0 0.0 0.056 yes yes no restriction Rename... DTW'i' distance = Get distance (weighted) if debug > 1 printline 'i': 'distance' - 'referenceName$' endif if distance < smallestDistance smallestDistance = distance choiceReference$ = "'distance' - 'referenceName$'" endif # Clean up select DTW DTW'i' Remove endif endfor if debug > 0 printline printline Match: 'test_word$' <== 'choiceReference$' endif # Clean up for i from 1 to numberOfReferences select Strings ReferenceList inFile$ = Get string... 'i' if exclude$ = "" or rindex_regex(inFile$, exclude$) <= 0 referenceName$ = replace_regex$(inFile$, "."+referenceExt$+"$", "-'i'", 0) # Clean up select MFCC 'referenceName$' Remove endif endfor select Strings ReferenceList if test_word$ <> "" and test_word$ <> "REUSEMFCC" plus Sound Source endif plus MFCC Source Remove endproc