Browse Source

Add perl and python scripts

master
Sam Black 11 years ago
parent
commit
b1d26d1b0f
6 changed files with 471 additions and 0 deletions
  1. +122
    -0
      ee4p/perl/ASR_EE4H.pl
  2. +143
    -0
      ee4p/perl/ASR_EE4H_3mix.pl
  3. +58
    -0
      ee4p/perl/ASR_EE4H_onlyTest.pl
  4. +58
    -0
      ee4p/perl/ASR_EE4H_onlyTest_3mix.pl
  5. BIN
      ee4p/perl/perlScripts_LabASR.zip
  6. +90
    -0
      ee4p/python/pyhtk.py

+ 122
- 0
ee4p/perl/ASR_EE4H.pl View File

@@ -0,0 +1,122 @@
#!c:/Program Files/Perl5.6.1/bin/perl
#####################################################################################################
#
# This script extract features from Aurora2 'Train clean' data and performs training and testing.
# Usage: perl ASR_EE4H.pl
# Author: Munevver Kokuer
# Date: Nov. 2008
#####################################################################################################
# Global Variables
$REC_DIR = "D:\\LabASR";
#$BINDIR = "C:\\HTK\\HTK3.2bin";
$BINDIR = "$REC_DIR\\binHTK3.2";
$HMM_DIR = "$REC_DIR\\hmmsTrained";
$LIST_TRAIN = "$REC_DIR/list/listTrainFulPath.scp";
$LIST_Train_Hcopy = "$REC_DIR/list/listTrainFulPath_Hcopy.scp";
$LIST_TEST = "$REC_DIR/list/listTestFulPath.scp";
$LIST_Test_Hcopy= "$REC_DIR/list/listTestFulPath_Hcopy.scp";
$CONFIG_HCopy = "$REC_DIR/config/config_HCopy";
$CONFIG_train = "$REC_DIR/config/config_train_mfcc";
$CONFIG_test = "$REC_DIR/config/config_test_mfcc";
$WORD_LISTSP = "$REC_DIR/lib/wordList_withSP";
$WORD_LIST = "$REC_DIR/lib/wordList_noSP";
$LABELSP = "$REC_DIR/label/label_EE4H_withSP.mlf";
$LABELS = "$REC_DIR/label/label_EE4H_noSP.mlf";
$ED_CMDFILE1 = "$REC_DIR/lib/tieSILandSP_EE4H.hed";
$Proto = "$REC_DIR/lib/proto_s1d39_st8m1_EE4H";
$mod_file = "$HMM_DIR/hmm8/models";
$mac_file = "$HMM_DIR/hmm8/macros";
$flags = "-p 10 -s 0.0";
$NET = "$REC_DIR\\lib\\wordNetwork";
$DICT = "$REC_DIR\\lib\\wordDict";
$NUM_COEF = 39;
$PAR_TYPE = "MFCC_E_D_A";
$RESULT = "$REC_DIR\\result\\recognitionFinalResult.res";
open(STDOUT, ">$REC_DIR\\result\\LogASR_EE4H.log") or die "Can't write to STDOUT $!";
#-------------------------------------------------------------------------
# Feature Extraction for mfcc_e_d_a
# HCopy: Calls HCopy to convert AURORA TESTA data files to HTK parameterised 'mfcc_e_d_a'
#-------------------------------------------------------------------------
print "Coding data\n";
system("$BINDIR/HCopy -C $CONFIG_HCopy -S $LIST_Train_Hcopy");
system("$BINDIR/HCopy -C $CONFIG_HCopy -S $LIST_Test_Hcopy");
print "Coding complete\n";
#-------------------------------------------------------------------------
# Training
#-------------------------------------------------------------------------
print "Training...\n";
foreach $i (0..20) {
mkdir("$HMM_DIR\\hmm$i");
}
system "$BINDIR\\HCompV -C $CONFIG_train -o hmmdef -f 0.01 -m -S $LIST_TRAIN -M $HMM_DIR/hmm0 $Proto";
print("Seed Hmm succesfully produced\n");
system "$BINDIR/macro $NUM_COEF $PAR_TYPE $HMM_DIR/hmm0/vFloors $HMM_DIR/hmm0/macros";
### creates the file "models" containing the HMM definition of all 11 digits and the silence model
system "$BINDIR/models_1mixsil $HMM_DIR/hmm0/hmmdef $HMM_DIR/hmm0/models";
###Training
foreach $i (1..3) {
print "Iteration Number $i\n";
$j=$i-1;
system "$BINDIR/HERest -D -C $CONFIG_train -I $LABELS -t 250.0 150.0 1000.0 -S $LIST_TRAIN -H $HMM_DIR/hmm$j/macros -H $HMM_DIR/hmm$j/models -M $HMM_DIR/hmm$i $WORD_LIST";
}
print "3 Iterations completed\n";
system("copy $HMM_DIR\\hmm3 $HMM_DIR\\hmm4");
system "$BINDIR/spmodel_gen $HMM_DIR/hmm3/models $HMM_DIR/hmm4/models";
system "$BINDIR/HHEd -T 2 -H $HMM_DIR/hmm4/macros -H $HMM_DIR/hmm4/models -M $HMM_DIR/hmm5 $ED_CMDFILE1 $WORD_LISTSP";
print "SP model fixed\n";
foreach $i (6..8) {
$j=$i-1;
system "$BINDIR/HERest -C $CONFIG_train -I $LABELSP -S $LIST_TRAIN -H $HMM_DIR/hmm$j/macros -H $HMM_DIR/hmm$j/models -M $HMM_DIR/hmm$i $WORD_LISTSP";
}
print "6 Iterations completed\n";
print "Training complete\n";
#-------------------------------------------------------------------------
# Testing
#-------------------------------------------------------------------------
print "Testing...\n";
system "$BINDIR/HVite -H $mac_file -H $mod_file -S $LIST_TEST -C $CONFIG_test -w $NET -i $REC_DIR/result/result.mlf $flags $DICT $WORD_LISTSP";
system ("$BINDIR/HResults -e \"???\" sil -e \"???\" sp -I $LABELSP $WORD_LISTSP $REC_DIR/result/result.mlf >> $RESULT ");
print "Testing complete\n";
print("\n------------------------------------------------------------------\n");
#--------------------------------------------------------------------------#
# End of Script: ASR_EE4H.pl #
#--------------------------------------------------------------------------#

+ 143
- 0
ee4p/perl/ASR_EE4H_3mix.pl View File

@@ -0,0 +1,143 @@
#!c:/Program Files/Perl5.6.1/bin/perl
#####################################################################################################
#
# This script extract features from Aurora2 'Train clean' data and performs training and testing.
# Usage: perl ASR_EE4H_3mix
.pl
# Author: Munevver Kokuer
# Date: Nov. 2008
#####################################################################################################
# Global Variables
$REC_DIR = "D:\\LabASR";
#$BINDIR = "C:\\HTK\\HTK3.2bin";
$BINDIR = "$REC_DIR\\binHTK3.2";
$HMM_DIR = "$REC_DIR\\hmmsTrained";
$LIST_TRAIN = "$REC_DIR/list/listTrainFulPath.scp";
$LIST_Train_Hcopy = "$REC_DIR/list/listTrainFulPath_Hcopy.scp";
$LIST_TEST = "$REC_DIR/list/listTestFulPath.scp";
$LIST_Test_Hcopy= "$REC_DIR/list/listTestFulPath_Hcopy.scp";
$CONFIG_HCopy = "$REC_DIR/config/config_HCopy";
$CONFIG_train = "$REC_DIR/config/config_train_mfcc";
$CONFIG_test = "$REC_DIR/config/config_test_mfcc";
$WORD_LISTSP = "$REC_DIR/lib/wordList_withSP";
$WORD_LIST = "$REC_DIR/lib/wordList_noSP";
$LABELSP = "$REC_DIR/label/label_EE4H_withSP.mlf";
$LABELS = "$REC_DIR/label/label_EE4H_noSP.mlf";
$ED_CMDFILE1 = "$REC_DIR/lib/tieSILandSP_EE4H.hed";
$ED_CMDFILE2 = "$REC_DIR/lib/mix2_st8_EE4H.hed";
$ED_CMDFILE3 = "$REC_DIR/lib/mix3_st8_EE4H.hed";
$Proto = "$REC_DIR/lib/proto_s1d39_st8m1_EE4H";
$mod_file = "$HMM_DIR/hmm20/models";
$mac_file = "$HMM_DIR/hmm20/macros";
$flags = "-p 10 -s 0.0";
$NET = "$REC_DIR\\lib\\wordNetwork";
$DICT = "$REC_DIR\\lib\\wordDict";
$NUM_COEF = 39;
$PAR_TYPE = "MFCC_E_D_A";
$RESULT = "$REC_DIR\\result\\recognitionFinalResult.res";
open(STDOUT, ">$REC_DIR\\result\\LogASR_EE4H.log") or die "Can't write to STDOUT $!";
#-------------------------------------------------------------------------
# Feature Extraction for mfcc_e_d_a
# HCopy: Calls HCopy to convert AURORA TESTA data files to HTK parameterised 'mfcc_e_d_a'
#-------------------------------------------------------------------------
print "Coding data\n";
system("$BINDIR/HCopy -C $CONFIG_HCopy -S $LIST_Train_Hcopy");
system("$BINDIR/HCopy -C $CONFIG_HCopy -S $LIST_Test_Hcopy");
print "Coding complete\n";
#-------------------------------------------------------------------------
# Training
#-------------------------------------------------------------------------
print "Training...\n";
foreach $i (0..20) {
mkdir("$HMM_DIR\\hmm$i");
}
system "$BINDIR\\HCompV -C $CONFIG_train -o hmmdef -f 0.01 -m -S $LIST_TRAIN -M $HMM_DIR/hmm0 $Proto";
print("Seed Hmm succesfully produced\n");
system "$BINDIR/macro $NUM_COEF $PAR_TYPE $HMM_DIR/hmm0/vFloors $HMM_DIR/hmm0/macros";
### creates the file "models" containing the HMM definition of all 11 digits and the silence model
system "$BINDIR/models_1mixsil $HMM_DIR/hmm0/hmmdef $HMM_DIR/hmm0/models";
###Training
foreach $i (1..3) {
print "Iteration Number $i\n";
$j=$i-1;
system "$BINDIR/HERest -D -C $CONFIG_train -I $LABELS -t 250.0 150.0 1000.0 -S $LIST_TRAIN -H $HMM_DIR/hmm$j/macros -H $HMM_DIR/hmm$j/models -M $HMM_DIR/hmm$i $WORD_LIST";
}
print "3 Iterations completed\n";
system("copy $HMM_DIR\\hmm3 $HMM_DIR\\hmm4");
system "$BINDIR/spmodel_gen $HMM_DIR/hmm3/models $HMM_DIR/hmm4/models";
system "$BINDIR/HHEd -T 2 -H $HMM_DIR/hmm4/macros -H $HMM_DIR/hmm4/models -M $HMM_DIR/hmm5 $ED_CMDFILE1 $WORD_LISTSP";
print "SP model fixed\n";
foreach $i (6..8) {
$j=$i-1;
system "$BINDIR/HERest -C $CONFIG_train -I $LABELSP -S $LIST_TRAIN -H $HMM_DIR/hmm$j/macros -H $HMM_DIR/hmm$j/models -M $HMM_DIR/hmm$i $WORD_LISTSP";
}
print "6 Iterations completed\n";
system "$BINDIR/HHEd -T 2 -H $HMM_DIR/hmm8/macros -H $HMM_DIR/hmm8/models -M $HMM_DIR/hmm9 $ED_CMDFILE2 $WORD_LISTSP";
print "2 Gaussians per mixture created\n";
foreach $i (10..12) {
$j=$i-1;
system "$BINDIR/HERest -C $CONFIG_train -I $LABELSP -S $LIST_TRAIN -H $HMM_DIR/hmm$j/macros -H $HMM_DIR/hmm$j/models -M $HMM_DIR/hmm$i $WORD_LISTSP";
}
print "9 Iterations completed\n";
system "$BINDIR/HHEd -T 2 -H $HMM_DIR/hmm12/macros -H $HMM_DIR/hmm12/models -M $HMM_DIR/hmm13 $ED_CMDFILE3 $WORD_LISTSP";
print "3 Gaussians per mixture created\n";
foreach $i (14..20) {
$j=$i-1;
system "$BINDIR/HERest -C $CONFIG_train -I $LABELSP -S $LIST_TRAIN -H $HMM_DIR/hmm$j/macros -H $HMM_DIR/hmm$j/models -M $HMM_DIR/hmm$i $WORD_LISTSP";
}
print "16 Iterations completed\n";
print "Training complete\n";
#-------------------------------------------------------------------------
# Testing
#-------------------------------------------------------------------------
print "Testing...\n";
system "$BINDIR/HVite -H $mac_file -H $mod_file -S $LIST_TEST -C $CONFIG_test -w $NET -i $REC_DIR/result/result.mlf $flags $DICT $WORD_LISTSP";
system ("$BINDIR/HResults -e \"???\" sil -e \"???\" sp -I $LABELSP $WORD_LISTSP $REC_DIR/result/result.mlf >> $RESULT ");
print "Testing complete\n";
print("\n------------------------------------------------------------------\n");
#--------------------------------------------------------------------------#
# End of Script: ASR_EE4H_3mix.pl #
#--------------------------------------------------------------------------#

+ 58
- 0
ee4p/perl/ASR_EE4H_onlyTest.pl View File

@@ -0,0 +1,58 @@
#!c:/Program Files/Perl5.6.1/bin/perl
#####################################################################################################
#
# This script runs testing
# Usage: perl ASR_EE4H_onlyTest.pl
# Author: Munevver Kokuer
# Date: Nov. 2008
#####################################################################################################
# Global Variables
$REC_DIR = "D:\\LabASR";
#$BINDIR = "C:\\HTK\\HTK3.2bin";
$BINDIR = "$REC_DIR\\binHTK3.2";
$HMM_DIR = "$REC_DIR\\hmmsTrained";
$LIST_TEST = "$REC_DIR/list/listTestFulPath.scp";
$LIST_Test_Hcopy= "$REC_DIR/list/listTestFulPath_Hcopy.scp";
$CONFIG_test = "$REC_DIR/config/config_test_mfcc";
$WORD_LISTSP = "$REC_DIR/lib/wordList_withSP";
$LABELSP = "$REC_DIR/label/label_EE4H_withSP.mlf";
$mod_file = "$HMM_DIR/hmm8/models";
$mac_file = "$HMM_DIR/hmm8/macros";
$flags = "-p 10 -s 0.0";
$NET = "$REC_DIR\\lib\\wordNetwork";
$DICT = "$REC_DIR\\lib\\wordDict";
$RESULT = "$REC_DIR\\result\\recognitionFinalResult.res";
open(STDOUT, ">$REC_DIR\\result\\LogASR_EE4H_onlyTesting.log") or die "Can't write to STDOUT $!";
#-------------------------------------------------------------------------
# Testing
#-------------------------------------------------------------------------
print "Testing...\n";
system "$BINDIR/HVite -H $mac_file -H $mod_file -S $LIST_TEST -C $CONFIG_test -w $NET -i $REC_DIR/result/result.mlf $flags $DICT $WORD_LISTSP";
system ("$BINDIR/HResults -e \"???\" sil -e \"???\" sp -I $LABELSP $WORD_LISTSP $REC_DIR/result/result.mlf >> $RESULT ");
print "Testing complete\n";
print("\n------------------------------------------------------------------\n");
#--------------------------------------------------------------------------#
# End of Script: ASR_EE4H_onlyTest.pl #
#--------------------------------------------------------------------------#

+ 58
- 0
ee4p/perl/ASR_EE4H_onlyTest_3mix.pl View File

@@ -0,0 +1,58 @@
#!c:/Program Files/Perl5.6.1/bin/perl
#####################################################################################################
#
# This script runs testing
# Usage: perl ASR_EE4H_onlyTest_3mix.pl
# Author: Munevver Kokuer
# Date: Nov. 2008
#####################################################################################################
# Global Variables
$REC_DIR = "D:\\LabASR";
#$BINDIR = "C:\\HTK\\HTK3.2bin";
$BINDIR = "$REC_DIR\\binHTK3.2";
$HMM_DIR = "$REC_DIR\\hmmsTrained";
$LIST_TEST = "$REC_DIR/list/listTestFulPath.scp";
$LIST_Test_Hcopy= "$REC_DIR/list/listTestFulPath_Hcopy.scp";
$CONFIG_test = "$REC_DIR/config/config_test_mfcc";
$WORD_LISTSP = "$REC_DIR/lib/wordList_withSP";
$LABELSP = "$REC_DIR/label/label_EE4H_withSP.mlf";
$mod_file = "$HMM_DIR/hmm20/models";
$mac_file = "$HMM_DIR/hmm20/macros";
$flags = "-p 10 -s 0.0";
$NET = "$REC_DIR\\lib\\wordNetwork";
$DICT = "$REC_DIR\\lib\\wordDict";
$RESULT = "$REC_DIR\\result\\recognitionFinalResult.res";
open(STDOUT, ">$REC_DIR\\result\\LogASR_EE4H_onlyTesting.log") or die "Can't write to STDOUT $!";
#-------------------------------------------------------------------------
# Testing
#-------------------------------------------------------------------------
print "Testing...\n";
system "$BINDIR/HVite -H $mac_file -H $mod_file -S $LIST_TEST -C $CONFIG_test -w $NET -i $REC_DIR/result/result.mlf $flags $DICT $WORD_LISTSP";
system ("$BINDIR/HResults -e \"???\" sil -e \"???\" sp -I $LABELSP $WORD_LISTSP $REC_DIR/result/result.mlf >> $RESULT ");
print "Testing complete\n";
print("\n------------------------------------------------------------------\n");
#--------------------------------------------------------------------------#
# End of Script: ASR_EE4H_onlyTest_3mix.pl #
#--------------------------------------------------------------------------#

BIN
ee4p/perl/perlScripts_LabASR.zip View File


+ 90
- 0
ee4p/python/pyhtk.py View File

@@ -0,0 +1,90 @@
#!/usr/bin/python
# pyhtk.py
#
# Copyright 2008 Sam Black <samwwwblack@lapwing.org>
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import sys, os, time, csv, pwd
from optparse import OptionParser

__version__ = "0.1"

class Htk:
def __init__(self):
self.htkpath = "/usr/bin/"
self.training = True
self.testing = True
self.recog = False
self.realtime = False

def testing(self):
pass

def training(self):
pass

def setHTKpath(self, path):
if not path.endswith("/"):
self.htkpath = path + "/"
else:
self.htkpath = path

def setTraining(self, flag):
if flag != True or flag != False:
print "Must be True or False"
sys.exit(1)
else:
self.training = flag

def setTesting(self, flag):
if flag != True or flag != False:
print "Must be True or False"
sys.exit(1)
else:
self.testing = flag

def setRecog(self, flag, rt=False):
if flag != True or flag != False:
print "Must be True or False"
sys.exit(1)
else:
self.testing = flag

def run(self):
print "Starting HTK with following options:"
print "HTK binary path: " + self.htkpath

if __name__ == "__main__":
parser = OptionParser()

parser.add_option("-V", "--version", action="store_true", default=False, dest="version", help="version information")
parser.add_option("-b", "--binary", action="store", type="string", default="/usr/bin/", dest="binpath", help="path to the HTK binaries")
parser.add_option("-a", "--training", action="store_true", default=False, dest="training", help="run training only")
parser.add_option("-t", "--testing", action="store_true", default=False, dest="testing", help="run testing only")
parser.add_option("-r", "--recog", action="store_true", default=False, dest="recog", help="run in recognition mode")
parser.add_option("-R", "--realtime", action="store_true", default=False, dest="realtime", help="run in realtime mode [EXPERIMENTAL]")

(options, args) = parser.parse_args()

app = Htk()

if options.version:
print "%s version %s" % (os.path.basename(sys.argv[0]),__version__)
elif options.binpath != "/usr/bin/":
app.setHTKpath(options.binpath)
else:
app.run()

Loading…
Cancel
Save