How to use the nltools.misc.render_template function in nltools

To help you get started, we’ve selected a few nltools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gooofy / py-nltools / tests / test_misc.py View on Github external
val1 = "v1"
        val2 = "v2"

        expected_text = """VAR1=%s
        VAR2=%s
        """ % (val1, val2)

        src_path = os.path.join(str(self.test_dir), "src.txt")
        dst_path = os.path.join(str(self.test_dir), "dst.txt")

        with open(src_path, "wt") as f:
            f.write(template_text)

        # when
        misc.render_template(src_path, dst_path, val1=val1, val2=val2)

        # then
        with open(dst_path) as f:
            actual_text = f.read()

        self.assertEqual(expected_text, actual_text)
github gooofy / zamia-speech / speech_kaldi_export.py View on Github external
def copy_scripts_and_config_files(work_dir, kaldi_root):
    misc.copy_file('data/src/speech/kaldi-run-chain.sh',           '%s/run-chain.sh' % work_dir)
    misc.copy_file('data/src/speech/kaldi-run-adapt-lm.sh',        '%s/run-adapt-lm.sh' % work_dir)
    misc.copy_file('data/src/speech/kaldi-cmd.sh',                 '%s/cmd.sh' % work_dir)
    misc.render_template('data/src/speech/kaldi-path.sh.template', '%s/path.sh' % work_dir, kaldi_root=kaldi_root)
    misc.mkdirs('%s/conf' % work_dir)
    misc.copy_file('data/src/speech/kaldi-mfcc.conf',              '%s/conf/mfcc.conf' % work_dir)
    misc.copy_file('data/src/speech/kaldi-mfcc-hires.conf',        '%s/conf/mfcc_hires.conf' % work_dir)
    misc.copy_file('data/src/speech/kaldi-online-cmvn.conf',       '%s/conf/online_cmvn.conf' % work_dir)
    misc.mkdirs('%s/local' % work_dir)
    misc.copy_file('data/src/speech/kaldi-score.sh',               '%s/local/score.sh' % work_dir)
    misc.mkdirs('%s/local/nnet3' % work_dir)
    misc.copy_file('data/src/speech/kaldi-run-ivector-common.sh',  '%s/local/nnet3/run_ivector_common.sh' % work_dir)
github gooofy / zamia-speech / speech_sphinx_export.py View on Github external
codecs.open (test_tsfn,  'w', 'utf8') as test_tsf:

        for cfn in ts_train:
            train_fif.write ('%s\n' % cfn)
            train_tsf.write (u'<s> %s </s> (%s)\n' % (ts_train[cfn]['ts'], cfn))

        for cfn in ts_test:
            test_fif.write ('%s\n' % cfn)
            test_tsf.write (u'<s> %s </s> (%s)\n' % (ts_test[cfn]['ts'], cfn))

    logging.info ("%s written." % train_tsfn)
    logging.info ("%s written." % train_fifn)
    logging.info ("%s written." % test_tsfn)
    logging.info ("%s written." % test_fifn)

    misc.render_template('data/src/speech/sphinx-run.sh.template', '%s/sphinx-run.sh' % work_dir, lm_name=lm_name)
github gooofy / zamia-speech / wav2letter_export.py View on Github external
lex = Lexicon(file_name=dictionary)
logging.info("loading lexicon...done.")

#
# language model
#

misc.copy_file('%s/lm.arpa' % language_model_dir, '%s/lm.arpa' % data_dir)


#
# scripts
#

misc.render_template('data/src/speech/w2l_run_train.sh.template', '%s/run_train.sh' % work_dir, w2l_env_activate=w2l_env_activate, w2l_train=w2l_train)
misc.render_template('data/src/speech/w2l_run_decode.sh.template', '%s/run_decode.sh' % work_dir, w2l_env_activate=w2l_env_activate, w2l_train=w2l_train)
misc.mkdirs('%s/config/conv_glu' % work_dir)
misc.render_template('data/src/speech/w2l_config_conv_glu_train.cfg.template', '%s/config/conv_glu/train.cfg' % work_dir, runname=model_name)
misc.copy_file('data/src/speech/w2l_config_conv_glu_network.arch', '%s/config/conv_glu/network.arch' % work_dir)

#
# export audio
#

cnt = 0

def export_audio (train_val, tsdict):

    global data_dir, utt_num, options, cnt

    destdirfn = '%s/%s' % (data_dir, train_val)
github gooofy / kaldi-adapt-lm / kaldiadaptlm / __init__.py View on Github external
misc.copy_file ('%s/ivectors_test_hires/conf/splice.conf'            % src_model_dir, '%s/exp/ivectors_test_hires/conf'    % work_dir)
        misc.copy_file ('%s/ivectors_test_hires/conf/ivector_extractor.conf' % src_model_dir, '%s/exp/ivectors_test_hires/conf'    % work_dir)
        misc.copy_file ('%s/ivectors_test_hires/conf/online_cmvn.conf'       % src_model_dir, '%s/exp/ivectors_test_hires/conf'    % work_dir)

    misc.mkdirs ('%s/conf'  % work_dir)
    misc.copy_file ('%s/conf/mfcc.conf' % src_model_dir,        '%s/conf/mfcc.conf' % work_dir)
    misc.copy_file ('%s/conf/mfcc_hires.conf' % src_model_dir,  '%s/conf/mfcc_hires.conf' % work_dir)
    misc.copy_file ('%s/conf/online_cmvn.conf' % src_model_dir, '%s/conf/online_cmvn.conf' % work_dir)

    #
    # copy scripts and config files
    #
     
    misc.copy_file       ('%s/kaldi-run-adaptation.sh' % tmpl_dir, '%s/run-adaptation.sh' % work_dir)
    misc.copy_file       ('%s/kaldi-cmd.sh' % tmpl_dir,            '%s/cmd.sh' % work_dir)
    misc.render_template ('%s/kaldi-path.sh.template' % tmpl_dir,  '%s/path.sh' % work_dir, kaldi_root=kaldi_root)
    misc.copy_file       ('%s/kaldi-model-dist.sh' % tmpl_dir,     '%s/model-dist.sh' % work_dir)

    misc.symlink ('%s/egs/wsj/s5/steps' % kaldi_root, '%s/steps' % work_dir)
    misc.symlink ('%s/egs/wsj/s5/utils' % kaldi_root, '%s/utils' % work_dir)

    cmd = '/bin/bash -c "pushd %s && bash run-adaptation.sh && popd"' % work_dir
    logging.info (cmd)
    os.system (cmd)

    cmd = '/bin/bash -c "pushd %s && bash model-dist.sh "%s" && popd"' % (work_dir, dst_model_name)
    logging.info (cmd)
    os.system (cmd)
github gooofy / zamia-speech / wav2letter_export.py View on Github external
logging.info("loading lexicon...")
lex = Lexicon(file_name=dictionary)
logging.info("loading lexicon...done.")

#
# language model
#

misc.copy_file('%s/lm.arpa' % language_model_dir, '%s/lm.arpa' % data_dir)


#
# scripts
#

misc.render_template('data/src/speech/w2l_run_train.sh.template', '%s/run_train.sh' % work_dir, w2l_env_activate=w2l_env_activate, w2l_train=w2l_train)
misc.render_template('data/src/speech/w2l_run_decode.sh.template', '%s/run_decode.sh' % work_dir, w2l_env_activate=w2l_env_activate, w2l_train=w2l_train)
misc.mkdirs('%s/config/conv_glu' % work_dir)
misc.render_template('data/src/speech/w2l_config_conv_glu_train.cfg.template', '%s/config/conv_glu/train.cfg' % work_dir, runname=model_name)
misc.copy_file('data/src/speech/w2l_config_conv_glu_network.arch', '%s/config/conv_glu/network.arch' % work_dir)

#
# export audio
#

cnt = 0

def export_audio (train_val, tsdict):

    global data_dir, utt_num, options, cnt

    destdirfn = '%s/%s' % (data_dir, train_val)
github gooofy / zamia-speech / wav2letter_export.py View on Github external
#
# language model
#

misc.copy_file('%s/lm.arpa' % language_model_dir, '%s/lm.arpa' % data_dir)


#
# scripts
#

misc.render_template('data/src/speech/w2l_run_train.sh.template', '%s/run_train.sh' % work_dir, w2l_env_activate=w2l_env_activate, w2l_train=w2l_train)
misc.render_template('data/src/speech/w2l_run_decode.sh.template', '%s/run_decode.sh' % work_dir, w2l_env_activate=w2l_env_activate, w2l_train=w2l_train)
misc.mkdirs('%s/config/conv_glu' % work_dir)
misc.render_template('data/src/speech/w2l_config_conv_glu_train.cfg.template', '%s/config/conv_glu/train.cfg' % work_dir, runname=model_name)
misc.copy_file('data/src/speech/w2l_config_conv_glu_network.arch', '%s/config/conv_glu/network.arch' % work_dir)

#
# export audio
#

cnt = 0

def export_audio (train_val, tsdict):

    global data_dir, utt_num, options, cnt

    destdirfn = '%s/%s' % (data_dir, train_val)

    lcnt = 0
github gooofy / zamia-speech / abook-kaldi-segment.py View on Github external
# clean up leftovers from previous runs
#

cmd = 'rm -rf %s' % WORKDIR
logging.info(cmd)
os.system(cmd)
misc.mkdirs(WORKDIR)

#
# copy scripts
#

misc.copy_file ('data/src/speech/kaldi-run-segmentation.sh', '%s/run-segmentation.sh' % WORKDIR)

misc.copy_file ('data/src/speech/kaldi-cmd.sh', '%s/cmd.sh' % WORKDIR)
misc.render_template ('data/src/speech/kaldi-path.sh.template', '%s/path.sh' % WORKDIR, kaldi_root=kaldi_root)
misc.symlink ('%s/egs/wsj/s5/steps' % kaldi_root, '%s/steps' % WORKDIR)
misc.symlink ('%s/egs/wsj/s5/utils' % kaldi_root, '%s/utils' % WORKDIR)

#
# create skeleton dst model
#

misc.mkdirs ('%s/exp'  % WORKDIR)

cmd = "cp -r '%s/model' '%s/exp/tri2b_adapt'" % (modelfn, WORKDIR)
logging.info(cmd)
os.system(cmd)
cmd = "cp -r '%s/data'  '%s/data'" % (modelfn, WORKDIR)
logging.info(cmd)
os.system(cmd)
cmd = "cp -r '%s/conf'  '%s/conf'" % (modelfn, WORKDIR)