This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Getting sphinxtrain.EXE to run w\o errors

Tags: None
(comma "," separated)
daveh
Registered Member
Posts
2
Karma
0
I see that simon uses python27, but it errors out in "C:/Program Files (x86)/Simon/bin/sphinxtrain.EXE". I have been trying to rewrite it because it has tab/space errors print errors (No parentheses). I have fixed most of them but this one has me stumped.

File "C:/Program Files (x86)/Simon/bin/sphinxtrain.EXE", line 110
elif command == "run":
^
SyntaxError: invalid syntax

Here is the code so far:
Code: Select all
#!/usr/bin/python

import getopt, sys, os

sphinxbinpath = sys.path[0].replace("\\", "/")
sphinxpath = sphinxbinpath + "/../"
sphinxlibpath = "${exec_prefix}/lib/sphinxtrain".replace("${exec_prefix}", sphinxpath)
print(sphinxlibpath)
def setup(task):
    if not os.path.exists("etc"):
        os.mkdir("etc")
   
    print ("Setting up the database " + task)

    out_cfg = open("etc/sphinx_train.cfg", "w")
    for line in open(sphinxlibpath + "/etc/sphinx_train.cfg", "r"):
        line = line.replace("___DB_NAME___", task)
        line = line.replace("___BASE_DIR___", os.getcwd().replace("\\", "/"))
        line = line.replace("___SPHINXTRAIN_DIR___", sphinxlibpath)
        line = line.replace("___SPHINXTRAIN_BIN_DIR___", sphinxpath + "/bin")
        out_cfg.write(line)
        out_cfg.close()

        out_cfg = open("etc/feat.params", "w")
        for line in open(sphinxlibpath + "/etc/feat.params", "r"):
                out_cfg.write(line)
                out_cfg.close()

steps = [
"000.comp_feat/slave_feat.pl",
"00.verify/verify_all.pl",
"0000.g2p_train/g2p_train.pl",
"01.lda_train/slave_lda.pl",
"02.mllt_train/slave_mllt.pl",
"05.vector_quantize/slave.VQ.pl",
"10.falign_ci_hmm/slave_convg.pl",
"11.force_align/slave_align.pl",
"12.vtln_align/slave_align.pl",
"20.ci_hmm/slave_convg.pl",
"30.cd_hmm_untied/slave_convg.pl",
"40.buildtrees/slave.treebuilder.pl",
"45.prunetree/slave.state-tying.pl",
"50.cd_hmm_tied/slave_convg.pl",
"60.lattice_generation/slave_genlat.pl",
"61.lattice_pruning/slave_prune.pl",
"62.lattice_conversion/slave_conv.pl",
"65.mmie_train/slave_convg.pl",
"90.deleted_interpolation/deleted_interpolation.pl",
"decode/slave.pl"
]

def run_stages(stages):
    for stage in stages.split(","):
        for step in steps:
           name = step.split("/")[0].split(".")[-1]
           if name == stage:
             print    ('""' + sphinxbinpath + '/perl.exe" "' + sphinxlibpath + "/scripts/" + step + '""')
             os.system('""' + sphinxbinpath + '/perl.exe" "' + sphinxlibpath + "/scripts/" + step + '""')

def run():
    print ("Running the training")
    for step in steps:
     print    ('""' + sphinxbinpath + '/perl.exe" "' + sphinxlibpath + "/scripts/" + step + '""')
     os.system('""' + sphinxbinpath + '/perl.exe" "' + sphinxlibpath + "/scripts/" + step + '""')

def usage():
    print ("")
    print ("Sphinxtrain processes the audio files and creates and acoustic model ")
    print ("for CMUSphinx toolkit. The data needs to have a certain layout ")
    print ("See the tutorial http://cmusphinx.sourceforge.net/wiki/tutorialam ")
    print ("for details")
    print ("")
    print ("Usage: sphinxtrain [options] <command>")
    print ("")
    print ("Commands:")
    print ("     -t <task> setup - copy configuration into database")
    print ("     [-s <stage1,stage2,stage3>] run - run the training or just selected stages")

def main():

    try:
        opts, args = getopt.getopt(sys.argv[1:], "ht:s:", ["help", "task", "stages"])
    except getopt.GetoptError as err:
        print (str(err))
        usage()
        sys.exit(-1)
       
    task = None
    stages = None
       
    for o, a in opts:
     if o in ("-t", "--task"):
        task = a
     if o in ("-s", "--stages"):
        stages = a
     if o in ("-h", "--help"):
           usage()
   
    if len(args) == 0:
        usage()
    sys.exit(-1)
   
    command = args[0]
   
    if command == "setup":
        if task == None:
            print ("No task name defined")
        sys.exit(-1)   
    setup(task)
    elif command == "run":
    if stages == None:
        run()
    else:
        run_stages(stages)
    else:
 run()
          
if __name__ == "__main__":
    main()


I removed the line in question and get errors on the next else: statement if that helps any?.
I am not a python programer so I don't have a clue what is wrong here. If someone could help me get this working I would be grateful.

Dave
bedahr
Moderator
Posts
141
Karma
0
OS
Print does not use parenthesis in Python 2. Is it possible you may have python3 installed, and this is getting picked up and used over Simon's Python 2.7?

Best regards,
Peter
daveh
Registered Member
Posts
2
Karma
0
That is what I think is going on. I do have python 3.x installed and in my path. How do i tell Simon not to use python 3.X. I have other apps that use 3.X and need it in the path.

Thanks for the reply. :)
bedahr
Moderator
Posts
141
Karma
0
OS
Honestly, I don't know what the "proper" way to do this in Windows. On Linux, you just need to edit the shebang to read /usr/bin/python2 to prefer that. I'd google what to do on Windows.
Btw, have you tried simply reordering the python installations on your path such that python 2 would be first?

Best regards,
Peter


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]