## Scale intensity of all sounds in a Directory ##### Check for clipped extrema ## Matthew B. Winn ## December 2012 ## NOTE: It helps to have the Praat info window open as you run this script, ###### as it will update info for you as it proceeds. ## Once the script is done and you choose to save the files, #### Look in the original sound directory - there you will find a new sub-folder of normalized sounds. form Input Enter specifications for Intensity scaling comment Enter desired intensity (dB): real intensity 75 comment Enter directory where the ORIGINAL sound files will be retrieved: sentence soundDir C:\Enter-Your-Directory-Here comment Enter filename to which the info should be written sentence outFile intensity_info.txt endform call changeIntensities procedure changeIntensities clearinfo clippedSounds = 0 # Reads in a list of files Create Strings as file list... list 'soundDir$'\*.wav numberOfFiles = Get number of strings # make a list of each sound in the directory for thisFile to numberOfFiles select Strings list fileName$ = Get string... thisFile name$ = fileName$ - ".wav" # Reads in all sound (wav) files Read from file... 'soundDir$'\'name$'.wav # get intensity of the original sound old_Int = Get intensity (dB) print 'name$' was 'old_Int:1' # scale it to the user-defined intensity Scale intensity... 'intensity' int_diff = 'intensity' - 'old_Int' print & adjusted by 'int_diff:2' to get 'intensity:1' 'tab$' # Check to see if it clips max = Get absolute extremum... 0 0 Sinc70 if max >= 1 clippedSounds = clippedSounds + 1 print CLIPPED endif print 'newline$' endfor # decide whether you want to save the files call userSelectSave endproc procedure userSelectSave choice = 1 beginPause ("'clippedSounds' sounds have been clipped") comment ("'clippedSounds' sounds have been clipped") comment ("Do you want to save the files?") optionMenu ("Choice", choice) option ("Yes - save the sounds") option ("No - Quit") option ("Lower level by 1 dB and try again") option ("Lower level by 2 dB and try again") option ("Lower level by 3 dB and try again") option ("Lower level by 4 dB and try again") option ("Lower level by 5 dB and try again") comment ("Then click Continue.") endPause ("Continue", 1) if choice = 1 call saveSounds elsif choice = 2 select all Remove else select all Remove intensity = intensity-(choice-2) call changeIntensities endif endproc procedure saveSounds # makes a directory system mkdir 'soundDir$'\Intensity'intensity' # first deletes any existing output file filedelete 'soundDir$'\'outFile$' # creates simple header fileappend Step 'tab$' Duration 'tab$' 'newline$' for thisFile to numberOfFiles select Strings list fileName$ = Get string... thisFile name$ = fileName$ - ".wav" select Sound 'name$' Save as WAV file... 'soundDir$'\Intensity'intensity'\'name$'.wav endfor call saveInfoWindow "'soundDir$'\Intensity'intensity'" IntensityInfo select Strings list Remove endproc procedure saveInfoWindow outputDirectory$ outputFileName$ filedelete 'outputDirectory$'\'outputFileName$'.txt fappendinfo 'outputDirectory$'\'outputFileName$'.txt endproc # # ## ### ##### ######## ############# ##################### ##################################