PK ! <+봋 html_speak/__init__.pyimport subprocess
import sys
import atexit
from pathlib import Path
import json
import regex
from urllib.parse import quote
from .util import is_html
class SpeakServer:
def __init__(self, port=29633, lang='zh_cn'):
self.port = port
self.server = subprocess.Popen([
'gunicorn',
'html_speak.server:api',
'-b', f'127.0.0.1:{self.port}'
])
self.lang = lang
env_python = Path(sys.argv[0]).name
if 'ipykernel' in env_python:
atexit.register(self.close)
elif 'pydev' in env_python:
print('hello')
atexit.register(self.close)
# signal.signal(signal.SIGINT, lambda s, f: self.close())
else:
try:
self.server.wait()
except KeyboardInterrupt:
self.close()
def close(self):
self.server.kill()
def view(self, obj, lang=None):
if not lang:
lang = self.lang
return SpeakableHTML(obj, lang, self.port)
class SpeakableHTML:
def __init__(self, obj, lang, port):
self.obj = obj
self.lang = lang
self.port = port
def _repr_html_(self):
def _sub(x):
vocab = x.group(1)
return f'''
{vocab}
'''
s = '''
'''
s += json.dumps(self.obj, cls=CustomEncoder, indent=4, ensure_ascii=False, default=repr)\
.replace('\n', '
')\
.replace(' ', ' ')
if self.lang.startswith('ja'):
regex_entity = r'([\p{IsHan}\p{IsBopo}\p{IsHira}\p{IsKatakana}\p{Block=CJK_Symbols_And_Punctuation}]+)'
elif self.lang.startswith('zh'):
regex_entity = r'([\p{IsHan}\p{Block=CJK_Symbols_And_Punctuation}]+)'
else:
return s
return regex.sub(regex_entity, _sub, s)
class CustomEncoder(json.JSONEncoder):
def iterencode(self, o, _one_shot=False):
if isinstance(o, str) and is_html(o):
return o
else:
return json.JSONEncoder.iterencode(self, o, _one_shot)
PK ! p html_speak/server.pyimport falcon
from ttslib.local import tts
class SpeakResource:
def on_get(self, req, resp):
tts(req.params['s'], req.params['lang'])
api = falcon.API()
api.add_route('/', SpeakResource())
PK ! 6 html_speak/util.pyimport regex
RE_IS_HTML = regex.compile(r"(?:[^<]+>)|(?:<[^<]+/>)")
def is_html(s):
return RE_IS_HTML.search(s) is not None
PK !HW X html_speak-0.1.1.dist-info/WHEEL
A
н#Z."jm)Afb~ڠO68oF04UhoAf
f4=4h0k::wXPK !HwM # html_speak-0.1.1.dist-info/METADATAT]o0}S
R֭kT0U6iUEM0Gb{S~]ه&{<͘c'nP26m+y+jg5-'UY2r<x+g4^9SR<,uqfՔ5dV2b R.-21WKef6,V.W&kk&|؊YЕtDK&g~ǫY+A-cJzڨ>kT*B6*3,`dVZt{][DF Qje$~dlvg{>I~s/j4I.nzAKtp1:7dA+yq{NQ-w-;TY3z:V[U+ޚhA>=pa0r_y%]ƿ_5 7z\JzB{
B8gd? PK !H8>% ! html_speak-0.1.1.dist-info/RECORD}ι0 gAT( a `ap!Y*K6<pg!2mKj6b9G@!+U` *cyז@L!#r?nlP>|FEml
4#)ؕSCvHԬdo%TCf}$e|5gҫ0>%2֎]jvP<+8WG7Y6
*VšX 6[oati=4<[((!3p:
mAPK ! <+봋 html_speak/__init__.pyPK ! p html_speak/server.pyPK ! 6
html_speak/util.pyPK !HW X s html_speak-0.1.1.dist-info/WHEELPK !HwM # html_speak-0.1.1.dist-info/METADATAPK !H8>% ! html_speak-0.1.1.dist-info/RECORDPK