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" } ] },