Skip to content

Instantly share code, notes, and snippets.

@julie-is-late
Last active February 21, 2019 02:44
Show Gist options
  • Save julie-is-late/cd65d12bd165919f3035ac8be28788b2 to your computer and use it in GitHub Desktop.
Save julie-is-late/cd65d12bd165919f3035ac8be28788b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import csv
import os
import subprocess
import json
import time
import signal
import sys
char_size = {}
def save_and_quit():
with open('test.csv', 'w') as f:
for key in char_size.keys():
f.write("{},{}\n".format(key,char_size[key]))
def signal_handler(sig, frame):
save_and_quit()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
start = 0
try:
with open('test.csv') as k:
reader = csv.reader(k)
char_size = {int(rows[0]):float(rows[1]) for rows in reader}
start=max(char_size.keys())
print("starting at: {}".format(chr(start)))
except:
pass
for x in range(start,0x110000):
charry = chr(x)
try:
print("{}: {}".format(hex(x), charry))
except:
continue
with open("tmp.json", "w") as k:
jc = {}
jc['voice'] = "Brian"
jc['text'] = charry*10
json.dump(jc, k)
filename = "data/{}.ogg".format(x)
s = subprocess.run("curl -d '@tmp.json' -H 'Content-Type: application/json' -X POST 'https://streamlabs.com/polly/speak' | sed 's/.*speak_url\":\"//' | sed 's/\"}}$//' | xargs curl -o {} -X GET".format(filename), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if s.returncode > 0:
time.sleep(30)
continue
r = subprocess.run("du {}".format(filename), shell=True, stdout=subprocess.PIPE)
runtime=int(r.stdout.decode(encoding='UTF-8').split("\t")[0])*0.1875
print(str(runtime) + "s")
char_size[x] = runtime
time.sleep(4)
save_and_quit()
#!/usr/bin/env python
import csv
import os
import subprocess
import json
import time
import signal
import sys
char_size = {}
def save_and_quit():
with open('test.csv', 'w') as f:
for key in char_size.keys():
f.write("{},{}\n".format(key,char_size[key]))
def signal_handler(sig, frame):
save_and_quit()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
start = 0
try:
with open('test.csv') as k:
reader = csv.reader(k)
char_size = {int(rows[0]):float(rows[1]) for rows in reader}
start=max(char_size.keys())
print("starting at: {}".format(chr(start)))
except:
pass
for x in range(start,0x110000):
charry = chr(x)
print("{}: {}".format(x, charry))
with open("tmp.json", "w") as k:
jc = {}
jc['voice'] = "Brian"
jc['text'] = charry*10
json.dump(jc, k)
filename = "data/{}.ogg".format(x)
s = subprocess.run("curl -d '@tmp.json' -H 'Content-Type: application/json' -X POST 'https://streamlabs.com/polly/speak' | sed 's/.*speak_url\":\"//' | sed 's/\"}}$//' | xargs curl -o {} -X GET".format(filename), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if s.returncode > 0:
time.sleep(30)
continue
s = subprocess.run("{{ TIMEFORMAT='%R' ; {{ time mpv {} >/dev/null 2>&- ; }} 2>&1 ; }}".format(filename), shell=True, stdout=subprocess.PIPE)
runtime = float(s.stdout)
print(runtime)
char_size[x] = runtime
time.sleep(3)
save_and_quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment