# Configuration script for sphinx decoder                  -*-mode:Perl-*-

# Variables starting with $DEC_CFG_ refer to decoder specific
# arguments, those starting with $CFG_ refer to trainer arguments,
# some of them also used by the decoder.

$DEC_CFG_VERBOSE = 1;		# Determines how much goes to the screen.

# These are filled in at configuration time
$DEC_CFG_DB_NAME = '___DB_NAME___';
$DEC_CFG_BASE_DIR = '___BASE_DIR___';
$DEC_CFG_SPHINXDECODER_DIR = '___SPHINXDECODER_DIR___';
$DEC_CFG_SPHINXTRAIN_CFG = "___SPHINXTRAIN_CFG___";

# Name of the decoding script to use (psdecode.pl or s3decode.pl, probably)
$DEC_CFG_SCRIPT = 'psdecode.pl';

require $DEC_CFG_SPHINXTRAIN_CFG;

$DEC_CFG_BIN_DIR = "$DEC_CFG_BASE_DIR/bin";
$DEC_CFG_GIF_DIR = "$DEC_CFG_BASE_DIR/gifs";
$DEC_CFG_SCRIPT_DIR = "$DEC_CFG_BASE_DIR/scripts_pl";

$DEC_CFG_EXPTNAME = "$CFG_EXPTNAME";
$DEC_CFG_JOBNAME  = "$CFG_EXPTNAME"."_job";

# Models to use.
$DEC_CFG_MODEL_NAME = "$CFG_EXPTNAME.cd_${CFG_DIRLABEL}_${CFG_N_TIED_STATES}";

$DEC_CFG_FEATFILES_DIR = "$DEC_CFG_BASE_DIR/feat";
$DEC_CFG_FEATFILE_EXTENSION = '.mfc';
$DEC_CFG_VECTOR_LENGTH = $CFG_VECTOR_LENGTH;
$DEC_CFG_AGC = $CFG_AGC;
$DEC_CFG_CMN = $CFG_CMN;
$DEC_CFG_VARNORM = $CFG_VARNORM;
$DEC_CFG_SVSPEC = $CFG_SVSPEC;

$DEC_CFG_QMGR_DIR = "$DEC_CFG_BASE_DIR/qmanager";
$DEC_CFG_LOG_DIR = "$DEC_CFG_BASE_DIR/logdir";
$DEC_CFG_MODEL_DIR = "$CFG_MODEL_DIR";

#*******variables used in decoding of wave files *******
$DEC_CFG_DICTIONARY     = "$DEC_CFG_BASE_DIR/etc/$DEC_CFG_DB_NAME.dic";
$DEC_CFG_FILLERDICT     = "$DEC_CFG_BASE_DIR/etc/$DEC_CFG_DB_NAME.filler";
$DEC_CFG_LISTOFFILES    = "$DEC_CFG_BASE_DIR/etc/${DEC_CFG_DB_NAME}_test.fileids";
$DEC_CFG_TRANSCRIPTFILE = "$DEC_CFG_BASE_DIR/etc/${DEC_CFG_DB_NAME}_test.transcription";
$DEC_CFG_RESULT_DIR     = "$DEC_CFG_BASE_DIR/result";

# This variables, used by the decoder, have to be user defined, and
# may affect the decoder output

$DEC_CFG_LANGUAGEMODEL_DIR = "$DEC_CFG_BASE_DIR/etc";
$DEC_CFG_LANGUAGEMODEL  = "$DEC_CFG_LANGUAGEMODEL_DIR/___LANGMODEL___";
$DEC_CFG_LANGUAGEWEIGHT = "___LANGWEIGHT___";
$DEC_CFG_BEAMWIDTH = "___BEAMWIDTH___";
$DEC_CFG_WORDBEAM = "___WORDBEAM___";

$DEC_CFG_ALIGN = "___ALIGN___";

#*******variables used in characterizing models*******

$DEC_CFG_HMM_TYPE = $CFG_HMM_TYPE;

if (($DEC_CFG_HMM_TYPE ne ".semi.") and ($DEC_CFG_HMM_TYPE ne ".cont.")) {
  die "Please choose one CFG_HMM_TYPE out of '.cont.' or '.semi.', " .
    "currently $DEC_CFG_HMM_TYPE\n";
}

# This comes directly from reading the code. The feature definitions
# aren're represented exactly by the same string in the trainer and
# the decoder. Therefore, we need to map between them.
%feature_type = (
		 'c/1..L-1/,d/1..L-1/,c/0/d/0/dd/0/,dd/1..L-1/' => 's2_4x',
		 'c/1..L-1/d/1..L-1/c/0/d/0/dd/0/dd/1..L-1/'    => 's3_1x39',
		 'c/0..L-1/d/0..L-1/dd/0..L-1/'                 => '1s_c_d_dd',
		 'c/0..L-1/d/0..L-1/'                           => 'cep_dcep',
		 'c/0..L-1/'                                    => 'cep',
		 'c/0..L-1/dd/0..L-1/'                          => 'INVALID',
		 '4s_12c_24d_3p_12dd'                           => 's2_4x',
		 '1s_12c_12d_3p_12dd'                           => 's3_1x39',
		 's2_4x' 	                                => 's2_4x',
		 's3_1x39'            	                        => 's3_1x39',
		 '1s_c_d_dd'                                    => '1s_c_d_dd',
		 '1s_c_d_ld_dd'                                 => '1s_c_d_ld_dd',
		 '1s_c_d'                                       => 'cep_dcep',
		 '1s_c'                                         => 'cep',
		 '1s_c_dd'                                      => 'INVALID',
		 '1s_d'                                         => 'INVALID',
		 '1s_dd'                                        => 'INVALID',
		);

$DEC_CFG_FEATURE = "INVALID"
    unless ((exists $feature_type{$CFG_FEATURE})
	    and ($DEC_CFG_FEATURE = $feature_type{$CFG_FEATURE}));

if ($DEC_CFG_FEATURE eq "INVALID") {
  die "Feature type used for training, $CFG_FEATURE, cannot be used for decoding.\n" .
    "Please use one of 1s_c_d_dd, 1s_c_d, 1s_c, s2_4x, s3_1x39, 1s_c_d_ld_dd\n";
}
$CFG_FEAT_WINDOW ||= 0;
# Undocumented decoder magic since SphinxBase may not support -cepwin yet
if ($CFG_FEAT_WINDOW) {
    $DEC_CFG_FEATURE = "$CFG_VECTOR_LENGTH:$CFG_FEAT_WINDOW";
}

$DEC_CFG_NPART = 1;		#  Define how many pieces to split decode in

$DEC_CFG_OKAY_COLOR = '00D000';
$DEC_CFG_WARNING_COLOR = '555500';
$DEC_CFG_ERROR_COLOR = 'DD0000';

return 1;
