Commit 8bd0ffec authored by Vijayaditya Peddinti's avatar Vijayaditya Peddinti
Browse files

trunk/aspire : Modified RIR preparation scripts to reduce reliance on python, removed minor bugs

git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@5175 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
parent 066a6102
#!/bin/bash
# Script to check the tool versions necessary for the aspire recipe
python -c "
from distutils.version import LooseVersion
import warnings, sys
try:
import scipy
if LooseVersion(scipy.__version__) < LooseVersion('0.15.1'):
warnings.warn('This recipe has not been tested on scipy version below 0.15.1. It is strongly recommended that an updated scipy version be used.')
sys.exit(1)
except ImportError:
warnings.warn('This recipe requires scipy version 0.15.1')
sys.exit(1)
" || exit 1;
......@@ -5,20 +5,31 @@
# the common scaling factor is computed to 1/\sqrt(1/(total_samples) * \sum_i{\sum_j x_i(j)^2}) where total_samples is sum of all samples of all wavefiles. If the data is multi-channel then each channel is treated as a seperate wave files
import argparse, scipy.io.wavfile, warnings, numpy as np, math
def normalize(file_list, is_rir, additional_scaling):
def get_normalization_coefficient(file_list, is_rir, additional_scaling):
assert(len(file_list) > 0)
sampling_rate = None
total_energy = 0.0
total_samples = 0.0
prev_dtype_max_value = None
for file in file_list:
try:
[rate, data] = scipy.io.wavfile.read(file)
if not str(data.dtype) in set(['int16', 'int32', 'int64']):
raise Exception('Cannot process {0}, only wav files of integer type are suppported'.format(file))
dtype_max_value = np.iinfo(data.dtype).max
# ensure that all the data in the current list is of the same format
if prev_dtype_max_value is not None:
assert(dtype_max_value == prev_dtype_max_value)
prev_dtype_max_value = dtype_max_value
if len(data.shape) == 1:
data = data.reshape([data.shape[0], 1])
if sampling_rate is not None:
assert(rate == sampling_rate)
else:
sampling_rate = rate
data = data / dtype_max_value
if is_rir:
# just count the energy of the direct impulse response
# this is treated as energy of signal from 0.001 seconds before impulse
......@@ -34,10 +45,13 @@ def normalize(file_list, is_rir, additional_scaling):
else:
start_index = 0
end_index = data.shape[0]
total_energy += float(np.sum(data[start_index:end_index, :] ** 2))
# numpy does not check for numerical overflow in integer type
# so we convert the data into floats
data = data.astype(np.float64)
total_energy += np.sum(data[start_index:end_index, :] ** 2)
data_shape = list(data.shape)
data_shape[0] = end_index-start_index
total_samples += float(np.prod(data_shape))
total_samples += np.prod(data_shape)
except IOError:
warnings.warn("Did not find the file {0}.".format(file))
assert(total_samples > 0)
......@@ -45,9 +59,7 @@ def normalize(file_list, is_rir, additional_scaling):
print "Scaling coefficient is {0}.".format(scaling_coefficient)
if math.isnan(scaling_coefficient):
raise Exception(" Nan encountered while computing scaling coefficient. This is mostly due to numerical overflow")
for file in file_list:
[rate, data] = scipy.io.wavfile.read(file)
scipy.io.wavfile.write(file, rate, data * scaling_coefficient * additional_scaling)
return scaling_coefficient
if __name__ == "__main__":
usage = """ Python script to normalize input wave file list"""
......@@ -56,6 +68,7 @@ if __name__ == "__main__":
parser.add_argument('--is-room-impulse-response', type=str, default = "false", help='is the input a list of room impulse responses', choices = ['True', 'False', 'true', 'false'])
parser.add_argument('--extra-scaling-factor', type=float, default = 1.0, help='additional scaling factor to be multiplied with the wav files')
parser.add_argument('input_file_list', type=str, help='list of wav files to be normalized collectively')
parser.add_argument('output_file', type=str, help='output file to store normalization coefficient')
params = parser.parse_args()
if params.is_room_impulse_response.lower() == 'true':
params.is_room_impulse_response = True
......@@ -66,4 +79,7 @@ if __name__ == "__main__":
for line in open(params.input_file_list).readlines():
if len(line.strip()) > 0 :
file_list.append(line.strip())
normalize(file_list, params.is_room_impulse_response, params.extra_scaling_factor)
norm_coefficient = get_normalization_coefficient(file_list, params.is_room_impulse_response, params.extra_scaling_factor)
out_file = open(params.output_file, 'w')
out_file.write('{0}'.format(norm_coefficient))
out_file.close()
......@@ -6,199 +6,50 @@
# This script processes RIRs available from available databases into
# 8Khz wav files so that these can be used to corrupt the Fisher data.
# The databases used are:
# RWCP : http://research.nii.ac.jp/src/en/RWCP-SSD.html (this data is provided with the recipe. Thanks to Mitsubishi Electric Research Laboratories)
# RWCP : http://research.nii.ac.jp/src/en/RWCP-SSD.html (this data is mirrored @ openslr.org. Thanks to Mitsubishi Electric Research Laboratories)
# AIRD : Aachen Impulse response database (http://www.ind.rwth-aachen.de/en/research/tools-downloads/aachen-impulse-response-database/)
# Reverb2014 : http://reverb2014.dereverberation.com/download.html
# OpenAIR : http://www.openairlib.net/auralizationdb
# MARDY : http://www.commsp.ee.ic.ac.uk/~sap/resources/mardy-multichannel-acoustic-reverberation-database-at-york-database/
# QMUL impulse response dataset : http://c4dm.eecs.qmul.ac.uk/rdr/handle/123456789/6
# Impulse responses from Varechoic chamber at Bell Labs : http://www1.icsi.berkeley.edu/Speech/papers/gelbart-ms/pointers/
# Concert Hall impulse responses, Aalto University : http://legacy.spa.aalto.fi/projects/poririrs/
stage=0
log_dir=log
stage=0
download_rirs=true # download the RIRs
sampling_rate=8000 # sampling rate to be used for the RIRs
log_dir=log # directory to store the log files
RIR_home=db/RIR_databases/ # parent directory of the RIR databases files
db_string="'aalto' 'air' 'rwcp' 'rvb2014' 'c4dm' 'varechoic' 'mardy' 'openair'" # RIR dbs to be used in the experiment
. cmd.sh
. path.sh
. utils/parse_options.sh
echo $*
if [ $# -ne 1 ]; then
echo "$0 outputdir"
exit 1;
fi
output_dir=$1
mkdir -p $output_dir
mkdir -p $output_dir/info
mkdir -p $output_dir/info ${output_dir}_non_normalized/info
mkdir -p $log_dir
rm -f $log_dir/type*.list
# download the necessary databases
if [ $stage -le 0 ]; then
mkdir -p db/RIR_databases
(cd db/RIR_databases
# download the AIR database
wget https://www2.ind.rwth-aachen.de/air/air_database_release_1_4.zip || exit 1;
unzip air_database_release_1_4.zip > /dev/null
# download reverb2014 database
wget http://reverb2014.dereverberation.com/tools/reverb_tools_for_Generate_mcTrainData.tgz || exit 1;
tar -zxvf reverb_tools_for_Generate_mcTrainData.tgz
wget http://reverb2014.dereverberation.com/tools/reverb_tools_for_Generate_SimData.tgz || exit 1;
tar -zxvf reverb_tools_for_Generate_SimData.tgz >/dev/null
# download RWCP sound scene database
wget http://www.openslr.org/resources/13/RWCP.tar.gz || exit 1;
tar -zxvf RWCP.tar.gz >/dev/null
)
if [ -z "$db_string" ]; then
echo "$0 : Please specify the db_string.";
exit 1;
fi
RWCP_home=db/RIR_databases/RWCP
AIR_home=db/RIR_databases/AIR_1_4
Reverb2014_home1=db/RIR_databases/reverb_tools_for_Generate_mcTrainData
Reverb2014_home2=db/RIR_databases/reverb_tools_for_Generate_SimData
# RWCP impulse responses and ambient noise
#-----------------------------------------
# all data is headerless binary type with little endian and 48 KHz
# impulse responses are float32 (4 byte)
# noises are short (2 byte)
# Data is multi-channel and each directory has a recording with each channel
# as a seperate file
sampling_rate=8000
# Impulse responses
RWCP_dirs=[]
RWCP_dirs[0]=$RWCP_home/micarray/MICARRAY/data1/
RWCP_dirs[1]=$RWCP_home/micarray/MICARRAY/data3/
RWCP_dirs[2]=$RWCP_home/micarray/MICARRAY/data5/
command_file=$log_dir/read_rir_noise.sh
echo "">$command_file
# micarray database
type_num=0
for base_dir_name in ${RWCP_dirs[@]}; do
type_num=$((type_num + 1))
leaf_directories=( $(find $base_dir_name -type d -links 2 -print || exit -1) )
files_done=0
total_files=$(echo ${leaf_directories[@]}|wc -w)
echo "Found ${total_files} impulse responses in ${base_dir_name}."
echo "" > $log_dir/type$type_num.rir.list
# create the list of commands to be executed
for leaf_dir_name in ${leaf_directories[@]}; do
output_file_name=`echo ${leaf_dir_name#$base_dir_name}| sed -e"s/[\/\]\+/_/g" | tr '[:upper:]' '[:lower:]'`
output_file_name=type${type_num}_rir_${output_file_name}.wav
echo "python local/multi_condition/read_rir.py --output-sampling-rate $sampling_rate rwcp/rir ${leaf_dir_name} ${output_dir}/${output_file_name} || exit -1" >> $command_file
echo ${output_dir}/${output_file_name} >> $log_dir/type$type_num.rir.list
files_done=$((files_done + 1))
done
done
# robot - non-directional microphone
type_num=$((type_num + 1))
data_files=( $(find $RWCP_home/robot/data/non -name '*.dat' -type f -print || exit -1) )
files_done=0
total_files=$(echo ${data_files[@]}|wc -w)
echo "" > $log_dir/type$type_num.rir.list
echo "Found $total_files impulse responses in ${RWCP_home}/robot/data/non."
# create the list of commands to be executed
for data_file in ${data_files[@]}; do
output_file_name=type${type_num}_rir_`basename $data_file .dat | tr '[:upper:]' '[:lower:]'`.wav
echo "python local/multi_condition/read_rir.py --output-sampling-rate $sampling_rate rwcp/rir ${data_file} ${output_dir}/${output_file_name} || exit -1;" >> $command_file
echo ${output_dir}/${output_file_name} >> $log_dir/type$type_num.rir.list
files_done=$((files_done + 1))
done
# Ambient noise
type_num=$((type_num + 1))
base_dir_name=$RWCP_home/micarray/MICARRAY/data6/
leaf_directories=( $(find $base_dir_name -type d -links 2 -print || exit -1) )
files_done=0
total_files=$(echo ${leaf_directories[@]}|wc -w)
echo "" > $log_dir/type$type_num.noise.list
echo "Found $total_files noises in ${base_dir_name}."
for leaf_dir_name in ${leaf_directories[@]}; do
output_file_name=`echo ${leaf_dir_name#$base_dir_name}| sed -e"s/[\/\]\+/_/g" | tr '[:upper:]' '[:lower:]'`
output_file_name=type${type_num}_noise_${output_file_name}.wav
echo "python local/multi_condition/read_rir.py --output-sampling-rate $sampling_rate rwcp/noise ${leaf_dir_name} ${output_dir}/${output_file_name} || exit -1" >> $command_file;
echo ${output_dir}/${output_file_name} >> $log_dir/type$type_num.noise.list
files_done=$((files_done + 1))
done
# AIR impulse responses
#----------------------
# data is stored in mat files with info about the impulse stored in a structure
type_num=$((type_num + 1))
python local/multi_condition/get_air_file_patterns.py $AIR_home > $log_dir/air_file_pattern
files_done=0
total_files=$(cat $log_dir/air_file_pattern|wc -l)
echo "" > $log_dir/type$type_num.rir.list
echo "Found $total_files impulse responses in ${AIR_home}."
while read file_pattern output_file_name; do
output_file_name=`echo type${type_num}_$output_file_name| tr '[:upper:]' '[:lower:]'`
echo "python local/multi_condition/read_rir.py --output-sampling-rate $sampling_rate air '${file_pattern}' ${output_dir}/${output_file_name} || exit -1;" >> $command_file
echo ${output_dir}/${output_file_name} >> $log_dir/type$type_num.rir.list
files_done=$((files_done + 1))
done < $log_dir/air_file_pattern
# Reverb2014 RIRs and noise
#--------------------------
# data is stored as multi-channel wav-files
# Simdata for training
#--------------------
type_num=$((type_num + 1))
data_files=( $(find $Reverb2014_home1/RIR -name '*.wav' -type f -print || exit -1) )
files_done=0
total_files=$(echo ${data_files[@]}|wc -w)
echo "" > $log_dir/type${type_num}.rir.list
echo "Found $total_files impulse responses in ${Reverb2014_home1}/RIR."
for data_file in ${data_files[@]}; do
output_file_name=type${type_num}_`basename $data_file | tr '[:upper:]' '[:lower:]'`
echo "python local/multi_condition/read_rir.py --output-sampling-rate $sampling_rate reverb2014 ${data_file} ${output_dir}/${output_file_name} || exit -1;" >> $command_file
echo ${output_dir}/${output_file_name} >> $log_dir/type${type_num}.rir.list
files_done=$((files_done + 1))
done
data_files=( $(find $Reverb2014_home1/NOISE -name '*.wav' -type f -print || exit -1) )
files_done=0
total_files=$(echo ${data_files[@]}|wc -w)
echo "" > $log_dir/type${type_num}.noise.list
echo "Found $total_files noises in ${Reverb2014_home1}/NOISE."
for data_file in ${data_files[@]}; do
output_file_name=type${type_num}_`basename $data_file| tr '[:upper:]' '[:lower:]'`
echo "python local/multi_condition/read_rir.py --output-sampling-rate $sampling_rate reverb2014 ${data_file} ${output_dir}/${output_file_name} || exit -1;" >> $command_file
echo ${output_dir}/${output_file_name} >> $log_dir/type${type_num}.noise.list
files_done=$((files_done + 1))
done
# Simdata for devset
type_num=$((type_num + 1))
data_files=( $(find $Reverb2014_home2/RIR -name '*.wav' -type f -print || exit -1) )
files_done=0
total_files=$(echo ${data_files[@]}|wc -w)
echo "" > $log_dir/type${type_num}.rir.list
echo "Found $total_files impulse responses in ${Reverb2014_home2}/RIR."
for data_file in ${data_files[@]}; do
output_file_name=type${type_num}_`basename $data_file| tr '[:upper:]' '[:lower:]'`
echo "python local/multi_condition/read_rir.py --output-sampling-rate $sampling_rate reverb2014 ${data_file} ${output_dir}/${output_file_name} || exit -1;" >> $command_file
echo ${output_dir}/${output_file_name} >> $log_dir/type${type_num}.rir.list
files_done=$((files_done + 1))
done
data_files=( $(find $Reverb2014_home2/NOISE -name '*.wav' -type f -print || exit -1) )
files_done=0
total_files=$(echo ${data_files[@]}|wc -w)
echo "" > $log_dir/type${type_num}.noise.list
echo "Found $total_files noises in ${Reverb2014_home2}/NOISE."
for data_file in ${data_files[@]}; do
output_file_name=type${type_num}_`basename $data_file | tr '[:upper:]' '[:lower:]'`
echo "python local/multi_condition/read_rir.py --output-sampling-rate $sampling_rate reverb2014 ${data_file} ${output_dir}/${output_file_name} || exit -1;" >> $command_file
echo ${output_dir}/${output_file_name} >> $log_dir/type${type_num}.noise.list
files_done=$((files_done + 1))
done
# Running commands created above
echo "Extracting the found room impulse responses and noises."
# write the file_splitter to create jobs files for queue.pl
# write the file_splitter to create job files for queue.pl
# we use this to parallelize the audio corruption and download jobs
cat << EOF > $log_dir/file_splitter.py
#!/usr/bin/env python
import os.path, sys, math
input_file = sys.argv[1]
num_lines_per_file = int(sys.argv[2])
num_lines_per_file = int(sys.argv[1])
input_file = sys.argv[2]
[file_base_name, ext] = os.path.splitext(input_file)
lines = open(input_file).readlines();
num_lines = len(lines)
......@@ -208,65 +59,72 @@ num_jobs = int(math.ceil(num_lines/ float(num_lines_per_file)))
for i in xrange(1, num_jobs+1) :
cur_lines = map(lambda index: lines[index], range(i - 1, num_lines , num_jobs))
file = open("{0}.{1}{2}".format(file_base_name, i, ext), 'w')
file.write("source /home/vpeddinti/scripts//python/MyPython/bin/activate\n")
file.write("which python\n")
file.write("".join(cur_lines))
file.close()
print num_jobs
EOF
chmod +x $log_dir/file_splitter.py
if [ $stage -le 1 ]; then
echo "Extracting the impulse responses from the databases $db_string"
num_db_jobs=`echo $db_string|wc -w`
$decode_cmd JOB=1:$num_db_jobs $log_dir/log/DBprocess.JOB.log \
db=\(0 $db_string \) \&\& \
local/multi_condition/rirs/prep_\$\{db\[JOB\]\}.sh --file-splitter "$log_dir/file_splitter.py 10 " --download $download_rirs --sampling-rate $sampling_rate $RIR_home ${output_dir}_non_normalized $log_dir ||exit 1;
fi
num_jobs=$(python $log_dir/file_splitter.py $command_file 10 || exit 1)
# execute the commands using the above created array jobs
time $decode_cmd --max-jobs-run 40 JOB=1:$num_jobs $log_dir/log/read_rir_noise.JOB.log \
sh $log_dir/read_rir_noise.JOB.sh || exit 1;
sleep 4;
echo "Normalizing the extracted room impulse responses and noises, per type"
for i in `ls $log_dir/type*.rir.list`; do
echo "$i"
python local/multi_condition/normalize_wavs.py --is-room-impulse-response true $i
done
for i in `ls $log_dir/type*.noise.list`; do
echo "$i"
python local/multi_condition/normalize_wavs.py --is-room-impulse-response false $i
done
cat $log_dir/type{1,2,3,4,6,7,8}.rir.list > $output_dir/info/impulse_files
cat $log_dir/type{5,7,8}.noise.list > $output_dir/info/noise_files
# get the Reverb2014 room names to pair the noises and impulse responses
for type_num in `seq 7 8`; do
noise_patterns=( $(ls ${output_dir}/type${type_num}_noise*.wav | xargs -n1 basename | python -c"
import sys
for line in sys.stdin:
name = line.split('type${type_num}_noise_')[1]
print name.split('_')[0]
"|sort -u) )
for noise_pattern in ${noise_patterns[@]}; do
set_file=$output_dir/info/noise_impulse_$noise_pattern
echo -n "noise_files =" > ${set_file}
ls ${output_dir}/type${type_num}_noise*${noise_pattern}*.wav | awk '{ ORS=" "; print;} END{print "\n"}' >> ${set_file}
echo -n "impulse_files =" >> ${set_file}
ls ${output_dir}/type${type_num}_rir*${noise_pattern}*.wav | awk '{ ORS=" "; print; } END{print "\n"}' >> ${set_file}
if [ $stage -le 2 ]; then
echo "Normalizing the extracted room impulse responses and noises, per type"
# normalizing the RIR files
for i in `ls $log_dir/*type*.rir.list`; do
echo "Processing files in $i"
python local/multi_condition/normalize_wavs.py --is-room-impulse-response true $i $i.normval || exit 1;
norm_coefficient=`cat $i.normval`
echo "" > $i.normalized
while read file_name; do
if [ ! -z $file_name ]; then
output_file_name=${output_dir}/`basename $file_name`
sox --volume $norm_coefficient -t wav $file_name -t wav $output_file_name 2>/dev/null
echo $output_file_name >> $i.normalized
fi
done < $i
done
done
# get the RWCP database noise mic and room settings to pair with corresponding impulse responses
type_num=5
noise_patterns=( $(ls ${output_dir}/type${type_num}_noise*.wav | xargs -n1 basename | python -c"
import sys
for line in sys.stdin:
name = line.split('type${type_num}_noise')[1]
print '_'.join(name.split('_')[1:-1])
"|sort -u) )
# normalizing the noise files
for i in `ls $log_dir/*type*.noise.list`; do
echo "Processing files in $i"
python local/multi_condition/normalize_wavs.py --is-room-impulse-response false $i $i.normval || exit 1;
norm_coefficient=`cat $i.normval`
echo "" > $i.normalized
while read file_name; do
if [ ! -z $file_name ]; then
output_file_name=${output_dir}/`basename $file_name`
sox --volume $norm_coefficient -t wav $file_name -t wav $output_file_name 2>/dev/null
echo $output_file_name >> $i.normalized
fi
done < $i
done
fi
for noise_pattern in ${noise_patterns[@]}; do
set_file=$output_dir/info/noise_impulse_$noise_pattern
echo -n "noise_files=" > $set_file
ls ${output_dir}/*${noise_pattern}*.wav | grep "type${type_num}" | grep "noise" | awk '{ ORS=" "; print; } END{print "\n"}' >> $set_file
echo -n "impulse_files=" >> $set_file
ls ${output_dir}/*${noise_pattern}*.wav | grep -v "type${type_num}" | grep "rir" | awk '{ ORS=" "; print; } END{print "\n"}' >> $set_file
done
# copying the noise-rir pairing files
cp ${output_dir}_non_normalized/info/* $output_dir/info
# generating the rir-list with probabilities alloted for each rir
db_string_python=$(echo $db_string|sed -e "s/'\s\+'/','/g")
python -c "
import glob, string, re
dbs=[$db_string_python]
rirs = []
for db in dbs:
files = glob.glob('$log_dir/{0}*type*.rir.list.normalized'.format(string.upper(db)))
for file in files:
for line in open(file).readlines():
if len(line.strip()) > 0:
rirs.append(line.strip())
final_rir_list_file = open('$output_dir/info/impulse_files', 'w')
final_rir_list_file.write('\n'.join(rirs))
final_rir_list_file.close()
"
wc -l $output_dir/info/impulse_files
#!/usr/bin/env python
# Copyright 2014 Johns Hopkins University (Authors: Vijayaditya Peddinti). Apache 2.0.
# script to read rir files from rwcp/air/reverb2014 databases
# script to read rir files from air database
import sys, numpy as np, argparse, scipy.signal as signal, os.path, glob, scipy.io, scipy.io.wavfile
......@@ -12,14 +11,25 @@ def read_raw(input_filename, precision = np.float32):
#sys.stderr.write("Read file of length {0} and type {1}\n".format(len(data), precision))
return data
def wav_write(file_handle, fs, data):
if str(data.dtype) in set(['float64', 'float32']):
data = (0.99 * data / np.max(np.abs(data))) * (2 ** 31)
data = data.astype('int32', copy = False)
elif str(data.dtype) == 'int32':
pass
else:
raise Exception('Not implemented for '+str(data.dtype))
scipy.io.wavfile.write(file_handle, fs, data)
def usage():
return """This is a python script to read various types of impulse responses stored in custom formats. It handles RWCP."""
return """This is a python script to read impulse responses stored in custom formats. It handles AIR database."""
if __name__ == "__main__":
#sys.stderr.write(" ".join(sys.argv)+"\n")
parser = argparse.ArgumentParser(usage())
parser.add_argument('--output-sampling-rate', type = int, default = 8000, help = 'sampling rate of the output')
parser.add_argument('type', type = str, default = None, help = 'database type', choices = ['rwcp/rir', 'rwcp/noise', 'air', 'reverb2014'])
parser.add_argument('type', type = str, default = None, help = 'database type', choices = ['air'])
parser.add_argument('input', type = str, default = None, help = 'directory containing the multi-channel data for a particular recording, or file name or file-regex-pattern')
parser.add_argument('output_filename', type = str, default = None, help = 'output filename (if "-" then output is written to output pipe)')
params = parser.parse_args()
......@@ -29,36 +39,7 @@ if __name__ == "__main__":
else:
output = open(params.output_filename, 'wb')
if params.type in set(['rwcp/rir', 'rwcp/noise']):
if params.type == 'rwcp/rir':
precision = np.float32
elif params.type == 'rwcp/noise':
precision = np.int16
sr = 48000
if (os.path.isdir(params.input)):
channel_files = glob.glob(params.input+'/*')
channel_file_basenames = map(lambda x: os.path.basename(x), channel_files)
# check if all the files are present
file_name = set(map(lambda x: x.split(".")[0], channel_files))
assert(len(file_name) == 1)
extensions = map(lambda x: int(x.split(".")[1]), channel_files)
extensions.sort()
assert(extensions == range(min(extensions), max(extensions)+1))
base_name = ".".join(channel_files[0].split(".")[:-1])
data = []
for ext in extensions:
data.append(read_raw("{0}.{1}".format(base_name, ext), precision = precision))
data = np.array(data)
data = data.transpose()
else:
data= []
data.append(read_raw(params.input, precision = precision))
data = np.array(data)
data = data.transpose()
assert(data.shape[1] == 1)
if params.output_sampling_rate != sr:
data = signal.resample(data, params.output_sampling_rate * float(data.shape[0]) / sr, axis = 0)
elif params.type == 'air':
if params.type == 'air':
files = glob.glob(params.input)
# there are just two files which vary in the channel id (0,1)
assert(len(files)==2)
......@@ -73,10 +54,4 @@ if __name__ == "__main__":
assert(data.shape[1] == 2)
if params.output_sampling_rate != sr:
data = signal.resample(data, params.output_sampling_rate * float(data.shape[0]) / sr, axis = 0)
elif params.type == 'reverb2014':
wav_data = scipy.io.wavfile.read(params.input)
sr = wav_data[0]
data = wav_data[1]
if params.output_sampling_rate != sr:
data = signal.resample(data, params.output_sampling_rate * float(data.shape[0]) / sr, axis = 0)
scipy.io.wavfile.write(output, params.output_sampling_rate, data)
wav_write(output, params.output_sampling_rate, data)
......@@ -74,7 +74,7 @@ done
python local/multi_condition/get_reverberate_parameter_lists.py \
--snrs $snrs --num-files-per-job $num_files_per_job --random-seed $random_seed \
$src_dir/wav.scp $log_dir/corrupted_${random_seed}.list $impnoise_dir \
$log_dir/corrupt_wavs.${random_seed}.list > $log_dir/num_corruption_jobs || exit -1;
$log_dir/corrupt_wavs.${random_seed}.list > $log_dir/num_corruption_jobs || exit 1;
num_jobs=$(cat $log_dir/num_corruption_jobs)
$decode_cmd -V --max-jobs-run $max_jobs_run JOB=1:$num_jobs $log_dir/corrupt_wavs.${random_seed}.JOB.log \
......
#!/bin/bash
# Copyright 2015 Johns Hopkins University (author: Vijayaditya Peddinti)
# Apache 2.0
# This script downloads the Concert Hall Impulse Responses - Pori, Finland
# and converts them to wav files with the required sampling rate
#==============================================
download=true
sampling_rate=8k
DBname=AALTO
file_splitter= #script to generate job scripts given the command file
. cmd.sh
. path.sh
. ./utils/parse_options.sh
if [ $# != 3 ]; then
echo "Usage: "
echo " $0 [options] <rir-home> <output-dir> <log-dir>"
echo "e.g.:"
echo " $0 --download true db/RIR_databases/ data/impulses_noises exp/make_reverb/log"
exit 1;
fi
RIR_home=$1
output_dir=$2
log_dir=$3
if [ "$download" = true ]; then
mkdir -p $RIR_home
(cd $RIR_home;
dir=aalto_concert_hall_pori/
rm -rf $dir
wget http://legacy.spa.aalto.fi/projects/poririrs/wavs/binaural.zip --directory-prefix=$dir
wget http://legacy.spa.aalto.fi/projects/poririrs/wavs/bin_dfeq.zip --directory-prefix=$dir