|
10精币
def pipe_server(self):
"""自定义socket服务器
发送格式必须是json字符串 范例:
{"tag": "bye"} 关闭并退出
{"tag": "start"} 开始音频转换
{"tag": "init", “values”: {}} 初始化所有配置
{"tag": "stop"} 停止rvc
{"tag": "status"} 查看运行状态
{"tag": "devices"} 查看设备列表
单一配置
{"tag": "config", "value": { "pth_path": "D:/X/M/luoluo.pth"}
"""
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 19730
sk.bind(("127.0.0.1", port))
sk.listen(1)
conn, address = sk.accept()
interval = timedelta(seconds=0.5)
last_time = datetime.now()
while True:
time.sleep(0.1)
try:
client_data = conn.recv(1024).decode('utf-8')
Msg = json.loads(client_data)
except ConnectionResetError as e:
break
except:
conn.send(json.dumps({"code": 500, "msg": "Can't recv/json u msg", "data": None}).encode(encoding="utf-8"))
continue
try:
if Msg["tag"] == "bye":
conn.send(json.dumps({"code": 200, "msg": "byebye", "data": None}).encode(encoding="utf-8"))
break
elif Msg["tag"] == "start":
if self.flag_vc:
conn.send(json.dumps({"code": 500, "msg": "Rvc is already running.", "data": None}).encode(encoding="utf-8"))
else:
try:
print("using_cuda:" + str(torch.cuda.is_available()))
self.start_vc()
except Exception as e:
self.flag_vc = False
conn.send(json.dumps({"code": 500, "msg": str(e), "data": None}).encode(encoding="utf-8"))
elif Msg["tag"] == "init":
if self.flag_vc:
conn.send(json.dumps({"code": 500, "msg": "Rvc is already running.", "data": None}).encode(encoding="utf-8"))
else:
try:
values = Msg["values"]
这是python上的代码 怎样在易语言上实现和他实时交互 求助 谢谢大佬
|
|