Spaces:
Runtime error
Runtime error
import io | |
import json | |
import requests | |
from pydub import AudioSegment | |
from .tts_utils import mix_background_music | |
def infer(token, appid, speaker, text, sdp, noise, noisew, length, 背景音乐, speaker_up, back_up): | |
try: | |
speed = (100 - length) / 100 | |
headers = {'Content-Type': 'application/json'} | |
infer_info = {'lang': 'zh', 'appid': appid, 'token': token, 'speaker': speaker, 'text': text, | |
'sdp_ratio': sdp, 'noise': noise, 'noisew': noisew, 'length': speed} | |
resp = requests.post(url=f"{genshin_api}/api/ex/vits", headers=headers, | |
data=json.dumps(infer_info)) | |
data = json.loads(resp.text) | |
wmv_file = requests.get(data["audio"]).content | |
original_audio = AudioSegment.from_wav(io.BytesIO(wmv_file)) | |
return data["message"].replace("\\n", "\n"), *mix_background_music(original_audio, 背景音乐, speaker_up, | |
back_up) | |
except Exception as e: | |
return str(e), None, None | |
def get_spk(): | |
resp = requests.get(url=f"{genshin_api}/spklist/spks.json") | |
data = json.loads(resp.text) | |
return data | |
def search_speaker(search_value): | |
for s in speakers_genshin: | |
if search_value == s: | |
return s | |
for s in speakers_genshin: | |
if search_value in s: | |
return s | |
genshin_api = "https://tirs.ai-lab.top" | |
speakers_genshin = get_spk() | |