#!/usr/bin/perl

use File::Basename;
use Cwd;
###################################################################
# Script which takes a list of files (containing files in htk format) as input and coverts them to SRI sph files.
#
# Vikramjit Mitra
# go_htk2sph.pl
# V1.0 2011/08/05
# 
# UPDATES: 
#
###################################################################
#USEAGE go_htk2sph.pl <input_file_list> <dest_dir> 
#
#---------------------------------------------------------------------------
# Check input arguments
#---------------------------------------------------------------------------

$numArgs = $#ARGV + 1;

if ($numArgs == 2)
{
    ( -e $ARGV[0] ) || die("ERROR: $0 : ERROR with $ARGV[0] : $!\n");
    #USEAGE goPripAudio.pl <input_file_list> <dest_dir> <temp_dir> <log_dir>
    $INPUT_FILES_LIST=$ARGV[0];
    $DEST_DIR=$ARGV[1];
}
else
{
    die("ERROR: You must provide an input file list to process and a Destination directory !! \n");
}


#---------------------------------------------------------------------------
# Read the input file list and process one file at a time
#---------------------------------------------------------------------------

open(FILE_LIST,$INPUT_FILES_LIST)
    || die("ERROR: $0: Could not open $INPUT_FILES_LIST: $!\n");
@trials_list=<FILE_LIST>;
close(FILE_LIST);
#


foreach $file(@trials_list)
{
    chomp($file);
    ($FNAME,$INPUT_DIR,$EXT) = fileparse($file,qr/\.[^.]*/);

    #
    if (-e $DEST_DIR . '/' . $INPUT_DIR . $FNAME . '.sph') {
	# file exists	
	print "File $DEST_DIR/$FNAME.sph exists\n"; 
    } else {
	  system(" mkdir -p $DEST_DIR");
	  system("feacat -ip htk -i $file -srif nmcc_plp_mmedusa_pca52 -op sri -o $DEST_DIR/${FNAME}.sph");

    }
}

