6
# Find the location of the files
7
currentpath = os.path.dirname(os.path.abspath(__file__))
9
sphinxbinpath = os.path.abspath(currentpath + "/../libexec/sphinxtrain")
10
if os.path.exists(currentpath + "/../bin/Release"):
11
sphinxbinpath = os.path.abspath(currentpath + "/../bin/Release")
13
sphinxpath = os.path.abspath(currentpath + "/../lib/sphinxtrain")
14
if os.path.exists(currentpath + "/../scripts/00.verify"):
15
sphinxpath = os.path.abspath(currentpath + "/..")
18
# Perl script want forward slashes
19
training_basedir = os.getcwd().replace('\\', '/');
20
sphinxpath = sphinxpath.replace('\\','/')
21
sphinxbinpath = sphinxbinpath.replace('\\','/')
23
print "Sphinxtrain path:", sphinxpath
24
print "Sphinxtrain binaries path:", sphinxbinpath
28
if not os.path.exists("etc"):
31
print "Setting up the database " + task
33
out_cfg = open("etc/sphinx_train.cfg", "w")
34
for line in open(sphinxpath + "/etc/sphinx_train.cfg", "r"):
35
line = line.replace("___DB_NAME___", task)
36
line = line.replace("___BASE_DIR___", training_basedir)
37
line = line.replace("___SPHINXTRAIN_DIR___", sphinxpath)
38
line = line.replace("___SPHINXTRAIN_BIN_DIR___", sphinxbinpath)
42
out_cfg = open("etc/feat.params", "w")
43
for line in open(sphinxpath + "/etc/feat.params", "r"):
48
"000.comp_feat/slave_feat.pl",
49
"00.verify/verify_all.pl",
50
"0000.g2p_train/g2p_train.pl",
51
"01.lda_train/slave_lda.pl",
52
"02.mllt_train/slave_mllt.pl",
53
"05.vector_quantize/slave.VQ.pl",
54
"10.falign_ci_hmm/slave_convg.pl",
55
"11.force_align/slave_align.pl",
56
"12.vtln_align/slave_align.pl",
57
"20.ci_hmm/slave_convg.pl",
58
"30.cd_hmm_untied/slave_convg.pl",
59
"40.buildtrees/slave.treebuilder.pl",
60
"45.prunetree/slave.state-tying.pl",
61
"50.cd_hmm_tied/slave_convg.pl",
62
"60.lattice_generation/slave_genlat.pl",
63
"61.lattice_pruning/slave_prune.pl",
64
"62.lattice_conversion/slave_conv.pl",
65
"65.mmie_train/slave_convg.pl",
66
"90.deleted_interpolation/deleted_interpolation.pl",
70
def run_stages(stages):
71
for stage in stages.split(","):
73
name = step.split("/")[0].split(".")[-1]
75
os.system(sphinxpath + "/scripts/" + step)
78
print "Running the training"
80
os.system(sphinxpath + "/scripts/" + step)
84
print "Sphinxtrain processes the audio files and creates and acoustic model "
85
print "for CMUSphinx toolkit. The data needs to have a certain layout "
86
print "See the tutorial http://cmusphinx.sourceforge.net/wiki/tutorialam "
89
print "Usage: sphinxtrain [options] <command>"
92
print " -t <task> setup - copy configuration into database"
93
print " [-s <stage1,stage2,stage3>] run - run the training or just selected stages"
98
opts, args = getopt.getopt(sys.argv[1:], "ht:s:", ["help", "task", "stages"])
99
except getopt.GetoptError, err:
108
if o in ("-t", "--task"):
110
if o in ("-s", "--stages"):
112
if o in ("-h", "--help"):
121
if command == "setup":
123
print "No task name defined"
126
elif command == "run":
134
if __name__ == "__main__":