🚧[WIP/TEST] Controller : stdioでのtauriとpythonの通信をutf8でエンコード/デコードするように変更

This commit is contained in:
misyaguziya
2024-08-31 11:04:11 +09:00
parent 0a7e5e0a93
commit bc59cf6089
3 changed files with 16 additions and 9 deletions

View File

@@ -5,11 +5,17 @@ from subprocess import Popen
from threading import Thread
from config import config
from model import model
# from view import view
from utils import getKeyByValue, isUniqueStrings, strPctToInt
import argparse
from utils import getKeyByValue, isUniqueStrings
# Common
def encodeUtf8(data:str) -> dict:
data = {i: byte for i, byte in enumerate(data.encode('UTF-8'))}
return data
def decodeUtf8(data:dict) -> str:
data = bytes(data.values()).decode("UTF-8")
return data
class DownloadSoftwareProgressBar:
def __init__(self, action):
self.action = action
@@ -305,7 +311,7 @@ class ChatMessage:
def send(self, data):
id = data["id"]
message = data["message"]
message = decodeUtf8(data["message"])
if len(message) > 0:
addSentMessageLog(message)
translation = ""
@@ -345,6 +351,8 @@ class ChatMessage:
translation = f" ({translation})"
model.logger.info(f"[SENT] {message}{translation}")
message = encodeUtf8(message)
translation = encodeUtf8(translation)
return {"status":200,
"result":{
"id":id,
@@ -1364,4 +1372,5 @@ def init(endpoints:dict, *args, **kwargs) -> None:
print(json.dumps({"status":348, "log": "Init OSC Receive"}), flush=True)
model.startReceiveOSC()
if config.ENABLE_VRC_MIC_MUTE_SYNC is True:
model.startCheckMuteSelfStatus()
model.startCheckMuteSelfStatus()
print(json.dumps({"status":348, "log": "End Initialization"}), flush=True)

View File

@@ -326,13 +326,10 @@ def main():
print(response, flush=True)
if __name__ == "__main__":
print(json.dumps({"status":200, "endpoint": "/initialization/start", "result":True}), flush=True)
controller.init({
"ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"],
"whisper": action_mapping["/controller/callback_download_whisper_weight"]["download"],
})
print(json.dumps({"status":200, "endpoint": "/initialization/completed", "result":True}), flush=True)
print(json.dumps({"status":348, "log": "Initialization from Python."}), flush=True)
process = "main"
match process: