#!/usr/bin/perl -w
####################################################################
###
### script name : prompts2codetrainscp.pl
### version: 0.1
### created by: Ken MacLean
### mail: contact@voxforge.org
### Date: 2007.01.06
### Command: perl ./prompts2codetrainscp.pl PromptFile Train.scp
###    
### Copyright (C) 2007 Ken MacLean
###
### This program is free software; you can redistribute it and/or
### modify it under the terms of the GNU General Public License
### as published by the Free Software Foundation; either version 3
### of the License, or (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###                                                             
####################################################################
use strict;
use File::Spec;
my ($promptfile, $trainscp, $line);
if (@ARGV != 2) {
  print "error - usage: $0 prompts codetrain\.scp\n\n"; 
  exit (0);
}
# read in command line arguments
($promptfile, $trainscp) = @ARGV;

open (PROMPT, "$promptfile") || die ("Unable to open $promptfile file for reading");
open (SCP,">$trainscp") || die ("Unable to open $trainscp file for writing");
my $mkdir;
while ($line = <PROMPT>) {
  chomp ($line);
  my ($to_filename,@labels) = split(/\s+/,$line);
  my ($volume,$directories,$from_filename) = File::Spec->splitpath($to_filename);
  $directories =~ s/mfc\///g;
  print SCP ("$directories$from_filename\.wav $to_filename\.mfc\n");
  $mkdir = $directories;
}
my $command = ("mkdir $mkdir" . "mfc"); system($command) == 0 or print "Prompts2codetrain.pl directory:$mkdir already exists! (system $command failed: $?)\n"; 

close (PROMPT);
close(SCP);
