#!/usr/bin/perl # # Yousef Rabah - started April 14th, 2004 # # wav_to_raw.pl # # -- This scripts runs through all the wav files and # changes the formate type into raw files and it places # them in another directory. # First Open the directory that contains the wav files that were # recorded by record_wav.pl # Then all the wav files. For each of the files names that matches .wav file # The names will be changed to .raw rather than .wav # Then the system call uses sox, which is a sound file exchange with rate of 16000 will # change the wav file type and then copy it into another directory called raw_files. # This is an option, that could be used later on as an enhancment, to replay what the user # recored in the record_wav.pl script. But with this, the new raw file output will be changed # into a wav file so that it would be replayed to user if option is needed. ############################################### use strict; my $wav_target = "/usr/local/share/sphinx3/model/lm/an4/wav_files"; my $raw_target = "/usr/local/share/sphinx3/model/lm/an4/raw_files"; my $name; my $wav_raw_log = "/root/perl/wav_to_raw_log.txt"; my $out_Name; # Open the directory that contains the wav files that were # recorded by record_wav.pl opendir (WAV, $wav_target) || die "cannot opendir $wav_target: $!"; # Here all the wav files are going to be read while ($name = readdir(WAV)){ # for each of the files names that matches .wav file foreach ($name){ $name =~ m/(.*)\.wav$/; # The names will be changed to .raw rather than .wav $out_Name = "$1.raw"; # Here the system call uses sox, which is a sound file exchange with rate of 16000 will # change the wav file type and then copy it into another directory called raw_files. system ("sox $wav_target/$_ -t raw -w -r 16000 -c1 $raw_target/$out_Name 2>$wav_raw_log"); # This is an option, that could be used later on as an enhancment, to replay what the user # recored in the record_wav.pl script. But with this, the new raw file output will be changed # into a wav file so that it would be replayed to user if option is needed. #system ("sox -r 16000 -c 2 -s -w $raw_target/record000.raw $wav_target/record000.wav"); } } closedir (WAV); exit;