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