Speech:MkDec.pl

Summary
Title: mkDec.pl

Author: Peter Ferro

Location: mnt/main/scripts/user/mkDec.pl

Usage: mnt/main/scripts/user/mkDec.pl  

Description
This script executes a decode within an experiment, and automates the steps in Speech:Run_Decode. Scoring is not included in the script. The script uses command line arguments as following: To avoid catastrophe, the script contains checkpoints that ensure that all three parameters only contain numbers, and the experiment ID and sub-experiment ID consist of a fixed number of digits, padded by zeroes (the experiment ID must be four digits and the sub-experiment ID must be three digits). In addition, there are some stopgaps in place in case previous steps were not executed properly (although it can still get to the last step if you started, but did not finish creating the language model, so watch out!).
 * The experiment number
 * The sub-experiment number
 * Number of audio files to process

Code

 * 1) !/usr/bin/perl

=begin comment Make Decode Author: Peter Ferro Semester: Spring 2016 Start Date: 2/24/16 Last Modified: 3/5/16 Recent changes: - Added language model verification. - First fully functional version.

This code prepares and executes a decode. A train must have been previously run.

(Trained data and untrained data have very little differences in the documentation, just to note...) =cut

$help = <<'=cut'; Make Decode Script Produced by Peter Ferro for Spring 2016 Semester at UNH Manchester

Parameters are: - $EXP_ID: Experiment ID Experiment ID should be a 4-digit number with zeroes used for padding. - $SUBEXP_ID: Sub-experiment ID (also called a task ID) Sub-experiment ID should be a 3-digit number with zeroes used for padding. - $SPH_FILES: Number of speech files (senomes) to process All parameters must consist only of numeric digits.

Please make sure you have ran a train and created the language model. If this has not happened, then this code will not work properly. =cut


 * 1) WARNING: This code is subject to modification.
 * 2) The basic features are implemented, but you may still slip by
 * 3) the verification. Please make sure you have executed a train and created the
 * 4) language model before running this code, or else bad things might happen.

use feature qw(say);

if(scalar @ARGV != 3) {	if(scalar @ARGV == 0){die("$help\n\n");} #Add an error message if arguments were provided. else{die("Wrong number of parameters.\n\n$help\n\n");} }
 * 1) First, make sure the number of arguments is 3. If not, then display help.
 * 2) This acts as a manual for the users that are attempting to run the code.

$EXP_ID = @ARGV[0]; $SUBEXP_ID = @ARGV[1]; $SPH_FILES = @ARGV[2];

if (($EXP_ID =~ /\D/) or ($SUBEXP_ID =~ /\D/) or ($SPH_FILES =~ /\D/)) {die("Non-numeric data detected in parameters.\n");}
 * 1) Now verify that the parameters only consist of numbers.

if (length($EXP_ID) != 4) {die("Experiment ID must be four digits long (padded with zeroes).\n");}
 * 1) Verify the number of digits in the experiment and sub-experiment IDs.

if (length($SUBEXP_ID) != 3) {die("Sub-experiment ID must be three digits long (padded with zeroes).\n");}

chdir("/mnt/main/Exp/$EXP_ID") or die("The experiment ID likely does not exist.\n" .			"Please verify that you are using a valid experiment ID\n" . 			"before trying again.\n");
 * 1) Now go to where the experiment ID resides.

chdir("$SUBEXP_ID") or die("The sub-experiment ID likely does not exist.\n" .	"Please verify that you are using a valid sub-experiment ID\n" . 	"before trying again.\n"); chdir("etc") or die("etc directory likely does not exist.\n" .			"Have you run a train and created the language model yet?\n");

system("head " .	"-$SPH_FILES $SUBEXP_ID\_train.fileids > $SUBEXP_ID\_decode.fileids") == 0 or die("The train fileids likely do not exist.\n" .				"Have you run a train and created the language model yet?\n");
 * 1) Copy a certain number of audio file IDs to a new file to process.

chdir(".."); chdir("LM") or die("Language model likely does not exist.\n" .				"Please verify that the corresponding language model files exist.\n"); chdir("..");
 * 1) At this point we verify that the language model exists.
 * 2) Without a language model, the decoder will not work.
 * 1) TODO: Add extra language model verification?

system("mkdir DECODE"); chdir("DECODE");
 * 1) Prepare DECODE directory to save decoding results in.
 * 1) TODO: Set up permissions for directory?

system("cp -i /mnt/main/scripts/user/run_decode.pl .") == 0 or die("Went to copy run_decode.pl, and... \n$!\n");
 * 1) Prepare the run_decode.pl script by copying it.

exec("perl run_decode.pl $SUBEXP_ID $EXP_ID/$SUBEXP_ID $SPH_FILES");
 * 1) This script is no longer needed. Run run_decode.pl, and you should get your results.