👍️[Update] All : 不要なprintLogを削除 / なるべくtry exceptした場合にはerrorLogを保存するように変更

This commit is contained in:
misyaguziya
2024-12-16 23:38:05 +09:00
parent 030b8a9f01
commit 3fa819df3f
14 changed files with 73 additions and 67 deletions

View File

@@ -7,6 +7,7 @@ from tinyoscquery.queryservice import OSCQueryService
from tinyoscquery.query import OSCQueryBrowser, OSCQueryClient
from tinyoscquery.utility import get_open_udp_port, get_open_tcp_port
from tinyoscquery.shared.node import OSCAccess
from utils import errorLogging
class OSCHandler:
def __init__(self, ip_address="127.0.0.1", port=9000) -> None:
@@ -55,7 +56,7 @@ class OSCHandler:
browser.browser.cancel()
except Exception:
pass
errorLogging()
return value
def getOSCParameterMuteSelf(self) -> bool:
@@ -77,6 +78,7 @@ class OSCHandler:
self.osc_query_service.advertise_endpoint(filter, access=OSCAccess.READWRITE_VALUE)
break
except Exception:
errorLogging()
sleep(1)
def oscServerServe(self) -> None:

View File

@@ -10,11 +10,7 @@ try:
from . import overlay_utils as utils
except ImportError:
import overlay_utils as utils
try:
from utils import printLog
except ImportError:
def printLog(*args):
print(*args)
from utils import errorLogging
def mat34Id(array):
arr = openvr.HmdMatrix34_t()
@@ -114,8 +110,8 @@ class Overlay:
self.updateFadeoutDuration(self.settings[size]["fadeout_duration"], size)
self.init_process = False
except Exception as e:
printLog("error:Could not initialise OpenVR", e)
except Exception:
errorLogging()
def updateImage(self, img, size):
if self.initialized is True:
@@ -125,8 +121,8 @@ class Overlay:
try:
self.overlay.setOverlayRaw(self.handle[size], img, width, height, 4)
except Exception as e:
printLog("error:Could not update image", e)
except Exception:
errorLogging()
self.initialized = False
self.reStartOverlay()
while self.initialized is False:
@@ -217,8 +213,8 @@ class Overlay:
if new_event.eventType == openvr.VREvent_Quit:
return False
return True
except Exception as e:
printLog("error:Could not check SteamVR running", e)
except Exception:
errorLogging()
return False
def evaluateOpacityFade(self, size):
@@ -344,9 +340,11 @@ if __name__ == "__main__":
overlay.updateImage(img, "small")
time.sleep(15)
except openvr.error_code.OverlayError_InvalidParameter as e:
errorLogging()
logging.error(f"OverlayError_InvalidParameter: {e}")
break
except Exception as e:
errorLogging()
logging.error(f"Unexpected error: {e}")
break

View File

@@ -2,6 +2,7 @@ from os import path as os_path
from datetime import datetime
from typing import Tuple
from PIL import Image, ImageDraw, ImageFont
from utils import errorLogging
class OverlayImage:
LANGUAGES = {
@@ -56,6 +57,7 @@ class OverlayImage:
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
font = ImageFont.truetype(font_path, font_size)
except Exception:
errorLogging()
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
font = ImageFont.truetype(font_path, font_size)
@@ -133,6 +135,7 @@ class OverlayImage:
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf")
font = ImageFont.truetype(font_path, font_size)
except Exception:
errorLogging()
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf")
font = ImageFont.truetype(font_path, font_size)
@@ -167,6 +170,7 @@ class OverlayImage:
font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf")
font = ImageFont.truetype(font_path, font_size)
except Exception:
errorLogging()
font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf")
font = ImageFont.truetype(font_path, font_size)

View File

@@ -3,6 +3,7 @@ from io import BytesIO
from threading import Event
import wave
from speech_recognition import Recognizer, AudioData, AudioFile
from speech_recognition.exceptions import UnknownValueError
from datetime import timedelta
from pyaudiowpatch import get_sample_size, paInt16
from .transcription_languages import transcription_lang
@@ -11,6 +12,8 @@ from .transcription_whisper import getWhisperModel, checkWhisperWeight
import torch
import numpy as np
from pydub import AudioSegment
from utils import errorLogging
import warnings
warnings.simplefilter('ignore', RuntimeWarning)
@@ -74,9 +77,10 @@ class AudioTranscriber:
if s.avg_logprob < avg_logprob or s.no_speech_prob > no_speech_prob:
continue
text += s.text
except Exception:
except UnknownValueError:
pass
except Exception:
errorLogging()
finally:
pass

View File

@@ -4,7 +4,6 @@ from typing import Callable
import huggingface_hub
from faster_whisper import WhisperModel
import logging
from utils import printLog
logger = logging.getLogger('faster_whisper')
logger.setLevel(logging.CRITICAL)
@@ -40,10 +39,8 @@ def downloadFile(url, path, func=None):
if isinstance(func, Callable):
total_chunk += len(chunk)
func(total_chunk/file_size)
printLog(f"Downloading Whisper Model: {total_chunk/file_size:.0%}")
except Exception as e:
printLog("warning:downloadFile()", e)
except Exception:
pass
def checkWhisperWeight(root, weight_type):
path = os_path.join(root, "weights", "whisper", weight_type)

View File

@@ -6,7 +6,7 @@ from .translation_utils import ctranslate2_weights
import ctranslate2
import transformers
from utils import printLog
from utils import errorLogging
import warnings
warnings.filterwarnings("ignore")
@@ -25,6 +25,7 @@ class Translator():
self.deepl_client = deepl_Translator(authkey)
self.deepl_client.translate_text(" ", target_lang="EN-US")
except Exception:
errorLogging()
self.deepl_client = None
result = False
return result
@@ -47,8 +48,8 @@ class Translator():
)
try:
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
except Exception as e:
printLog("error:changeCTranslate2Model()", e)
except Exception:
errorLogging()
tokenizer_path = os_path.join("./weights", "ctranslate2", directory_name, "tokenizer")
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
self.is_loaded_ctranslate2_model = True
@@ -67,7 +68,7 @@ class Translator():
target = results[0].hypotheses[0][1:]
result = self.ctranslate2_tokenizer.decode(self.ctranslate2_tokenizer.convert_tokens_to_ids(target))
except Exception:
pass
errorLogging()
return result
@staticmethod
@@ -138,8 +139,7 @@ class Translator():
source_language=source_language,
target_language=target_language,
)
except Exception as e:
from utils import errorLogging
errorLogging(e)
except Exception:
errorLogging()
result = False
return result

View File

@@ -5,7 +5,7 @@ from os import makedirs as os_makedirs
from requests import get as requests_get
from typing import Callable
import hashlib
from utils import printLog
from utils import errorLogging
ctranslate2_weights = {
"small": { # M2M-100 418M-parameter model
@@ -79,12 +79,11 @@ def downloadCTranslate2Weight(root, weight_type="small", callback=None, end_call
if isinstance(callback, Callable):
total_chunk += len(chunk)
callback(total_chunk/file_size)
printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}")
with ZipFile(os_path.join(tmp_path, filename)) as zf:
zf.extractall(path)
except Exception as e:
printLog("warning:downloadCTranslate2Weight()", e)
except Exception:
errorLogging()
if isinstance(end_callback, Callable):
end_callback()

View File

@@ -1,6 +1,5 @@
from typing import Callable
import time
from utils import printLog
class Watchdog:
def __init__(self, timeout:int=60, interval:int=20):
@@ -16,7 +15,6 @@ class Watchdog:
def start(self):
if time.time() - self.last_feed_time > self.timeout:
printLog("Watchdog timeout! Shutting down...")
if isinstance(self.callback, Callable):
self.callback()
time.sleep(self.interval)