Speech:Clone exp.pl

Summary
Title: clone_exp.pl

Author: Eric Beikman

Date: June, 2013 - updated July 2013

Revisions:
 * Version 2.9:
 * Added -t flag. Allows for complete cloning of transcripts, dictionaries, phone lists, fileid lists, and wave files.
 * Version 1.0:
 * Initial release.

Usage:

Description

 * This script is designed to clone one experiment based on the settings from another.
 * Allows for complete cloning of transcripts, dictionaries, phone lists, fileid lists, and wave files.
 * This script is designed to clone an existing experiment. It will either clone the dictonaries and phone list; the transcripts, file list, and wavfiles; or it will do both. It will not touch the sphinx_train.cfg file or create feats from the copied wav files; use train_02.pl and make_feats.pl respectively to do those tasks.

Options:
 * -t:
 * Type of clone. A REQUIRED argument.


 * 3 possible values:
 * dict: Copy over an experiment dictionary, phone list, and filler dictionary from an experiment and adapt it for a new experiment.
 * trans: Copy over a an experiment transcript and fileID, and the the contents of the experiment's 'wav' directory.
 * all: Both of the above.
 * -e:
 * Experiment Number. This is a REQUIRED argument. States which experiment's config file the actions will be performed on. Not supplying this argument, or supplying an invalid experiment number will result in the script erroring out.


 * -h:
 * Help, This text. When this flag is given, the script will not perform any other actions.


 * -c:
 * Clone. The experiment number to clone from. Using an invalid experiment number will kill the script.

Code
use strict; use Getopt::Std;#Simplifies CMD line Options use File::Path; use File::Copy; use File::Basename; my ( @wavFileList, $rootExpDir, $scriptName, $etc, $help, $dict, $filler, $phone, $wav, $fileId, $trans, $wavExt, %flags); $rootExpDir = "/mnt/main/Exp/"; $scriptName = basename($0); $etc = "/etc/"; $dict = ".dic"; $filler = ".filler"; $phone = ".phone"; $wav = "/wav/"; $fileId = "_train.fileids"; $trans = "_train.trans"; $wavExt = ".sph"; $help = "Experiment cloning script:
 * 1) !/usr/bin/perl
 * 2)   Title: clone_exp.pl
 * 3)   Author: Eric Beikman
 * 4)       Date : July, 2013
 * 5) 	 Version 2.0:
 * 6) 	 	Added -t flag. Allows for complete cloning of transcripts, dictionaries, phone lists, fileid lists, and wave files.
 * 7) 	 Version 1.0:
 * 8) 		Initial Release
 * 9) 	This script is designed to clone one experiment based on the contents of another.
 * 1) 	This script is designed to clone one experiment based on the contents of another.

Usage: $scriptName [-t dict|trans|all -e -c ] | [-h]

This script is designed to clone an existing experiment. It will either clone the dictonaries and phone list; the transcripts, file list, and wavfiles; or it will do both. It will not touch the sphinx_train.cfg file or create feats from the copied wav files; use train_02.pl and make_feats.pl respectively to do those tasks.

Flags: -t: Type of clone. A REQUIRED argument. 3 possible values: dict: Copy over an experiment dictionary, phone list, and filler dictionary from an experiment and adapt it for a new experiment. trans: Copy over a an experiment transcript and fileID, and the the contents of the experiment's 'wav' directory. all: Both of the above.

-e: Experiment Number. This is a REQUIRED argument. States which experiment's config file the actions will be performed on. Not supplying this argument, or supplying an invalid experiment number will result in the script erroring out.

-c: Clone. Also REQUIRED The experiment number to clone from.

-h: Help, This text. When this flag is given, the script will not perform any other actions. "; getopts('t:he:c:', \%flags) or die $help; #get option flags. if($flags{h} ){	die $help; } if(!(defined $flags{t})){       die "Error: no action given! Define an action with '-t dict|trans|all' use -h for more information."	} if(!(defined $flags{e})){       die "Error: No experiment number given to clone to!"	} if(!(defined $flags{c})){        die "Error: No experiment number to clone from!"	}

my ($destExp, $orgExp); $destExp = $flags{e}; $orgExp = $flags{c};

if(!(-e $rootExpDir. $destExp)){ die "Error: Specified target experiment does not exist!"; }

if(!(-e $rootExpDir. $orgExp)){ die "Error: Specified original experiment does not exist!"; }

if($flags{t} eq 'all' || $flags{t} eq 'dict'){ if((-e $rootExpDir. $destExp. $etc. $destExp. $dict) || (-e $rootExpDir. $destExp. $etc. $destExp. $filler) || (-e $rootExpDir. $destExp. $etc. $destExp. $phone)){ die "Error: An existing dictionary, filler dictionary, or phone list already exists in the destination directory!\nRename/Remove them and try again!\n"; }
 * 1) Now: the fun stuff. #############

if(!(-e $rootExpDir. $orgExp. $etc. $orgExp. $dict)){ die "Error: No dictionary exists in the experiment to be cloned!\n"; }	if(!(-e $rootExpDir. $orgExp. $etc. $orgExp. $filler)){ die "Error: No filler dictionary exists in the experiment to be cloned!\n"; }	if(!(-e $rootExpDir. $orgExp. $etc. $orgExp. $phone)){ die "Error: No phone list exists in the experiment to be cloned!\n"; }

copy($rootExpDir . $orgExp . $etc . $orgExp . $filler, $rootExpDir . $destExp . $etc . $destExp . $filler) or die "Cannot copy filler dictionary into directory!"; copy($rootExpDir . $orgExp . $etc . $orgExp . $dict, $rootExpDir . $destExp . $etc . $destExp . $dict)or die "Cannot copy dictionary into directory!"; copy($rootExpDir . $orgExp . $etc . $orgExp . $phone, $rootExpDir . $destExp . $etc . $destExp . $phone)or die "Cannot copy phone list into directory!"; } if($flags{t} eq 'all' || $flags{t} eq 'trans'){ if((-e $rootExpDir. $destExp. $etc. $destExp. $trans) || (-e $rootExpDir. $destExp. $etc. $destExp. $fileId) || (glob( $rootExpDir . $destExp . $wav . "*" . $wavExt))){ die "Error: An existing transcript, file list, or wave files exist within the target experiment!\nRename/Remove them and try again!\n"; }	if(!(-e $rootExpDir. $orgExp. $etc. $orgExp. $trans)){ die "Error: No transcript exist in the experiment to be cloned!\n"; }	if(!(-e $rootExpDir. $orgExp. $etc. $orgExp. $fileId)){ die "Error: No fileid list exist in the experiment to be cloned!\n"; }	@wavFileList = glob($rootExpDir . $orgExp . $wav . '*' . $wavExt); if(!(scalar @wavFileList)){ die "Error: No wave files exist in the experiment to be cloned!\n"; }	copy($rootExpDir . $orgExp . $etc . $orgExp . $trans, $rootExpDir . $destExp . $etc . $destExp . $trans) or die "Cannot copy transcript into target experiment!"; copy($rootExpDir . $orgExp . $etc . $orgExp . $fileId, $rootExpDir . $destExp . $etc . $destExp . $fileId)or die "Cannot copy file id list into target experiment!";

foreach (@wavFileList){ copy($_, $rootExpDir . $destExp . $wav . basename($_))or die "Cannot copy wav files into directory!"; } }

exit 0;