#!/usr/bin/perl use warnings; use strict; die "Usage: $0 \n" if @ARGV != 2; # ================== # my system function # ================== sub mysystem { my $ret = system @_; die "Interrupted\n" if $ret; } # ===================== # function definitions # ===================== sub reduce { my $fname = shift; my $tmp = $fname.'.tmp'; open FILE1, "<$fname"; open FILE2, ">$tmp"; ; # strip off the first line while () { my @l = split /\s+/; print FILE2 "$l[2]\n"; } close FILE2; close FILE1; mysystem qq{mv $tmp $fname}; } sub convert { my ($fromdir, $todir) = @_; warn "Copying directory structure from $fromdir to $todir\n"; opendir DIR, $fromdir; my @alldirs = grep { !/^\.+/ } (readdir DIR); closedir DIR; mysystem qq{mkdir -p $todir}; mysystem qq{mkdir -p $todir/$_} foreach (@alldirs); foreach my $dir (@alldirs) { my $from = "$fromdir/$dir"; my $to = "$todir/$dir"; opendir DIR, $from; while ($_ = readdir DIR) { if (/^([1-9oz][ab])\.wav$/) { my $f1 = "$from/$1.wav"; my $f2 = "$to/$1.dat"; mysystem qq{sox $f1 -r 8000 $f2 polyphase}; &reduce($f2); } } closedir DIR; } } # ================ # main directories # ================ my $fromdir = shift; my $todir = shift; my $datadir = "$todir/data"; my $listdir = "$todir/lists"; # ===================================== # find original train and test datasets # ===================================== my @l = split /\n/, qx{find $fromdir -name man}; my ($traindir) = grep {/train/} @l; my ($testdir) = grep {/test/} @l; # ============================== # create train and test datasets # ============================== &convert($traindir, "$datadir/clean/train/man"); &convert($testdir, "$datadir/clean/test/man"); # ================ # build list files # ================ my $tmp1 = "$listdir/clean/train"; my $tmp2 = "$listdir/clean/test"; mysystem qq{mkdir -p $tmp1 $tmp2}; foreach my $id (1..9, 'o', 'z') { mysystem qq{find $datadir/clean/train -name $id?.dat >$tmp1/$id.lst}; mysystem qq{find $datadir/clean/test -name $id?.dat >$tmp2/$id.lst}; }