def speech_synthesis(): _input = request.args.get('text') _input = str(_input) misc.command('/bin/bash /work/atango/bin/ojtalk.sh %s -q' % _input, True) with open('/tmp/out.wav', 'rb') as fd: response = make_response(fd.read()) response.headers['Content-Type'] = 'audio/wav' response.headers['Content-Disposition'] = 'attachment; filename=voice.wav' return response
def delete_term(line): if line.endswith(',E'): filename = 'enamdict.csv' elif line.endswith(',NST'): filename = 'naist_jdic.csv' elif line.endswith(',W'): filename = 'wiki120121.csv' elif line.endswith(',MZ'): filename = 'mozc.csv' elif line.endswith(',N'): filename = 'nico_name.csv' elif line.endswith(',WPH'): filename = 'wp_hiragana.csv' dicfile = os.path.join(get_dicdir(), filename) misc.command("grep -v '%s' %s > %s.temp" % (line, dicfile, dicfile), True) misc.command("mv %s.temp %s" % (dicfile, dicfile), True)
def give_valentine_present(*arg): if random.randint(0, 11) > 8: icon_url = arg[1]['icon'].replace('_normal', '') filename = icon_url.split('/')[-1] web.download(icon_url, '/tmp/%s' % (filename)) misc.command('%s evaluate.py --checkpoint ../../data/ckpt ' % (PYTHON_EXE_PATH) + '--in-path /tmp/%s --out-path /tmp/%s' % (filename, filename), shell=True, allow_err=True, cwd=STYLE_TRANSFER_PATH) return {'text': '%nameをチョコにしてやろうか!(゚Д゚)', 'media[]': '/tmp/%s' % (filename)} pid = random.randint(0, 59) xml = web.open_url(SAFEBOORU_URL % pid) soup = BeautifulSoup(xml, 'lxml') post = misc.choice(soup.find_all('post')) image_url = 'https:' + post['file_url'] web.download(image_url, '/tmp/present') suffix = '!' * random.randint(0, 59) return {'text': '%nameにチョコをヽ(´ー`)ノ' + suffix, 'media[]': '/tmp/present'}
def edit_matrix(lid, rid, cost): if cost.lower() == 'max': cost = '32765' elif cost.lower() == 'min': cost = '-32765' if not all(is_int_castable(v) for v in (lid, rid, cost)): return '[ERROR] Invalid value' lid = int(lid) rid = int(rid) cost = int(cost) if lid >= 1316 or rid >= 1316 or abs(cost) > 32765: return '[ERROR] Invalid value' matrix_file = os.path.join(get_dicdir(), 'matrix.def') line_number = 1316 * lid + rid + 2 command = "sed -e '%dc\\'$'\\n''%d %d %d' %s > /tmp/matrix" % (line_number, lid, rid, cost, matrix_file) misc.command(command, True) misc.command('mv -f /tmp/matrix %s' % matrix_file, True) return 'Success!'
def test_command(): assert misc.command('date')[0] is True
def get_dicdir(): result = misc.command('mecab-config --dicdir', True) return os.path.join(result[1].strip(), 'original')
def is_duplicate_launch(): result = misc.command('pgrep -fl python|grep "atango.py -j twitter_respond"', True) return bool(result[1].splitlines())
def read_log(path): result = misc.command(['cat', path]) return result[1].rstrip().splitlines()
def mem_usage(): result = misc.command("ps aux|awk '{ m+=$4 } END{ print m }'", True) return result[1].rstrip()
def is_updating_dic_now(): result = misc.command('pgrep -fl bash|grep "mecab_update.sh"', True) return bool(result[1].splitlines())
def get_mac_temperature(): cmd_result = misc.command('istats cpu temp', True) return float(cmd_result[1].split(' ')[2][:-2])
def test_command(): assert_true(misc.command('date')[0])
def check_matrix(lid, rid): grep = "grep -e'^%s %s ' matrix.def" % (lid, rid) result = misc.command("cd %s; %s" % (get_dicdir(), grep), True) return result[1]
def search(query): query = query.replace('*', '\\*') query = query.replace('+', '\\+') result = misc.command("cd %s; ag '%s'" % (get_dicdir(), query), True) return result[1]