Mercurial > hg > aimc
comparison trunk/experiments/scripts/cnbh-syllables/run_training_and_testing/gen_hmmproto.py @ 365:2f4530363f7a
- Added as-yet-unfinished support for a proper configuraiton file format
- Added a couple of pythin scripts to generate HMM configuration files
- Variable name changes and other cosmetic things
- Added the option for the noise generation to do pink noise (untested)
author | tomwalters |
---|---|
date | Thu, 12 Aug 2010 11:28:11 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
364:5a12172dcb73 | 365:2f4530363f7a |
---|---|
1 #!/usr/bin/env python | |
2 # encoding: utf-8 | |
3 """ | |
4 gen_hmmproto.py | |
5 | |
6 Created by Thomas Walters on 2010-07-08. | |
7 """ | |
8 | |
9 import sys | |
10 import getopt | |
11 | |
12 | |
13 help_message = ''' | |
14 Generate an HTK HMM prototype with an input_size dimensional input and | |
15 total_hmm_states total HMM states (including start and end state) | |
16 The feature type string can be specified in feature_type | |
17 ''' | |
18 | |
19 | |
20 class Usage(Exception): | |
21 def __init__(self, msg): | |
22 self.msg = msg | |
23 | |
24 | |
25 def main(argv=None): | |
26 if argv is None: | |
27 argv = sys.argv | |
28 try: | |
29 try: | |
30 opts, args = getopt.getopt(argv[1:], "hi:s:t:v", ["help", "input_size=", "total_hmm_states=", "feature_type="]) | |
31 except getopt.error, msg: | |
32 raise Usage(msg) | |
33 | |
34 # defaults | |
35 input_size = 39 | |
36 total_hmm_states = 6 | |
37 feature_type = "MFCC_0_D_A" | |
38 | |
39 # option processing | |
40 for option, value in opts: | |
41 if option == "-v": | |
42 verbose = True | |
43 if option in ("-h", "--help"): | |
44 raise Usage(help_message) | |
45 if option in ("-i", "--input_size"): | |
46 input_size = int(value) | |
47 if option in ("-s", "--total_hmm_states"): | |
48 total_hmm_states = int(value) | |
49 if option in ("-t", "--feature_type"): | |
50 feature_type = value | |
51 | |
52 except Usage, err: | |
53 print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg) | |
54 print >> sys.stderr, "\t for help use --help" | |
55 return 2 | |
56 | |
57 print "~o<VECSIZE> " + str(input_size) + "<NULLD>" + "<" + feature_type + ">" | |
58 print "~h \"proto\"" | |
59 print "<BEGINHMM>" | |
60 print "<NUMSTATES> " + str(total_hmm_states) | |
61 for state in xrange(2, total_hmm_states): | |
62 print "<State> " + str(state) | |
63 print "<Mean>" + str(input_size) | |
64 print "0 " * input_size | |
65 print "<Variance> " + str(input_size) | |
66 print "1.0 " * input_size | |
67 print | |
68 print "<TransP> " + str(total_hmm_states) | |
69 print "0.0 1.0 " + "0.0 " * (total_hmm_states - 2) | |
70 for state in xrange(1, total_hmm_states - 1): | |
71 print ("0.0 " * state) + "0.6 0.4 " + "0.0 " * (total_hmm_states -2 - state) | |
72 print "0.0 " * total_hmm_states | |
73 print "<EndHMM>" | |
74 | |
75 if __name__ == "__main__": | |
76 sys.exit(main()) |