From 7d74fca176552199bf8051a7e8f6c3c2f6146272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Wed, 7 Aug 2024 23:18:45 +0800 Subject: [PATCH] except --- .../LunaTranslator/tts/vitsSimpleAPI.py | 2 - .../LunaTranslator/tts/voiceroid2.py | 7 +- LunaTranslator/LunaTranslator/tts/voicevox.py | 70 +++++++++---------- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/LunaTranslator/LunaTranslator/tts/vitsSimpleAPI.py b/LunaTranslator/LunaTranslator/tts/vitsSimpleAPI.py index 8481366b..26b872bd 100644 --- a/LunaTranslator/LunaTranslator/tts/vitsSimpleAPI.py +++ b/LunaTranslator/LunaTranslator/tts/vitsSimpleAPI.py @@ -6,8 +6,6 @@ from urllib.parse import quote class TTS(TTSbase): def getvoicelist(self): - if self.config["voices"] == "": - return [(0, 0, 0)], [] responseVits = requests.get( urljoin(self.config["URL"], self.config["voices"]) ).json() diff --git a/LunaTranslator/LunaTranslator/tts/voiceroid2.py b/LunaTranslator/LunaTranslator/tts/voiceroid2.py index 1a58a30c..18cf59b9 100644 --- a/LunaTranslator/LunaTranslator/tts/voiceroid2.py +++ b/LunaTranslator/LunaTranslator/tts/voiceroid2.py @@ -9,9 +9,10 @@ from myutils.subproc import subproc_w, autoproc class TTS(TTSbase): def getvoicelist(self): voicelist = [] - if os.path.exists(self.config["path"]) == False: - return [] - l = os.listdir(os.path.join(self.config["path"], "Voice")) + _p = os.path.join(self.config["path"], "Voice") + if os.path.exists(_p) == False: + raise Exception(f"not exists {_p}") + l = os.listdir(_p) for _ in l: if "_" in _: diff --git a/LunaTranslator/LunaTranslator/tts/voicevox.py b/LunaTranslator/LunaTranslator/tts/voicevox.py index c9f94080..ac217b65 100644 --- a/LunaTranslator/LunaTranslator/tts/voicevox.py +++ b/LunaTranslator/LunaTranslator/tts/voicevox.py @@ -7,46 +7,40 @@ from tts.basettsclass import TTSbase class TTS(TTSbase): def getvoicelist(self): - while True: - try: - headers = { - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", - "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", - "Cache-Control": "no-cache", - "Connection": "keep-alive", - "Pragma": "no-cache", - "Sec-Fetch-Dest": "document", - "Sec-Fetch-Mode": "navigate", - "Sec-Fetch-Site": "none", - "Sec-Fetch-User": "?1", - "Upgrade-Insecure-Requests": "1", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52", - "sec-ch-ua": '"Chromium";v="106", "Microsoft Edge";v="106", "Not;A=Brand";v="99"', - "sec-ch-ua-mobile": "?0", - "sec-ch-ua-platform": '"Windows"', - } + headers = { + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", + "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", + "Cache-Control": "no-cache", + "Connection": "keep-alive", + "Pragma": "no-cache", + "Sec-Fetch-Dest": "document", + "Sec-Fetch-Mode": "navigate", + "Sec-Fetch-Site": "none", + "Sec-Fetch-User": "?1", + "Upgrade-Insecure-Requests": "1", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52", + "sec-ch-ua": '"Chromium";v="106", "Microsoft Edge";v="106", "Not;A=Brand";v="99"', + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": '"Windows"', + } - response = requests.get( - f"http://127.0.0.1:{self.config['Port']}/speakers", - headers=headers, - proxies={"http": None, "https": None}, - ).json() - print(response) - vis=[] - idxs=[] - for speaker in response: - name=speaker['name'] - styles = speaker["styles"] - for style in styles: - idxs.append(style['id']) - vis.append(name+ ' '+ style["name"]) - - return idxs, vis - except: - print_exc() - time.sleep(1) - break + response = requests.get( + f"http://127.0.0.1:{self.config['Port']}/speakers", + headers=headers, + proxies={"http": None, "https": None}, + ).json() + print(response) + vis = [] + idxs = [] + for speaker in response: + name = speaker["name"] + styles = speaker["styles"] + for style in styles: + idxs.append(style["id"]) + vis.append(name + " " + style["name"]) + + return idxs, vis def speak(self, content, rate, voice): headers = {