-
Notifications
You must be signed in to change notification settings - Fork 17
/
convertwavdir.pl
52 lines (46 loc) · 1.13 KB
/
convertwavdir.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
use File::Basename;
if (@ARGV < 1) {
exit -1;
}
$startdir = $ARGV[0];
$outdir = $ARGV[1];
$sox='/Users/ekapolc/Desktop/sox-14.4.2/sox';
opendir (DIR, $startdir) or die $!;
print "checking $startdir\n";
while ($file = readdir(DIR)) {
$fullpath = $startdir."/".$file;
@parts = split('\.',$file);
if( @parts < 2) {next;}
if( $parts[-1] eq 'wav') {
print "checking $file\n";
$ret = `$sox --i -t $fullpath`;
chomp($ret);
if ($ret ne "wav") {
print "WARNING $file not .wav\n";
next;
}
$ret = `$sox --i -c $fullpath`;
chomp($ret);
if ($ret ne "1") {
`$sox $fullpath /tmp/tmp.wav remix 1-2`;
$fullpath = '/tmp/tmp.wav';
}
$ret = `$sox --i -r $fullpath`;
chomp($ret);
if ($ret ne "16000") {
print "converting $file\n";
`$sox $fullpath -r 16000 -b 16 $outdir/$file`;
next;
}
$ret = `$sox --i -b $fullpath`;
chomp($ret);
if ($ret ne "16") {
print "converting $file\n";
`$sox $fullpath -r 16000 -b 16 $outdir/$file`;
next;
}
`cp $fullpath $outdir/$file`;
}
}
closedir(DIR);