############################################################################### # divideNoise4-automatic.praat (Modified by Kyuchul Yoon, kyoon@kyungnam.ac.kr) ############################################################################### # DIVIDING NOISE into fricative & aspiration # Written by Kyuchul Yoon, kyoon@ling.osu.edu with much help from Mary Beckman # The values "dividing frequency and criterion value" can be determined # by trial and error based on spectrogram observation. ############################################################################### # Dividing noise proceeds by extracting successive windowed selections, # making spectra, and calculating band energy differences. ############################################################################### # divideNoise2.praat # Does the dividing for the files in the specified folder. # The folder should contain files from THE SAME speaker because the script was # written under the assumption that the criterionValue will be the same for the # same speaker. ############################################################################### # This version (3) focuses on improving the ease of use in finding the # criterionValue. ==> Creates a log file so that user can see the criterionValue # Version 4 ==> Displays the criterionValue in the Praat info. window # Version 4 - automatic ==> Hide the confirmation popup window once the # criterionValue is decided # Aspiration boundary name is "automatic" ############################################################################### form Select a file and parameters for spectral analysis word inputFolder_(without_extension) repeated word soundExtension_(with_dot) .wav word textgridExtension_(with_dot) .TextGrid positive dividingFrequency_(Hz_for_noise_analysis) 3800 real criterionValue_(dB_for_noise_analysis) -400 word windowShape Hamming positive timeStep_(sec._for_noise_windowing) 0.005 word boundaryLabel automatic comment A log file to contain important information word logFile log_repeated_automatic.txt endform # Clears the Info window just in case. clearinfo # Make a list of all sound files in the folder. Create Strings as file list... fileListObj 'inputFolder$'/*'soundExtension$' Sort numFiles = Get number of strings pause 'numFiles' sound files identified. Continue? printline time_sec'tab$'H_band_E_Sum'tab$'L_band_E_Sum'tab$'criterionValue fileappend 'logFile$' fileName'tab$'specBegin'tab$'H_band_E_Sum'tab$'L_band_E_Sum ...'tab$'criterionValue'newline$' # Loop through each file. for iFile to numFiles select Strings fileListObj soundName$ = Get string... iFile prefix$ = soundName$ - soundExtension$ textgridName$ = prefix$ + textgridExtension$ Read from file... 'inputFolder$'/'soundName$' Rename... soundObj Read from file... 'inputFolder$'/'textgridName$' Rename... textgridObj # Temporary matrix file for picking out aspiration location tempOut$ = "tempOut" filedelete 'tempOut$' # Flag for presence of aspiration point in TextGrid aspBegin = 0 select TextGrid textgridObj numLabels = Get number of points... 1 for i from 1 to numLabels label$ = Get label of point... 1 i if label$ = "fricative" noiseBegin = Get time of point... 1 i elsif label$ = boundaryLabel$ aspBegin = Get time of point... 1 i elsif label$ = "vowelBegin" noiseEnd = Get time of point... 1 i endif endfor # If there's already an aspiration point, delete it so we can try again if aspBegin > 0 select TextGrid textgridObj Edit editor TextGrid textgridObj Move cursor to... aspBegin Remove Close endeditor endif specNum = 0 repeat select Sound soundObj Edit editor Sound soundObj specBegin = noiseBegin + timeStep * specNum specEnd = specBegin + timeStep Select... specBegin specEnd Extract windowed selection... slice 'windowShape$' 1 yes Close endeditor # Band energy querying across supplied dividing frequency To Spectrum To Ltas (1-to-1) numBands = Get number of bands divBand = Get band from frequency... dividingFrequency divBand = floor(divBand) lowBandEnergySum = 0 for i from 1 to divBand lowEnergy = Get value in band... i lowBandEnergySum = lowBandEnergySum + lowEnergy endfor highBandEnergySum = 0 for k from (divBand + 1) to numBands highEnergy = Get value in band... k highBandEnergySum = highBandEnergySum + highEnergy endfor subtracted = highBandEnergySum - lowBandEnergySum fileappend 'tempOut$' 'specBegin:4' 'tab$' 'subtracted:4' 'newline$' fileappend 'logFile$' 'textgridName$''tab$''specBegin:4''tab$' ...'highBandEnergySum:0''tab$''lowBandEnergySum:0''tab$''subtracted:2' ...'newline$' # Print the same info in the Info window printline 'specBegin:4''tab$''tab$''highBandEnergySum:0''tab$''tab$' ...'lowBandEnergySum:0''tab$''tab$''subtracted:2' select Sound slice plus Ltas slice plus Spectrum slice Remove specNum = specNum + 1 # Stop if windowed selection crosses over end of noise segment until (specBegin > noiseEnd - timeStep) # Read in the values from the temporary output file and determine point # where criterion value has been reached Read Matrix from raw text file... 'tempOut$' sliceNum = 1 halfNoise = (noiseEnd - noiseBegin) / 5 + noiseBegin repeat sliceNum = sliceNum + 1 sliceTime = Get value in cell... sliceNum 1 sliceRatio = Get value in cell... sliceNum 2 until ((sliceRatio <= criterionValue) and (halfNoise <= sliceTime)) select Matrix 'tempOut$' Remove # Write a label there select TextGrid textgridObj Insert point... 1 sliceTime 'boundaryLabel$' Write to text file... 'inputFolder$'/'textgridName$' # And in the Info window, tell the user what you did printline printline criterionValue 'criterionValue' at 'sliceTime' seconds printline fileappend 'logFile$' 'newline$'criterionValue 'criterionValue' ... at 'sliceTime' seconds'newline$''newline$' # Delete the temporary matrix file filedelete 'tempOut$' # Get time of vowelEnd for TextGrid confirmation # noiseBegin is already defined earlier vowelEnd = Get time of point... 1 4 select Sound soundObj Edit editor Sound soundObj Select... noiseBegin-0.1 vowelEnd+0.1 Zoom to selection Close endeditor plus TextGrid textgridObj Edit # Comment the following line to make this script run continuously #pause Check 'textgridName$' aspiration point! Remove endfor select Strings fileListObj Remove ####### END OF SCRIPT #########