voxforge.org
VoxForge Dev

root/Trunk/Scripts/Testing_scripts/NightlyTest/downsample.pl

Revision 2270, 2.1 kB (checked in by kmaclean, 1 year ago)

Flac audio processing updates & GPL v3 updates

Line 
1 #!/usr/bin/perl -w
2 ####################################################################
3 ###
4 ###     script name : downsample.pl
5 ###     version: 0.2
6 ###             modified by: Ken MacLean
7 ###             mail: kmaclean@voxforge.org
8 ###             Date: 2006.5.9
9 ###     Command: ./downsample.pl FilesToBeDownsampled filetype(raw/wav) original_sampling_rate targetrate
10 ###
11 ### Copyright (C) 2006 Ken MacLean
12 ###
13 ### This program is free software; you can redistribute it and/or
14 ### modify it under the terms of the GNU General Public License
15 ### as published by the Free Software Foundation; either version 3
16 ### of the License, or (at your option) any later version.
17 ###
18 ### This program is distributed in the hope that it will be useful,
19 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ### GNU General Public License for more details.
22 ###                                                                 
23 ####################################################################
24
25 use strict;
26 use File::Spec;
27
28 my ($targetrate, $command, $codetrain, $line,  $file, $directories, $volume);
29 my ($original_file_type, @filename, $original_sampling_rate);
30
31 # check usage
32 if (@ARGV != 4) {
33   print "Wrong number of arguments ... usage: $0 FilesToBeDownsampled filetype(raw/wav) original_sampling_rate(Hz) targetrate(Hz)\n\n";
34   exit (0);
35 }
36
37 # read in command line arguments
38 ($codetrain, $original_file_type, $original_sampling_rate, $targetrate) = @ARGV;
39
40 # open files
41 open (FILEIN,"$codetrain") || die ("Unable to open codetrain $codetrain file for reading");
42
43 # process each prompt one at a time
44 while ($line = <FILEIN>) {
45   chomp ($line);
46   ($volume,$directories,$file) = File::Spec->splitpath( $line );
47   print "downsampling:$file\n";
48  
49 if ($original_file_type eq "wav") {
50         $command = ("sox $line -r $targetrate -w /home/kmaclean/workspace/VoxForge/Audio/Test/Main/8kHz_16bit/$file"); system($command) == 0 or die "system $command failed: $?";
51 } else {
52         die ("Error: wrong file type (only \'wav\' or \'raw\' permitted)");
53 }
54
55 } #end of while loop
56
57 close(FILEIN);
58
Note: See TracBrowser for help on using the browser.