From 36374d69790735638a108739ed410837dd4408b1 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Mon, 24 Jul 2023 23:50:35 +0900 Subject: [PATCH] =?UTF-8?q?[Add]=20init=E6=99=82=E3=81=ABOSC=E3=81=AE?= =?UTF-8?q?=E8=B5=B7=E5=8B=95=E7=A2=BA=E8=AA=8D=E3=82=92=E8=A1=8C=E3=81=86?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 裏でOSC receive処理は回りっぱなし --- VRCT.py | 30 ++++++++++++++++++++++++++---- osc_tools.py | 18 +++++++++++++++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/VRCT.py b/VRCT.py index 84c72f23..64cc44b6 100644 --- a/VRCT.py +++ b/VRCT.py @@ -10,7 +10,7 @@ from flashtext import KeywordProcessor from threading import Thread from utils import save_json, print_textbox, thread_fnc, get_localized_text, widget_main_window_label_setter -from osc_tools import send_typing, send_message +from osc_tools import send_typing, send_message, send_test_action, receive_osc_parameters from window_config import ToplevelWindowConfig from window_information import ToplevelWindowInformation from languages import transcription_lang, translators, translation_lang, selectable_languages @@ -77,6 +77,7 @@ class App(CTk): self.MESSAGE_FORMAT = "[message]([translation])" # Others self.ENABLE_AUTO_CLEAR_CHATBOX = False + self.ENABLE_OSC = False # load config if os_path.isfile(self.PATH_CONFIG) is not False: @@ -403,6 +404,14 @@ class App(CTk): self.config_window = ToplevelWindowConfig(self) + # start receive osc + th_receive_osc_parameters = Thread(target=receive_osc_parameters, args=(self.check_osc_receive,)) + th_receive_osc_parameters.daemon = True + th_receive_osc_parameters.start() + + # check osc started + send_test_action() + def button_config_callback(self): self.checkbox_translation.configure(state="disabled") self.checkbox_transcription_send.configure(state="disabled") @@ -477,8 +486,12 @@ class App(CTk): voice_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) if self.checkbox_transcription_send.get() is True: - # send OSC message - send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + if self.ENABLE_OSC is True: + # send OSC message + send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + else: + print_textbox(self.textbox_message_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR") + print_textbox(self.textbox_message_system_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR") # update textbox message log print_textbox(self.textbox_message_log, f"{voice_message}", "SEND") print_textbox(self.textbox_message_send_log, f"{voice_message}", "SEND") @@ -647,7 +660,11 @@ class App(CTk): chat_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) # send OSC message - send_message(chat_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + if self.ENABLE_OSC is True: + send_message(chat_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + else: + print_textbox(self.textbox_message_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR") + print_textbox(self.textbox_message_system_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR") # update textbox message log print_textbox(self.textbox_message_log, f"{chat_message}", "SEND") @@ -747,6 +764,11 @@ class App(CTk): widget_main_window_label_setter(self, language_yaml_data) + def check_osc_receive(self, address, osc_arguments): + if self.ENABLE_OSC is False: + self.ENABLE_OSC = True + # print(address, osc_arguments) + if __name__ == "__main__": try: app = App() diff --git a/osc_tools.py b/osc_tools.py index dacda522..7c7d9504 100644 --- a/osc_tools.py +++ b/osc_tools.py @@ -1,5 +1,9 @@ +from time import sleep +from typing import List from pythonosc import osc_message_builder from pythonosc import udp_client +from pythonosc import dispatcher +from pythonosc import osc_server # send OSC message typing def send_typing(flag=False, ip_address="127.0.0.1", port=9000): @@ -18,4 +22,16 @@ def send_message(message=None, ip_address="127.0.0.1", port=9000): msg.add_arg(True) b_msg = msg.build() client = udp_client.SimpleUDPClient(ip_address, port) - client.send(b_msg) \ No newline at end of file + client.send(b_msg) + +def send_test_action(ip_address="127.0.0.1", port=9000): + client = udp_client.SimpleUDPClient(ip_address, port) + client.send_message("/input/Vertical", 1) + sleep(0.01) + client.send_message("/input/Vertical", False) + +def receive_osc_parameters(target, filter="/*", ip_address="127.0.0.1", port=9001): + _dispatcher = dispatcher.Dispatcher() + _dispatcher.map(filter, target) + server = osc_server.ThreadingOSCUDPServer((ip_address, port), _dispatcher) + server.serve_forever() \ No newline at end of file