File size: 1,479 Bytes
446c342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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()