tomwalters@335: #!/bin/bash tomwalters@335: # Copyright 2009-2010 Thomas Walters tomwalters@335: # tomwalters@335: # Add pink noise to the CNBH syllables database. The first argument is the tomwalters@335: # path to the clean .wav files. The second argument is a quoted list of the tomwalters@335: # desired SNRs in dB, separated by spaces. Directories are made for each SNR tomwalters@335: # in the directory above that given in the first argument. tomwalters@335: set -e tomwalters@335: set -u tomwalters@335: tomwalters@335: CLEAN_SYLLABLES_DATABASE_PATH=$1 tomwalters@335: SIGNAL_TO_NOISE_RATIOS=$2 tomwalters@335: tomwalters@335: # The syllables database is approximately at -9dB re. the max RMS level for a tomwalters@335: # .wav file. tomwalters@335: REFERENCE_SIGNAL_LEVEL="-9" tomwalters@335: SAMPLE_RATE=48000 tomwalters@335: tomwalters@335: PREV_DIR=`pwd` tomwalters@335: cd $CLEAN_SYLLABLES_DATABASE_PATH tomwalters@335: tomwalters@335: for SNR in ${SIGNAL_TO_NOISE_RATIOS}; do tomwalters@355: echo "Generating noisy data for SNR ${SNR}dB" tomwalters@335: if [ ! -e ../snr_${SNR}dB/.pink_noise_success ] tomwalters@335: then tomwalters@335: mkdir -p ../snr_${SNR}dB/ tomwalters@335: VOWELS="a e i o u" tomwalters@335: CONSONANTS="b d f g h k l m n p r s t v w x y z" tomwalters@335: for v in $VOWELS; do tomwalters@335: mkdir ../snr_${SNR}dB/$v$v tomwalters@335: for c in $CONSONANTS; do tomwalters@335: mkdir ../snr_${SNR}dB/$c$v tomwalters@335: mkdir ../snr_${SNR}dB/$v$c tomwalters@335: done tomwalters@335: done tomwalters@335: NOISE_LEVEL=$(( $REFERENCE_SIGNAL_LEVEL - $SNR )) tomwalters@335: for file in `find . -iname "*.wav"`; do tomwalters@335: # Note: the 0.684 below is the length of each syllable in the database tomwalters@335: # in seconds tomwalters@335: sox -r ${SAMPLE_RATE} -b 16 -n -t s2 - synth 0.684 pinknoise vol ${NOISE_LEVEL} dB | sox -m -v 0.25 $file -t s2 -r ${SAMPLE_RATE} -c 1 - ../snr_${SNR}dB/${file} tomwalters@335: done tomwalters@335: touch ../snr_${SNR}dB/.pink_noise_success tomwalters@335: fi tomwalters@335: done tomwalters@335: cd $PREV_DIR