This commit is contained in:
恍兮惚兮 2024-08-07 23:18:45 +08:00
parent e8d6776229
commit 7d74fca176
3 changed files with 36 additions and 43 deletions

View File

@ -6,8 +6,6 @@ from urllib.parse import quote
class TTS(TTSbase): class TTS(TTSbase):
def getvoicelist(self): def getvoicelist(self):
if self.config["voices"] == "":
return [(0, 0, 0)], []
responseVits = requests.get( responseVits = requests.get(
urljoin(self.config["URL"], self.config["voices"]) urljoin(self.config["URL"], self.config["voices"])
).json() ).json()

View File

@ -9,9 +9,10 @@ from myutils.subproc import subproc_w, autoproc
class TTS(TTSbase): class TTS(TTSbase):
def getvoicelist(self): def getvoicelist(self):
voicelist = [] voicelist = []
if os.path.exists(self.config["path"]) == False: _p = os.path.join(self.config["path"], "Voice")
return [] if os.path.exists(_p) == False:
l = os.listdir(os.path.join(self.config["path"], "Voice")) raise Exception(f"not exists {_p}")
l = os.listdir(_p)
for _ in l: for _ in l:
if "_" in _: if "_" in _:

View File

@ -7,46 +7,40 @@ from tts.basettsclass import TTSbase
class TTS(TTSbase): class TTS(TTSbase):
def getvoicelist(self): def getvoicelist(self):
while True:
try:
headers = { 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": "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", "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", "Cache-Control": "no-cache",
"Connection": "keep-alive", "Connection": "keep-alive",
"Pragma": "no-cache", "Pragma": "no-cache",
"Sec-Fetch-Dest": "document", "Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate", "Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none", "Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1", "Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "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", "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": '"Chromium";v="106", "Microsoft Edge";v="106", "Not;A=Brand";v="99"',
"sec-ch-ua-mobile": "?0", "sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"', "sec-ch-ua-platform": '"Windows"',
} }
response = requests.get( response = requests.get(
f"http://127.0.0.1:{self.config['Port']}/speakers", f"http://127.0.0.1:{self.config['Port']}/speakers",
headers=headers, headers=headers,
proxies={"http": None, "https": None}, proxies={"http": None, "https": None},
).json() ).json()
print(response) print(response)
vis=[] vis = []
idxs=[] idxs = []
for speaker in response: for speaker in response:
name=speaker['name'] name = speaker["name"]
styles = speaker["styles"] styles = speaker["styles"]
for style in styles: for style in styles:
idxs.append(style['id']) idxs.append(style["id"])
vis.append(name+ ' '+ style["name"]) vis.append(name + " " + style["name"])
return idxs, vis return idxs, vis
except:
print_exc()
time.sleep(1)
break
def speak(self, content, rate, voice): def speak(self, content, rate, voice):
headers = { headers = {