def test_run_command(self): txt = '' for line in misc.run_command(['uname', '-a']): txt += line.strip() self.assertEqual('Linux' in txt, True)
def sequitur_gen_ipa_multi(modelfn, words): ipa_map = {} with tempfile.NamedTemporaryFile() as f: for word in words: f.write((u'%s\n' % word).encode('utf8')) f.flush() cmd = ['g2p.py', '--model', modelfn, '--apply', f.name] res = misc.run_command(cmd, capture_stderr=False) logging.debug('%s' % ' '.join(cmd)) for l in res: line = l.strip() logging.debug('%s' % line) if 'stack usage:' in line: continue parts = line.decode('utf8', errors='ignore').split('\t') if len(parts) < 2: continue try: word = parts[0] if word in words: xs = parts[1] # print 'XS', xs ipa = xsampa2ipa(word, xs) ipa_map[word] = ipa except: logging.error("Error processing line %s:" % line) logging.error(traceback.format_exc()) return ipa_map
def sequitur_gen_ipa(modelfn, word): ipa = u'' with tempfile.NamedTemporaryFile() as f: f.write((u'%s\n' % word).encode('utf8')) f.flush() cmd = ['g2p.py', '--model', modelfn, '--apply', f.name] res = misc.run_command(cmd) logging.debug('%s' % ' '.join(cmd)) for l in res: line = l.strip() logging.debug('%s' % line) if 'stack usage:' in line: continue if word in line.decode('utf8'): parts = line.split('\t') if len(parts) < 2: continue xs = parts[1] # print 'XS', xs ipa = xsampa2ipa(word, xs) return ipa