Files
Athena-Deck/applio_worker.py

29 lines
1.2 KiB
Python

"""Resident RVC inference. stdout is JSON; upstream diagnostics go to stderr."""
import contextlib,ctypes,json,os,signal,sys,traceback
def bind_parent():
if sys.platform=="linux":
parent=os.getppid()
if ctypes.CDLL(None,use_errno=True).prctl(1,signal.SIGTERM,0,0,0)!=0:raise OSError(ctypes.get_errno(),"Worker shutdown guard")
if os.getppid()!=parent:raise SystemExit("Parent process stopped")
def main():
bind_parent()
if len(sys.argv)>1 and sys.argv[1]=="--exec":
os.execv(sys.argv[2],sys.argv[2:])
# A script launched from /app does not add its runtime working directory
# to Python's import path. RVC lives in the separately installed source tree.
sys.path.insert(0,os.environ.get('APPLIO_WORKDIR',os.getcwd()))
with contextlib.redirect_stdout(sys.stderr):
from rvc.infer.infer import VoiceConverter
converter=VoiceConverter()
print(json.dumps({'ready':True}),flush=True)
for line in sys.stdin:
try:
data=json.loads(line)
with contextlib.redirect_stdout(sys.stderr):converter.convert_audio(**data)
print(json.dumps({'ok':True}),flush=True)
except Exception as exc:
traceback.print_exc(file=sys.stderr);print(json.dumps({'error':type(exc).__name__+': '+str(exc)}),flush=True)
if __name__=='__main__':main()