From 579cb627e655c5a2a2c2025800f3688302ad1dae Mon Sep 17 00:00:00 2001 From: "Mr.Raindrop" <53202747+raindrop213@users.noreply.github.com> Date: Sun, 10 Mar 2024 11:48:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=AD=E9=9F=B3=E5=90=88?= =?UTF-8?q?=E6=88=90=20vits-simple-api=20(#568)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LunaTranslator/tts/vitsSimpleAPI.py | 35 +++++++++++++++++++ .../files/defaultconfig/config.json | 5 +++ .../files/defaultconfig/static_data.json | 12 +++++++ 3 files changed, 52 insertions(+) create mode 100644 LunaTranslator/LunaTranslator/tts/vitsSimpleAPI.py diff --git a/LunaTranslator/LunaTranslator/tts/vitsSimpleAPI.py b/LunaTranslator/LunaTranslator/tts/vitsSimpleAPI.py new file mode 100644 index 00000000..d9549cde --- /dev/null +++ b/LunaTranslator/LunaTranslator/tts/vitsSimpleAPI.py @@ -0,0 +1,35 @@ +from traceback import print_exc +import requests +from myutils.config import globalconfig +import time +from tts.basettsclass import TTSbase +from urllib.parse import quote + +class TTS(TTSbase): + def getvoicelist(self): + responseVits = requests.get('http://127.0.0.1:23456/voice/speakers').json() + self.voicelist = [] + + # 获取所有模型类型,对于每个模型类型下的模型信息,将其 modelType、id、name 合成一个字符串 + modelTypes = responseVits.keys() + for modelType in modelTypes: + vits_data = responseVits[modelType] + for item in vits_data: + model_info = f'{modelType}_{item["id"]}_{item["name"]}' + self.voicelist.append(model_info) + return self.voicelist + + def voiceshowmap(self,voice): + return voice + + def speak(self, content, rate, voice, voiceidx): + encoded_content = quote(content) + idx = int(voice.split('_')[1]) + model = str.lower(voice.split('_')[0]) + response = requests.get(f"http://127.0.0.1:23456/voice/{model}?text={encoded_content}&id={idx}&lang=ja&format=wav").content + fname = str(time.time()) + with open('./cache/tts/'+fname+'.wav', 'wb') as ff: + ff.write(response) + + return ('./cache/tts/'+fname+'.wav') + diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 8386ca2c..e47d963e 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -607,6 +607,11 @@ "voice": "", "path": "", "name": "VOICEVOX" + }, + "vitsSimpleAPI": { + "use": false, + "voice": "", + "name": "vits-simple-api" } }, "hirasetting": { diff --git a/LunaTranslator/files/defaultconfig/static_data.json b/LunaTranslator/files/defaultconfig/static_data.json index 8e0df291..9d498e58 100644 --- a/LunaTranslator/files/defaultconfig/static_data.json +++ b/LunaTranslator/files/defaultconfig/static_data.json @@ -231,6 +231,18 @@ { "name": "VoiceRoid2_附加音源_ギャラ子", "link": "https://github.com/HIllya51/RESOURCES/releases/download/install_free_voice_packages/galaco_44.zip" + }, + { + "name": "vits-simple-api", + "link": "https://github.com/Artrajz/vits-simple-api/releases" + }, + { + "name": "vits-simple-api_CPU版附模型vits-uma-genshin-honkai", + "link": "https://github.com/raindrop213/LunaTranslator-re/releases/download/v0.0.1/vits-simple-api-windows-cpu-v0.6.9_vits-uma-genshin-honkai.rar" + }, + { + "name": "vits-simple-api_GPU版附模型vits-uma-genshin-honkai", + "link": "https://github.com/raindrop213/LunaTranslator-re/releases/download/v0.0.1/vits-simple-api-windows-gpu-v0.6.9_vits-uma-genshin-honkai.7z" } ] },