def default_test_prop(): """Return the default proportion for the test set Try to read from configuration file, else return 0.5""" try: return float(config.get('split', 'default-test-proportion')) except ConfigParser.NoOptionError: return 0.5
def kaldi_path(): """Return an environment for running the abkhazia recipes""" env = os.environ env['LC_ALL'] = 'C' # for expected sorting and joining behaviour kaldiroot = config.get('kaldi', 'kaldi-directory') kaldisrc = os.path.join(kaldiroot, 'src') targets = ('bin', 'featbin', 'fgmmbin', 'fstbin', 'gmmbin', 'latbin', 'nnetbin', 'nnet2bin', 'sgmmbin', 'lmbin', 'kwsbin', 'ivectorbin', 'online2bin', 'sgmm2bin') kaldibin = ':'.join((os.path.join(kaldisrc, target) for target in targets)) fstbin = os.path.join(kaldiroot, 'tools', 'openfst', 'bin') platform = 'macosx' if os.uname()[0] is 'Darwin' else 'i686-m64' lmbin = ':'.join([ os.path.join(kaldiroot, 'tools', 'irstlm', 'bin'), os.path.join(kaldiroot, 'tools', 'srilm', 'bin'), os.path.join(kaldiroot, 'tools', 'srilm', 'bin', platform), os.path.join(kaldiroot, 'tools', 'sctk', 'bin') ]) if 'PATH' not in env: # PATH isn't in the environment, should not occur env['PATH'] = ':'.join([kaldibin, fstbin, lmbin]) else: path = ':'.join([kaldibin, fstbin, lmbin]) if path not in env['PATH']: env['PATH'] += ':' + path env['IRSTLM'] = os.path.join(kaldiroot, 'tools', 'irstlm') # was a bug -> error while loading shared libraries: libfstscript.so.1 fstlib = os.path.join(kaldiroot, 'tools', 'openfst', 'lib') libfstscript = os.path.join(fstlib, 'libfstscript.so.1') assert os.path.exists(libfstscript) if 'LD_LIBRARY_PATH' not in env: env['LD_LIBRARY_PATH'] = fstlib else: if fstlib not in env['LD_LIBRARY_PATH']: env['LD_LIBRARY_PATH'] += ':' + fstlib return env
def __init__(self, corpus, recipe_dir, name='recipe', log=logger.null_logger()): # filter out short utterances self.corpus = corpus.subcorpus( self._desired_utterances(corpus), validate=False) # init the recipe directory, create it if needed self.recipe_dir = recipe_dir if not os.path.isdir(self.recipe_dir): os.makedirs(self.recipe_dir) self.name = name self.log = log # init the path to kaldi self.kaldi_root = config.get('kaldi', 'kaldi-directory') # init the path to abkhazia/share self.share_dir = pkg_resources.resource_filename( pkg_resources.Requirement.parse('abkhazia'), 'abkhazia/share')
def _write_cmd_script(script): with open(script, 'w') as stream: for cmd in ('train', 'decode', 'highmem'): key = '{}-cmd'.format(cmd) value = config.get('kaldi', key) stream.write('export {}={}\n'.format(key, value))