annotate trunk/experiments/scripts/cnbh-syllables/run_training_and_testing/gen_hmmproto.py @ 706:f8e90b5d85fd tip

Delete CARFAC code from this repository. It has been moved to https://github.com/google/carfac Please email me with your github username to get access. I've also created a new mailing list to discuss CARFAC development: https://groups.google.com/forum/#!forum/carfac-dev
author ronw@google.com
date Thu, 18 Jul 2013 20:56:51 +0000
parents 2f4530363f7a
children
rev   line source
tomwalters@365 1 #!/usr/bin/env python
tomwalters@365 2 # encoding: utf-8
tomwalters@365 3 """
tomwalters@365 4 gen_hmmproto.py
tomwalters@365 5
tomwalters@365 6 Created by Thomas Walters on 2010-07-08.
tomwalters@365 7 """
tomwalters@365 8
tomwalters@365 9 import sys
tomwalters@365 10 import getopt
tomwalters@365 11
tomwalters@365 12
tomwalters@365 13 help_message = '''
tomwalters@365 14 Generate an HTK HMM prototype with an input_size dimensional input and
tomwalters@365 15 total_hmm_states total HMM states (including start and end state)
tomwalters@365 16 The feature type string can be specified in feature_type
tomwalters@365 17 '''
tomwalters@365 18
tomwalters@365 19
tomwalters@365 20 class Usage(Exception):
tomwalters@365 21 def __init__(self, msg):
tomwalters@365 22 self.msg = msg
tomwalters@365 23
tomwalters@365 24
tomwalters@365 25 def main(argv=None):
tomwalters@365 26 if argv is None:
tomwalters@365 27 argv = sys.argv
tomwalters@365 28 try:
tomwalters@365 29 try:
tomwalters@365 30 opts, args = getopt.getopt(argv[1:], "hi:s:t:v", ["help", "input_size=", "total_hmm_states=", "feature_type="])
tomwalters@365 31 except getopt.error, msg:
tomwalters@365 32 raise Usage(msg)
tomwalters@365 33
tomwalters@365 34 # defaults
tomwalters@365 35 input_size = 39
tomwalters@365 36 total_hmm_states = 6
tomwalters@365 37 feature_type = "MFCC_0_D_A"
tomwalters@365 38
tomwalters@365 39 # option processing
tomwalters@365 40 for option, value in opts:
tomwalters@365 41 if option == "-v":
tomwalters@365 42 verbose = True
tomwalters@365 43 if option in ("-h", "--help"):
tomwalters@365 44 raise Usage(help_message)
tomwalters@365 45 if option in ("-i", "--input_size"):
tomwalters@365 46 input_size = int(value)
tomwalters@365 47 if option in ("-s", "--total_hmm_states"):
tomwalters@365 48 total_hmm_states = int(value)
tomwalters@365 49 if option in ("-t", "--feature_type"):
tomwalters@365 50 feature_type = value
tomwalters@365 51
tomwalters@365 52 except Usage, err:
tomwalters@365 53 print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
tomwalters@365 54 print >> sys.stderr, "\t for help use --help"
tomwalters@365 55 return 2
tomwalters@365 56
tomwalters@365 57 print "~o<VECSIZE> " + str(input_size) + "<NULLD>" + "<" + feature_type + ">"
tomwalters@365 58 print "~h \"proto\""
tomwalters@365 59 print "<BEGINHMM>"
tomwalters@365 60 print "<NUMSTATES> " + str(total_hmm_states)
tomwalters@365 61 for state in xrange(2, total_hmm_states):
tomwalters@365 62 print "<State> " + str(state)
tomwalters@365 63 print "<Mean>" + str(input_size)
tomwalters@365 64 print "0 " * input_size
tomwalters@365 65 print "<Variance> " + str(input_size)
tomwalters@365 66 print "1.0 " * input_size
tomwalters@365 67 print
tomwalters@365 68 print "<TransP> " + str(total_hmm_states)
tomwalters@365 69 print "0.0 1.0 " + "0.0 " * (total_hmm_states - 2)
tomwalters@365 70 for state in xrange(1, total_hmm_states - 1):
tomwalters@365 71 print ("0.0 " * state) + "0.6 0.4 " + "0.0 " * (total_hmm_states -2 - state)
tomwalters@365 72 print "0.0 " * total_hmm_states
tomwalters@365 73 print "<EndHMM>"
tomwalters@365 74
tomwalters@365 75 if __name__ == "__main__":
tomwalters@365 76 sys.exit(main())