## ## This Praat script adds white noise to all the sound files in a given directory. ## The processed sound files are saved in a predefined directory; the original sound files are intact. ## -The user can specify if the sound files are to be prescaled to a given intensity level. ## -The user can specify the S/N ratio of the sound and the white noise. ## ## Author: Lei He (Phonetics Laboratory, Universität Zürich) ## lei.he@uzh.ch; helei@rocketmail.com 16.06.2014 ## form Add white noise to your sound objects comment «This program adds white noise to your sound file with assigned S/N ratio» comment Please specify the S/N ratio (signalSound:noiseSound): real Signal_to_noise_ratio_(dB) 15 comment Please specify the path of the original sound files: text Out_directory /Users/leihe/Documents/tevoid/wavAndTextgrid/ comment Please specify the path of the processed sound files: text In_directory /Users/leihe/Documents/Tevoid_Noise/ comment Please specify the tag for the processed sound files: word Tag _Noise comment Check to show counter: boolean Show_counter 1 comment Check to confirm scaling all sound files to a given intensity level. boolean Pre_intensity_scaling 1 comment What intensity level do you want to scale to: positive Prescaling_at_(dB-SPL) 68 comment Formulae for reference and cross-checking: comment -- 10*log10[signalPower/noisePower] = S:Nratio comment -- log10[signalPower]-log10[noisePower] = S:Nratio/10 comment -- noisePower = 10^(log10[signalPower] - S:Nratio/10) endform beginPause: "Parameters setting" comment: "Please set the parameters for creating the intensity object of the signal sound." positive: "Minimum pitch (Hz)", 100 real: "Time step (s)", 0.0 boolean: "Substract mean", 1 comment: "Please specify the averaging method to query the mean intensity of the signal" comment: "sound." choice: "Averaging method", 1 option: "energy" option: "sones" option: "dB" endPause: "OK", 1 wavFileList = Create Strings as file list: "wavFileList", "'out_directory$'*.wav" nFiles = Get number of strings for iFile to nFiles select wavFileList wavName$ = Get string: iFile baseName$ = wavName$-".wav" soundSignal = Read from file: "'out_directory$''wavName$'" if pre_intensity_scaling = 1 select soundSignal soundScaled = Copy: "'baseName$'_scaled" Scale intensity: prescaling_at #nocheck pause select soundScaled samplingRate = Get sampling frequency intensityScaled = To Intensity: minimum_pitch, time_step, substract_mean select intensityScaled duration = Get total duration dBsplScaled = Get mean: 0.0, 0.0, averaging_method$ soundNoise = Create Sound from formula: "noise", 1, 0.0, duration, samplingRate, "randomGauss(0,0.1)" select soundNoise dBsplNoise = Scale intensity: dBsplScaled - signal_to_noise_ratio select soundNoise plus soundScaled stereo = Combine to stereo select stereo product = Convert to mono select product Save as WAV file: "'in_directory$''baseName$''tag$'.wav" select soundSignal plus soundNoise plus soundScaled plus intensityScaled plus stereo plus product Remove else select soundSignal samplingRate = Get sampling frequency intensitySignal = To Intensity: minimum_pitch, time_step, substract_mean select intensitySignal duration = Get total duration dBsplSignal = Get mean: 0.0, 0.0, averaging_method$ soundNoise = Create Sound from formula: "noise", 1, 0.0, duration, samplingRate, "randomGauss(0,0.1)" select soundNoise dBsplNoise = Scale intensity: dBsplSignal - signal_to_noise_ratio select soundNoise plus soundSignal stereo = Combine to stereo select stereo product = Convert to mono select product Save as WAV file: "'in_directory$''baseName$''tag$'.wav" select soundSignal plus soundNoise plus intensitySignal plus stereo plus product Remove endif if show_counter = 1 writeInfoLine: "*** Calculation in process ***" appendInfoLine: " " appendInfoLine: ">>> , 'baseName$''tag$'" appendInfoLine: (iFile/nFiles)*100,"% finished" appendInfoLine: (1-(iFile/nFiles))*100,"% left" endif endfor select wavFileList Remove ###END###