👍️[Update] Model : OverlayのUIにsakuraを追加
This commit is contained in:
12
config.py
12
config.py
@@ -727,6 +727,17 @@ class Config:
|
||||
self._ENABLE_NOTICE_OVERLAY = value
|
||||
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
|
||||
|
||||
@property
|
||||
@json_serializable('OVERLAY_UI_TYPE')
|
||||
def OVERLAY_UI_TYPE(self):
|
||||
return self._OVERLAY_UI_TYPE
|
||||
|
||||
@OVERLAY_UI_TYPE.setter
|
||||
def OVERLAY_UI_TYPE(self, value):
|
||||
if isinstance(value, str):
|
||||
self._OVERLAY_UI_TYPE = value
|
||||
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
|
||||
|
||||
@property
|
||||
@json_serializable('ENABLE_SEND_MESSAGE_TO_VRC')
|
||||
def ENABLE_SEND_MESSAGE_TO_VRC(self):
|
||||
@@ -991,6 +1002,7 @@ class Config:
|
||||
self._SEND_MESSAGE_BUTTON_TYPE = "show"
|
||||
self._ENABLE_NOTICE_XSOVERLAY = False
|
||||
self._ENABLE_NOTICE_OVERLAY = False
|
||||
self._OVERLAY_UI_TYPE = "default"
|
||||
self._ENABLE_SEND_MESSAGE_TO_VRC = True
|
||||
self._ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = False # Speaker2Chatbox
|
||||
self._ENABLE_SPEAKER2CHATBOX_PASS = "000000000"
|
||||
|
||||
BIN
img/overlay_br_sakura.png
Normal file
BIN
img/overlay_br_sakura.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.9 KiB |
BIN
img/overlay_tl_sakura.png
Normal file
BIN
img/overlay_tl_sakura.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
3
model.py
3
model.py
@@ -542,7 +542,8 @@ class Model:
|
||||
def createOverlayImageShort(self, message, translation):
|
||||
your_language = config.TARGET_LANGUAGE
|
||||
target_language = config.SOURCE_LANGUAGE
|
||||
return self.overlay_image.create_overlay_image_short(message, your_language, translation, target_language)
|
||||
ui_type = config.OVERLAY_UI_TYPE
|
||||
return self.overlay_image.create_overlay_image_short(message, your_language, translation, target_language, ui_type)
|
||||
|
||||
def createOverlayImageLong(self, message_type, message, translation):
|
||||
your_language = config.TARGET_LANGUAGE if message_type == "receive" else config.SOURCE_LANGUAGE
|
||||
|
||||
@@ -172,7 +172,7 @@ if __name__ == '__main__':
|
||||
t.start()
|
||||
|
||||
time.sleep(1)
|
||||
img = overlay_image.create_overlay_image_short("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese")
|
||||
img = overlay_image.create_overlay_image_short("こんにちは、世界!さようなら", "Japanese", "Hello,World!Goodbye", "Japanese", ui_type="sakura")
|
||||
if overlay.initFlag is True:
|
||||
overlay.uiMan.uiUpdate(img)
|
||||
time.sleep(10)
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
from os import path as os_path
|
||||
from datetime import datetime
|
||||
# from datetime import datetime
|
||||
from typing import Tuple
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
class OverlayImage:
|
||||
WIDTH = 1920//2
|
||||
HEIGHT = 46//2
|
||||
BACKGROUND_COLOR = (41, 42, 45)
|
||||
TEXT_COLOR_LARGE = (223, 223, 223)
|
||||
TEXT_COLOR_SMALL = (190, 190, 190)
|
||||
TEXT_COLOR_SEND = (70, 161, 146)
|
||||
TEXT_COLOR_RECEIVE = (220, 20, 60)
|
||||
TEXT_COLOR_TIME = (120, 120, 120)
|
||||
FONT_SIZE_LARGE = HEIGHT
|
||||
FONT_SIZE_SMALL = int(FONT_SIZE_LARGE * 2 / 3)
|
||||
FONT_SIZE_SHORT = HEIGHT
|
||||
|
||||
# TEXT_COLOR_LARGE = (223, 223, 223)
|
||||
# TEXT_COLOR_SMALL = (190, 190, 190)
|
||||
# TEXT_COLOR_SEND = (70, 161, 146)
|
||||
# TEXT_COLOR_RECEIVE = (220, 20, 60)
|
||||
# TEXT_COLOR_TIME = (120, 120, 120)
|
||||
# FONT_SIZE_LARGE = HEIGHT
|
||||
# FONT_SIZE_SMALL = int(FONT_SIZE_LARGE * 2 / 3)
|
||||
LANGUAGES = {
|
||||
"Japanese": "NotoSansJP-Regular",
|
||||
"Korean": "NotoSansKR-Regular",
|
||||
@@ -40,135 +41,188 @@ class OverlayImage:
|
||||
result.paste(image, (left, top))
|
||||
return result
|
||||
|
||||
def create_textimage(self, message_type, size, text, language):
|
||||
font_size = self.FONT_SIZE_LARGE if size == "large" else self.FONT_SIZE_SMALL
|
||||
text_color = self.TEXT_COLOR_LARGE if size == "large" else self.TEXT_COLOR_SMALL
|
||||
anchor = "lm" if message_type == "receive" else "rm"
|
||||
text_x = 0 if message_type == "receive" else self.WIDTH
|
||||
align = "left" if message_type == "receive" else "right"
|
||||
# def create_textimage(self, message_type, size, text, language):
|
||||
# font_size = self.FONT_SIZE_LARGE if size == "large" else self.FONT_SIZE_SMALL
|
||||
# text_color = self.TEXT_COLOR_LARGE if size == "large" else self.TEXT_COLOR_SMALL
|
||||
# anchor = "lm" if message_type == "receive" else "rm"
|
||||
# text_x = 0 if message_type == "receive" else self.WIDTH
|
||||
# align = "left" if message_type == "receive" else "right"
|
||||
|
||||
# font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
||||
# img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||
# draw = ImageDraw.Draw(img)
|
||||
# font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", f"{font_family}.ttf"), font_size)
|
||||
# # font = ImageFont.truetype(os_path.join("./fonts", f"{font_family}.ttf"), font_size)
|
||||
# text_width = draw.textlength(text, font)
|
||||
# character_width = text_width // len(text)
|
||||
# character_line_num = int(self.WIDTH // character_width)
|
||||
# if len(text) > character_line_num:
|
||||
# text = "\n".join([text[i:i+character_line_num] for i in range(0, len(text), character_line_num)])
|
||||
|
||||
# n_num = len(text.split("\n")) - 1
|
||||
# text_height = int(font_size*(n_num+2))
|
||||
|
||||
# img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0))
|
||||
# draw = ImageDraw.Draw(img)
|
||||
|
||||
# text_y = text_height // 2
|
||||
|
||||
# draw.multiline_text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font, align=align)
|
||||
# return img
|
||||
|
||||
# def create_textimage_message_type(self, message_type):
|
||||
# anchor = "lm" if message_type == "receive" else "rm"
|
||||
# text = "Receive" if message_type == "receive" else "Send"
|
||||
# text_color = self.TEXT_COLOR_RECEIVE if message_type == "receive" else self.TEXT_COLOR_SEND
|
||||
# text_color_time = self.TEXT_COLOR_TIME
|
||||
|
||||
# now = datetime.now()
|
||||
# formatted_time = now.strftime("%H:%M")
|
||||
# font_size = self.FONT_SIZE_SMALL
|
||||
# img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||
# draw = ImageDraw.Draw(img)
|
||||
# font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", "NotoSansJP-Regular.ttf"), font_size)
|
||||
# # font = ImageFont.truetype(os_path.join("./fonts", "NotoSansJP-Regular.ttf"), font_size)
|
||||
# text_height = font_size*2
|
||||
# text_width = draw.textlength(formatted_time, font)
|
||||
# character_width = text_width // len(formatted_time)
|
||||
# img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0))
|
||||
# draw = ImageDraw.Draw(img)
|
||||
# text_y = text_height // 2
|
||||
# text_time_x = 0 if message_type == "receive" else self.WIDTH - (text_width + character_width)
|
||||
# text_x = (text_width + character_width) if message_type == "receive" else self.WIDTH
|
||||
|
||||
# draw.text((text_time_x, text_y), formatted_time, text_color_time, anchor=anchor, stroke_width=0, font=font)
|
||||
# draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font)
|
||||
# return img
|
||||
|
||||
# def create_textbox(self, message_type, message, your_language, translation, target_language):
|
||||
# message_type_img = self.create_textimage_message_type(message_type)
|
||||
# if len(translation) > 0 and target_language is not None:
|
||||
# img = self.create_textimage(message_type, "small", message, your_language)
|
||||
# translation_img = self.create_textimage(message_type, "large",translation, target_language)
|
||||
# img = self.concatenate_images_vertically(img, translation_img)
|
||||
# else:
|
||||
# img = self.create_textimage(message_type, "large", message, your_language)
|
||||
# return self.concatenate_images_vertically(message_type_img, img)
|
||||
|
||||
# def create_overlay_image_long(self, message_type, message, your_language, translation="", target_language=None):
|
||||
# if len(self.log_data) > 10:
|
||||
# self.log_data.pop(0)
|
||||
|
||||
# self.log_data.append(
|
||||
# {
|
||||
# "message_type":message_type,
|
||||
# "message":message,
|
||||
# "your_language":your_language,
|
||||
# "translation":translation,
|
||||
# "target_language":target_language,
|
||||
# }
|
||||
# )
|
||||
|
||||
# imgs = []
|
||||
# for log in self.log_data:
|
||||
# message_type = log["message_type"]
|
||||
# message = log["message"]
|
||||
# your_language = log["your_language"]
|
||||
# translation = log["translation"]
|
||||
# target_language = log["target_language"]
|
||||
# img = self.create_textbox(message_type, message, your_language, translation, target_language)
|
||||
# imgs.append(img)
|
||||
|
||||
# img = imgs[0]
|
||||
# for i in imgs[1:]:
|
||||
# img = self.concatenate_images_vertically(img, i)
|
||||
# img = self.add_image_margin(img, 0, 20, 0, 20, (0, 0, 0, 0))
|
||||
|
||||
# width, height = img.size
|
||||
# background = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||
# draw = ImageDraw.Draw(background)
|
||||
# draw.rounded_rectangle([(0, 0), (width, height)], radius=15, fill=self.BACKGROUND_COLOR, outline=self.BACKGROUND_OUTLINE_COLOR, width=5)
|
||||
# img = Image.alpha_composite(background, img)
|
||||
# return img
|
||||
|
||||
def get_ui_size(self):
|
||||
return {
|
||||
"width": 960,
|
||||
"height": 23,
|
||||
"font_size": 23,
|
||||
}
|
||||
|
||||
def get_ui_colors(self, ui_type):
|
||||
match ui_type:
|
||||
case "default":
|
||||
background_color = (41, 42, 45, 127)
|
||||
background_outline_color = (41, 42, 45, 127)
|
||||
text_color = (223, 223, 223)
|
||||
case "sakura":
|
||||
background_color = (225, 40, 30, 20)
|
||||
background_outline_color = (255, 255, 255, 50)
|
||||
text_color = (223, 223, 223)
|
||||
return {
|
||||
"background_color": background_color,
|
||||
"background_outline_color": background_outline_color,
|
||||
"text_color": text_color
|
||||
}
|
||||
|
||||
def create_decoration_image(self, ui_type, image_size):
|
||||
decoration_image = Image.new("RGBA", image_size, (0, 0, 0, 0))
|
||||
match ui_type:
|
||||
case "default":
|
||||
pass
|
||||
case "sakura":
|
||||
overlay_tl = Image.open(os_path.join(os_path.dirname(__file__), "img", "overlay_tl_sakura.png"))
|
||||
overlay_br = Image.open(os_path.join(os_path.dirname(__file__), "img", "overlay_br_sakura.png"))
|
||||
alpha = overlay_tl.getchannel("A")
|
||||
alpha = alpha.point(lambda x: x * 0.1)
|
||||
overlay_tl.putalpha(alpha)
|
||||
alpha = overlay_br.getchannel("A")
|
||||
alpha = alpha.point(lambda x: x * 0.1)
|
||||
overlay_br.putalpha(alpha)
|
||||
decoration_image.paste(overlay_tl, (7, 7))
|
||||
decoration_image.paste(overlay_br, (image_size[0]-overlay_br.size[0]-7, image_size[1]-overlay_br.size[1]-7))
|
||||
return decoration_image
|
||||
|
||||
def create_textbox_short(self, text, language, text_color, base_width, base_height, font_size):
|
||||
font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
||||
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||
img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(img)
|
||||
font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", f"{font_family}.ttf"), font_size)
|
||||
# font = ImageFont.truetype(os_path.join("./fonts", f"{font_family}.ttf"), font_size)
|
||||
text_width = draw.textlength(text, font)
|
||||
character_width = text_width // len(text)
|
||||
character_line_num = int(self.WIDTH // character_width)
|
||||
character_line_num = int((base_width) // character_width) - 12
|
||||
if len(text) > character_line_num:
|
||||
text = "\n".join([text[i:i+character_line_num] for i in range(0, len(text), character_line_num)])
|
||||
|
||||
n_num = len(text.split("\n")) - 1
|
||||
text_height = int(font_size*(n_num+2))
|
||||
|
||||
img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0))
|
||||
text_height = font_size * (len(text.split("\n")) + 1) + 20
|
||||
img = Image.new("RGBA", (base_width, text_height), (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
text_x = base_width // 2
|
||||
text_y = text_height // 2
|
||||
|
||||
draw.multiline_text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font, align=align)
|
||||
draw.text((text_x, text_y), text, text_color, anchor="mm", stroke_width=0, font=font, align="center")
|
||||
return img
|
||||
|
||||
def create_textimage_message_type(self, message_type):
|
||||
anchor = "lm" if message_type == "receive" else "rm"
|
||||
text = "Receive" if message_type == "receive" else "Send"
|
||||
text_color = self.TEXT_COLOR_RECEIVE if message_type == "receive" else self.TEXT_COLOR_SEND
|
||||
text_color_time = self.TEXT_COLOR_TIME
|
||||
def create_overlay_image_short(self, message, your_language, translation="", target_language=None, ui_type="default"):
|
||||
ui_size = self.get_ui_size()
|
||||
height = ui_size["height"]
|
||||
width = ui_size["width"]
|
||||
font_size = ui_size["font_size"]
|
||||
|
||||
now = datetime.now()
|
||||
formatted_time = now.strftime("%H:%M")
|
||||
font_size = self.FONT_SIZE_SMALL
|
||||
img = Image.new("RGBA", (0, 0), (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(img)
|
||||
font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", "NotoSansJP-Regular.ttf"), font_size)
|
||||
# font = ImageFont.truetype(os_path.join("./fonts", "NotoSansJP-Regular.ttf"), font_size)
|
||||
text_height = font_size*2
|
||||
text_width = draw.textlength(formatted_time, font)
|
||||
character_width = text_width // len(formatted_time)
|
||||
img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(img)
|
||||
text_y = text_height // 2
|
||||
text_time_x = 0 if message_type == "receive" else self.WIDTH - (text_width + character_width)
|
||||
text_x = (text_width + character_width) if message_type == "receive" else self.WIDTH
|
||||
ui_colors = self.get_ui_colors(ui_type)
|
||||
text_color = ui_colors["text_color"]
|
||||
background_color = ui_colors["background_color"]
|
||||
background_outline_color = ui_colors["background_outline_color"]
|
||||
|
||||
draw.text((text_time_x, text_y), formatted_time, text_color_time, anchor=anchor, stroke_width=0, font=font)
|
||||
draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font)
|
||||
return img
|
||||
|
||||
def create_textbox(self, message_type, message, your_language, translation, target_language):
|
||||
message_type_img = self.create_textimage_message_type(message_type)
|
||||
img = self.create_textbox_short(message, your_language, text_color, width, height, font_size)
|
||||
if len(translation) > 0 and target_language is not None:
|
||||
img = self.create_textimage(message_type, "small", message, your_language)
|
||||
translation_img = self.create_textimage(message_type, "large",translation, target_language)
|
||||
img = self.concatenate_images_vertically(img, translation_img)
|
||||
else:
|
||||
img = self.create_textimage(message_type, "large", message, your_language)
|
||||
return self.concatenate_images_vertically(message_type_img, img)
|
||||
|
||||
def create_overlay_image_long(self, message_type, message, your_language, translation="", target_language=None):
|
||||
if len(self.log_data) > 10:
|
||||
self.log_data.pop(0)
|
||||
|
||||
self.log_data.append(
|
||||
{
|
||||
"message_type":message_type,
|
||||
"message":message,
|
||||
"your_language":your_language,
|
||||
"translation":translation,
|
||||
"target_language":target_language,
|
||||
}
|
||||
)
|
||||
|
||||
imgs = []
|
||||
for log in self.log_data:
|
||||
message_type = log["message_type"]
|
||||
message = log["message"]
|
||||
your_language = log["your_language"]
|
||||
translation = log["translation"]
|
||||
target_language = log["target_language"]
|
||||
img = self.create_textbox(message_type, message, your_language, translation, target_language)
|
||||
imgs.append(img)
|
||||
|
||||
img = imgs[0]
|
||||
for i in imgs[1:]:
|
||||
img = self.concatenate_images_vertically(img, i)
|
||||
img = self.add_image_margin(img, 0, 20, 0, 20, (0, 0, 0, 0))
|
||||
|
||||
width, height = img.size
|
||||
background = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(background)
|
||||
draw.rounded_rectangle([(0, 0), (width, height)], radius=15, fill=self.BACKGROUND_COLOR, outline=self.BACKGROUND_COLOR, width=5)
|
||||
img = Image.alpha_composite(background, img)
|
||||
return img
|
||||
|
||||
def create_overlay_image_short(self, message, your_language, translation="", target_language=None):
|
||||
def create_textbox(text, language):
|
||||
font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular")
|
||||
img = Image.new("RGBA", (self.WIDTH, self.HEIGHT), (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(img)
|
||||
font = ImageFont.truetype(os_path.join(os_path.dirname(__file__), "fonts", f"{font_family}.ttf"), self.FONT_SIZE_LARGE)
|
||||
text_width = draw.textlength(text, font)
|
||||
character_width = text_width // len(text)
|
||||
character_line_num = int((self.WIDTH - 40) // character_width)
|
||||
if len(text) > character_line_num:
|
||||
text = "\n".join([text[i:i+character_line_num] for i in range(0, len(text), character_line_num)])
|
||||
text_height = self.FONT_SIZE_LARGE * (len(text.split("\n")) + 1) + 20
|
||||
img = Image.new("RGBA", (self.WIDTH, text_height), (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
text_x = self.WIDTH // 2
|
||||
text_y = text_height // 2
|
||||
draw.text((text_x, text_y), text, self.TEXT_COLOR_LARGE, anchor="mm", stroke_width=0, font=font, align="center")
|
||||
return img
|
||||
|
||||
img = create_textbox(message, your_language)
|
||||
if len(translation) > 0 and target_language is not None:
|
||||
translation_img = create_textbox(translation, target_language)
|
||||
translation_img = self.create_textbox_short(translation, target_language, text_color, width, height, font_size)
|
||||
img = self.concatenate_images_vertically(img, translation_img)
|
||||
|
||||
width, height = img.size
|
||||
background = Image.new("RGBA", (width, height), (0, 0, 0, 0))
|
||||
background = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
||||
draw = ImageDraw.Draw(background)
|
||||
draw.rounded_rectangle([(0, 0), (width, height)], radius=30, fill=self.BACKGROUND_COLOR, outline=self.BACKGROUND_COLOR, width=5)
|
||||
draw.rounded_rectangle([(0, 0), img.size], radius=30, fill=background_color, outline=background_outline_color, width=5)
|
||||
|
||||
decoration_image = self.create_decoration_image(ui_type, img.size)
|
||||
background = Image.alpha_composite(background, decoration_image)
|
||||
img = Image.alpha_composite(background, img)
|
||||
return img
|
||||
@@ -12,6 +12,7 @@ transformers[torch]==4.37.2
|
||||
sentencepiece==0.1.99
|
||||
ctranslate2==3.24.0
|
||||
faster-whisper==0.10.0
|
||||
openvr==1.26.701
|
||||
translators @ git+https://github.com/misyaguziya/translators@5.8.9
|
||||
SpeechRecognition @ git+https://github.com/misyaguziya/custom_speech_recognition@3.10.2
|
||||
tinyoscquery @ git+https://github.com/cyberkitsune/tinyoscquery@0.1.2
|
||||
Reference in New Issue
Block a user