RVC-Boss / GPT-SoVITS

1 min voice data can also be used to train a good TTS model! (few shot voice cloning)
MIT License
32.54k stars 3.75k forks source link

引用GPT-SoVITS的api动态切换模型 #1140

Open AiDreamerOoO opened 3 months ago

AiDreamerOoO commented 3 months ago

在使用GPT-SoVITS的api时,可以实现动态切换模型嘛?大佬能添加一下这个功能么

liudiao1992 commented 3 months ago

from TTS_infer_pack.TTS import TTS, TTS_Config

tts_config = TTS_Config("GPT_FVoice/configs/tts_infer.yaml") tts_config.device = device tts_config.is_half = is_half tts_pipline = TTS(tts_config)

def inference_api(gpt_path, sovits_path,text, text_lang, ref_audio_path, prompt_text, prompt_lang, top_k, top_p, temperature, text_split_method, batch_size, speed_factor, volume_factor, ref_text_free, split_bucket,fragment_interval, ): global tts_pipline if tts_config.t2s_weights_path != gpt_path and tts_config.vits_weights_path != sovits_path: tts_config.t2s_weights_path = gpt_path tts_config.vits_weights_path = sovits_path tts_pipline = TTS(tts_config) inputs={ "text": text, "text_lang": dict_language[text_lang], "ref_audio_path": ref_audio_path, "prompt_text": prompt_text if not ref_text_free else "", "prompt_lang": dict_language[prompt_lang], "top_k": top_k, "top_p": top_p, "temperature": temperature, "text_split_method": cut_method[text_split_method], "batch_size":int(batch_size), "speed_factor":float(speed_factor), "volume_factor": float(volume_factor), "split_bucket":split_bucket, "return_fragment":False, "fragment_interval":fragment_interval, }

yield next(tts_pipline.run(inputs))

我是这么做的

KevinZhang19870314 commented 3 months ago

在使用GPT-SoVITS的api时,可以实现动态切换模型嘛?大佬能添加一下这个功能么

看一下fast_inference_的api_v3.py,每次传入不同的yaml文件路径tts_infer_yaml_path

Separatee commented 3 months ago

根据你的描述,你可能没有使用fast_inference分支。切换到该分支能获得更快的速度。 对于Linux你需要使用以下命令: wget https://github.com/RVC-Boss/GPT-SoVITS/archive/refs/heads/fast_inference_.zip 或者直接访问,下载压缩包,解压内部文件到你的目录(全部覆盖) 这样你便能看到api_v2.py.这里比api.py不同的是增加了很多注释详细解释了功能,不再言。

按照你通常使用python的方式运行(比如整合包用python路径 -m pip install) pip install wordsegment 使用Windows的话,创建一个bat脚本用于快速启动api_v2。例如:

python api_v2.py
pause

双击即可bat运行。此外,api_v2为开发者带来更多可能性,比如批量处理srt文件

younger027 commented 3 months ago

根据你的描述,你可能没有使用fast_inference分支。切换到该分支能获得更快的速度。 对于Linux你需要使用以下命令: wget https://github.com/RVC-Boss/GPT-SoVITS/archive/refs/heads/fast_inference_.zip 或者直接访问,下载压缩包,解压内部文件到你的目录(全部覆盖) 这样你便能看到api_v2.py.这里比api.py不同的是增加了很多注释详细解释了功能,不再言。

按照你通常使用python的方式运行(比如整合包用python路径 -m pip install) pip install wordsegment 使用Windows的话,创建一个bat脚本用于快速启动api_v2。例如:

python api_v2.py
pause

双击即可bat运行。此外,api_v2为开发者带来更多可能性,比如批量处理srt文件

请问这个"批量处理srt文件这个功能",目前可以用吗?

Separatee commented 3 months ago

根据你的描述,你可能没有使用fast_inference分支。切换到该分支能获得更快的速度。 对于Linux你需要使用以下命令: wget https://github.com/RVC-Boss/GPT-SoVITS/archive/refs/heads/fast_inference_.zip 或者直接访问,下载压缩包,解压内部文件到你的目录(全部覆盖) 这样你便能看到api_v2.py.这里比api.py不同的是增加了很多注释详细解释了功能,不再言。 按照你通常使用python的方式运行(比如整合包用python路径 -m pip install) pip install wordsegment 使用Windows的话,创建一个bat脚本用于快速启动api_v2。例如:

python api_v2.py
pause

双击即可bat运行。此外,api_v2为开发者带来更多可能性,比如批量处理srt文件

请问这个"批量处理srt文件这个功能",目前可以用吗?

当然,蓝色的是超链接,点开就会跳转到对应仓库

HaxxorCialtion commented 2 months ago
import requests
import urllib.parse

audio_directory = "./"

def generate_audio(response, name, output_name):
    global audio_directory

    # 切换模型
    gpt_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\GPT_weights\mizuki-e15.ckpt"
    sovits_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\SoVITS_weights\mizuki_e8_s128.pth"

    url_gpt = "http://127.0.0.1:9880/set_gpt_weights"
    url_sovits = "http://127.0.0.1:9880/set_sovits_weights"
    params_gpt = {
        "weights_path": gpt_model_path
    }
    params_sovits = {
        "weights_path": sovits_model_path
    }

    try:
        response_gpt = requests.get(url_gpt, params=params_gpt)
        response_gpt.raise_for_status()  # 检查请求是否成功
        print("GPT weights set successfully:", response_gpt.json())
    except requests.exceptions.RequestException as e:
        print("Error setting GPT weights:", e)

    try:
        response_sovits = requests.get(url_sovits, params=params_sovits)
        response_sovits.raise_for_status()  # 检查请求是否成功
        print("SoVITS weights set successfully:", response_sovits.json())
    except requests.exceptions.RequestException as e:
        print("Error setting SoVITS weights:", e)

    # 输出音频
    # 定义音频文件路径
    wav_paths = {
        1: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\mizuki0.wav",
        2: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\herta0.wav",
        3: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\griso0.wav",
        4: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\bronya0.wav",
        5: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\miu0.wav"
    }

    # 定义角色对应的文本
    prompt_texts = {
        1: "要吸收和消化掉这些对吧?我会努力的!",
        2: "你也不愿意因为自己身体里埋了一颗星核,祸害空间站这么多人吧?",
        3: "不小心弄脏了,你会怪我吗?",
        4: "再这样下去,bronya的神经中枢,会坏掉的。",
        5: "我的润唇膏给你吧!之后买一支还给我就行。"
    }

    def generate_url(name, response):
        base_url = "http://127.0.0.1:9880/"
        if name in wav_paths:
            wav_path = wav_paths[name]
            prompt_text = prompt_texts[name]
        else:
            wav_path = wav_paths[1]
            prompt_text = prompt_texts[1]

        params = {
            "text": response,
            "text_lang": "zh",
            "ref_audio_path": wav_path,
            "prompt_lang": "zh",
            "prompt_text": prompt_text,
            "text_split_method": "cut5",
            "batch_size": 1,
            "media_type": "wav",
            "streaming_mode": "true"
        }

        encoded_params = urllib.parse.urlencode(params, safe='./')
        url = f"{base_url}?{encoded_params}"
        return url

    def get_audio(name, response, audio_directory, output_name):
        url = generate_url(name, response)
        try:
            response = requests.get(url)
            response.raise_for_status()
            output_path = rf'{audio_directory}\{output_name}.wav'
            with open(output_path, 'wb') as file:
                file.write(response.content)
            print(f"Audio saved to {output_path}")
        except requests.exceptions.RequestException as e:
            print("语音错误", e)

    # 调用生成音频
    get_audio(name, response, audio_directory, output_name)

# 示例调用
name = 1  # 角色ID
response = "你好, 定义了角色对应的音频文件路径和文本。"  # 文本
output_name = "output_audio"
generate_audio(response, name, output_name)

You can just modify this script especially for some endpoints and paths. Forgive me for using English, it's my first time to answer questions in github and I just want to mark it!

wanglongpeng1 commented 2 months ago
import requests
import urllib.parse

audio_directory = "./"

def generate_audio(response, name, output_name):
    global audio_directory

    # 切换模型
    gpt_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\GPT_weights\mizuki-e15.ckpt"
    sovits_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\SoVITS_weights\mizuki_e8_s128.pth"

    url_gpt = "http://127.0.0.1:9880/set_gpt_weights"
    url_sovits = "http://127.0.0.1:9880/set_sovits_weights"
    params_gpt = {
        "weights_path": gpt_model_path
    }
    params_sovits = {
        "weights_path": sovits_model_path
    }

    try:
        response_gpt = requests.get(url_gpt, params=params_gpt)
        response_gpt.raise_for_status()  # 检查请求是否成功
        print("GPT weights set successfully:", response_gpt.json())
    except requests.exceptions.RequestException as e:
        print("Error setting GPT weights:", e)

    try:
        response_sovits = requests.get(url_sovits, params=params_sovits)
        response_sovits.raise_for_status()  # 检查请求是否成功
        print("SoVITS weights set successfully:", response_sovits.json())
    except requests.exceptions.RequestException as e:
        print("Error setting SoVITS weights:", e)

    # 输出音频
    # 定义音频文件路径
    wav_paths = {
        1: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\mizuki0.wav",
        2: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\herta0.wav",
        3: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\griso0.wav",
        4: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\bronya0.wav",
        5: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\miu0.wav"
    }

    # 定义角色对应的文本
    prompt_texts = {
        1: "要吸收和消化掉这些对吧?我会努力的!",
        2: "你也不愿意因为自己身体里埋了一颗星核,祸害空间站这么多人吧?",
        3: "不小心弄脏了,你会怪我吗?",
        4: "再这样下去,bronya的神经中枢,会坏掉的。",
        5: "我的润唇膏给你吧!之后买一支还给我就行。"
    }

    def generate_url(name, response):
        base_url = "http://127.0.0.1:9880/"
        if name in wav_paths:
            wav_path = wav_paths[name]
            prompt_text = prompt_texts[name]
        else:
            wav_path = wav_paths[1]
            prompt_text = prompt_texts[1]

        params = {
            "text": response,
            "text_lang": "zh",
            "ref_audio_path": wav_path,
            "prompt_lang": "zh",
            "prompt_text": prompt_text,
            "text_split_method": "cut5",
            "batch_size": 1,
            "media_type": "wav",
            "streaming_mode": "true"
        }

        encoded_params = urllib.parse.urlencode(params, safe='./')
        url = f"{base_url}?{encoded_params}"
        return url

    def get_audio(name, response, audio_directory, output_name):
        url = generate_url(name, response)
        try:
            response = requests.get(url)
            response.raise_for_status()
            output_path = rf'{audio_directory}\{output_name}.wav'
            with open(output_path, 'wb') as file:
                file.write(response.content)
            print(f"Audio saved to {output_path}")
        except requests.exceptions.RequestException as e:
            print("语音错误", e)

    # 调用生成音频
    get_audio(name, response, audio_directory, output_name)

# 示例调用
name = 1  # 角色ID
response = "你好, 定义了角色对应的音频文件路径和文本。"  # 文本
output_name = "output_audio"
generate_audio(response, name, output_name)

You can just modify this script especially for some endpoints and paths. Forgive me for using English, it's my first time to answer questions in github and I just want to mark it!

您好,没看到api接口中有关于 url_gpt = "http://127.0.0.1:9880/set_gpt_weights" url_sovits = "http://127.0.0.1:9880/set_sovits_weights" set_gpt_weights和set_sovits_weights 能提供一下吗? Hello, I didn't see in the API.py interface that url_gpt = "http://127.0.0.1:9880/set_gpt_weights" and url_sovits = "http://127.0.0.1:9880/set_sovits_weights". Can you provide set_gpt_weights and set_sovits_weights?

XXXXRT666 commented 2 months ago
import requests
import urllib.parse

audio_directory = "./"

def generate_audio(response, name, output_name):
    global audio_directory

    # 切换模型
    gpt_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\GPT_weights\mizuki-e15.ckpt"
    sovits_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\SoVITS_weights\mizuki_e8_s128.pth"

    url_gpt = "http://127.0.0.1:9880/set_gpt_weights"
    url_sovits = "http://127.0.0.1:9880/set_sovits_weights"
    params_gpt = {
        "weights_path": gpt_model_path
    }
    params_sovits = {
        "weights_path": sovits_model_path
    }

    try:
        response_gpt = requests.get(url_gpt, params=params_gpt)
        response_gpt.raise_for_status()  # 检查请求是否成功
        print("GPT weights set successfully:", response_gpt.json())
    except requests.exceptions.RequestException as e:
        print("Error setting GPT weights:", e)

    try:
        response_sovits = requests.get(url_sovits, params=params_sovits)
        response_sovits.raise_for_status()  # 检查请求是否成功
        print("SoVITS weights set successfully:", response_sovits.json())
    except requests.exceptions.RequestException as e:
        print("Error setting SoVITS weights:", e)

    # 输出音频
    # 定义音频文件路径
    wav_paths = {
        1: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\mizuki0.wav",
        2: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\herta0.wav",
        3: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\griso0.wav",
        4: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\bronya0.wav",
        5: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\miu0.wav"
    }

    # 定义角色对应的文本
    prompt_texts = {
        1: "要吸收和消化掉这些对吧?我会努力的!",
        2: "你也不愿意因为自己身体里埋了一颗星核,祸害空间站这么多人吧?",
        3: "不小心弄脏了,你会怪我吗?",
        4: "再这样下去,bronya的神经中枢,会坏掉的。",
        5: "我的润唇膏给你吧!之后买一支还给我就行。"
    }

    def generate_url(name, response):
        base_url = "http://127.0.0.1:9880/"
        if name in wav_paths:
            wav_path = wav_paths[name]
            prompt_text = prompt_texts[name]
        else:
            wav_path = wav_paths[1]
            prompt_text = prompt_texts[1]

        params = {
            "text": response,
            "text_lang": "zh",
            "ref_audio_path": wav_path,
            "prompt_lang": "zh",
            "prompt_text": prompt_text,
            "text_split_method": "cut5",
            "batch_size": 1,
            "media_type": "wav",
            "streaming_mode": "true"
        }

        encoded_params = urllib.parse.urlencode(params, safe='./')
        url = f"{base_url}?{encoded_params}"
        return url

    def get_audio(name, response, audio_directory, output_name):
        url = generate_url(name, response)
        try:
            response = requests.get(url)
            response.raise_for_status()
            output_path = rf'{audio_directory}\{output_name}.wav'
            with open(output_path, 'wb') as file:
                file.write(response.content)
            print(f"Audio saved to {output_path}")
        except requests.exceptions.RequestException as e:
            print("语音错误", e)

    # 调用生成音频
    get_audio(name, response, audio_directory, output_name)

# 示例调用
name = 1  # 角色ID
response = "你好, 定义了角色对应的音频文件路径和文本。"  # 文本
output_name = "output_audio"
generate_audio(response, name, output_name)

You can just modify this script especially for some endpoints and paths. Forgive me for using English, it's my first time to answer questions in github and I just want to mark it!

您好,没看到api接口中有关于 url_gpt = "http://127.0.0.1:9880/set_gpt_weights" url_sovits = "http://127.0.0.1:9880/set_sovits_weights" set_gpt_weights和set_sovits_weights 能提供一下吗? Hello, I didn't see in the API.py interface that url_gpt = "http://127.0.0.1:9880/set_gpt_weights" and url_sovits = "http://127.0.0.1:9880/set_sovits_weights". Can you provide set_gpt_weights and set_sovits_weights?

这是main的api

wanglongpeng1 commented 2 months ago
import requests
import urllib.parse

audio_directory = "./"

def generate_audio(response, name, output_name):
    global audio_directory

    # 切换模型
    gpt_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\GPT_weights\mizuki-e15.ckpt"
    sovits_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\SoVITS_weights\mizuki_e8_s128.pth"

    url_gpt = "http://127.0.0.1:9880/set_gpt_weights"
    url_sovits = "http://127.0.0.1:9880/set_sovits_weights"
    params_gpt = {
        "weights_path": gpt_model_path
    }
    params_sovits = {
        "weights_path": sovits_model_path
    }

    try:
        response_gpt = requests.get(url_gpt, params=params_gpt)
        response_gpt.raise_for_status()  # 检查请求是否成功
        print("GPT weights set successfully:", response_gpt.json())
    except requests.exceptions.RequestException as e:
        print("Error setting GPT weights:", e)

    try:
        response_sovits = requests.get(url_sovits, params=params_sovits)
        response_sovits.raise_for_status()  # 检查请求是否成功
        print("SoVITS weights set successfully:", response_sovits.json())
    except requests.exceptions.RequestException as e:
        print("Error setting SoVITS weights:", e)

    # 输出音频
    # 定义音频文件路径
    wav_paths = {
        1: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\mizuki0.wav",
        2: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\herta0.wav",
        3: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\griso0.wav",
        4: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\bronya0.wav",
        5: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\miu0.wav"
    }

    # 定义角色对应的文本
    prompt_texts = {
        1: "要吸收和消化掉这些对吧?我会努力的!",
        2: "你也不愿意因为自己身体里埋了一颗星核,祸害空间站这么多人吧?",
        3: "不小心弄脏了,你会怪我吗?",
        4: "再这样下去,bronya的神经中枢,会坏掉的。",
        5: "我的润唇膏给你吧!之后买一支还给我就行。"
    }

    def generate_url(name, response):
        base_url = "http://127.0.0.1:9880/"
        if name in wav_paths:
            wav_path = wav_paths[name]
            prompt_text = prompt_texts[name]
        else:
            wav_path = wav_paths[1]
            prompt_text = prompt_texts[1]

        params = {
            "text": response,
            "text_lang": "zh",
            "ref_audio_path": wav_path,
            "prompt_lang": "zh",
            "prompt_text": prompt_text,
            "text_split_method": "cut5",
            "batch_size": 1,
            "media_type": "wav",
            "streaming_mode": "true"
        }

        encoded_params = urllib.parse.urlencode(params, safe='./')
        url = f"{base_url}?{encoded_params}"
        return url

    def get_audio(name, response, audio_directory, output_name):
        url = generate_url(name, response)
        try:
            response = requests.get(url)
            response.raise_for_status()
            output_path = rf'{audio_directory}\{output_name}.wav'
            with open(output_path, 'wb') as file:
                file.write(response.content)
            print(f"Audio saved to {output_path}")
        except requests.exceptions.RequestException as e:
            print("语音错误", e)

    # 调用生成音频
    get_audio(name, response, audio_directory, output_name)

# 示例调用
name = 1  # 角色ID
response = "你好, 定义了角色对应的音频文件路径和文本。"  # 文本
output_name = "output_audio"
generate_audio(response, name, output_name)

You can just modify this script especially for some endpoints and paths. Forgive me for using English, it's my first time to answer questions in github and I just want to mark it!

您好,没看到api接口中有关于 url_gpt = "http://127.0.0.1:9880/set_gpt_weights" url_sovits = "http://127.0.0.1:9880/set_sovits_weights" set_gpt_weights和set_sovits_weights 能提供一下吗? Hello, I didn't see in the API.py interface that url_gpt = "http://127.0.0.1:9880/set_gpt_weights" and url_sovits = "http://127.0.0.1:9880/set_sovits_weights". Can you provide set_gpt_weights and set_sovits_weights?

这是main的api

对的 我没在api里面看到封装这两个函数,应该是自己写的

XXXXRT666 commented 2 months ago
import requests
import urllib.parse

audio_directory = "./"

def generate_audio(response, name, output_name):
    global audio_directory

    # 切换模型
    gpt_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\GPT_weights\mizuki-e15.ckpt"
    sovits_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\SoVITS_weights\mizuki_e8_s128.pth"

    url_gpt = "http://127.0.0.1:9880/set_gpt_weights"
    url_sovits = "http://127.0.0.1:9880/set_sovits_weights"
    params_gpt = {
        "weights_path": gpt_model_path
    }
    params_sovits = {
        "weights_path": sovits_model_path
    }

    try:
        response_gpt = requests.get(url_gpt, params=params_gpt)
        response_gpt.raise_for_status()  # 检查请求是否成功
        print("GPT weights set successfully:", response_gpt.json())
    except requests.exceptions.RequestException as e:
        print("Error setting GPT weights:", e)

    try:
        response_sovits = requests.get(url_sovits, params=params_sovits)
        response_sovits.raise_for_status()  # 检查请求是否成功
        print("SoVITS weights set successfully:", response_sovits.json())
    except requests.exceptions.RequestException as e:
        print("Error setting SoVITS weights:", e)

    # 输出音频
    # 定义音频文件路径
    wav_paths = {
        1: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\mizuki0.wav",
        2: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\herta0.wav",
        3: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\griso0.wav",
        4: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\bronya0.wav",
        5: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\miu0.wav"
    }

    # 定义角色对应的文本
    prompt_texts = {
        1: "要吸收和消化掉这些对吧?我会努力的!",
        2: "你也不愿意因为自己身体里埋了一颗星核,祸害空间站这么多人吧?",
        3: "不小心弄脏了,你会怪我吗?",
        4: "再这样下去,bronya的神经中枢,会坏掉的。",
        5: "我的润唇膏给你吧!之后买一支还给我就行。"
    }

    def generate_url(name, response):
        base_url = "http://127.0.0.1:9880/"
        if name in wav_paths:
            wav_path = wav_paths[name]
            prompt_text = prompt_texts[name]
        else:
            wav_path = wav_paths[1]
            prompt_text = prompt_texts[1]

        params = {
            "text": response,
            "text_lang": "zh",
            "ref_audio_path": wav_path,
            "prompt_lang": "zh",
            "prompt_text": prompt_text,
            "text_split_method": "cut5",
            "batch_size": 1,
            "media_type": "wav",
            "streaming_mode": "true"
        }

        encoded_params = urllib.parse.urlencode(params, safe='./')
        url = f"{base_url}?{encoded_params}"
        return url

    def get_audio(name, response, audio_directory, output_name):
        url = generate_url(name, response)
        try:
            response = requests.get(url)
            response.raise_for_status()
            output_path = rf'{audio_directory}\{output_name}.wav'
            with open(output_path, 'wb') as file:
                file.write(response.content)
            print(f"Audio saved to {output_path}")
        except requests.exceptions.RequestException as e:
            print("语音错误", e)

    # 调用生成音频
    get_audio(name, response, audio_directory, output_name)

# 示例调用
name = 1  # 角色ID
response = "你好, 定义了角色对应的音频文件路径和文本。"  # 文本
output_name = "output_audio"
generate_audio(response, name, output_name)

You can just modify this script especially for some endpoints and paths. Forgive me for using English, it's my first time to answer questions in github and I just want to mark it!

您好,没看到api接口中有关于 url_gpt = "http://127.0.0.1:9880/set_gpt_weights" url_sovits = "http://127.0.0.1:9880/set_sovits_weights" set_gpt_weights和set_sovits_weights 能提供一下吗? Hello, I didn't see in the API.py interface that url_gpt = "http://127.0.0.1:9880/set_gpt_weights" and url_sovits = "http://127.0.0.1:9880/set_sovits_weights". Can you provide set_gpt_weights and set_sovits_weights?

这是main的api

对的 我没在api里面看到封装这两个函数,应该是自己写的

类似的有一个 https://github.com/RVC-Boss/GPT-SoVITS/blob/95354647c87fc86a416361b39e7268afd95e193d/api.py#L705

wanglongpeng1 commented 2 months ago
import requests
import urllib.parse

audio_directory = "./"

def generate_audio(response, name, output_name):
    global audio_directory

    # 切换模型
    gpt_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\GPT_weights\mizuki-e15.ckpt"
    sovits_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\SoVITS_weights\mizuki_e8_s128.pth"

    url_gpt = "http://127.0.0.1:9880/set_gpt_weights"
    url_sovits = "http://127.0.0.1:9880/set_sovits_weights"
    params_gpt = {
        "weights_path": gpt_model_path
    }
    params_sovits = {
        "weights_path": sovits_model_path
    }

    try:
        response_gpt = requests.get(url_gpt, params=params_gpt)
        response_gpt.raise_for_status()  # 检查请求是否成功
        print("GPT weights set successfully:", response_gpt.json())
    except requests.exceptions.RequestException as e:
        print("Error setting GPT weights:", e)

    try:
        response_sovits = requests.get(url_sovits, params=params_sovits)
        response_sovits.raise_for_status()  # 检查请求是否成功
        print("SoVITS weights set successfully:", response_sovits.json())
    except requests.exceptions.RequestException as e:
        print("Error setting SoVITS weights:", e)

    # 输出音频
    # 定义音频文件路径
    wav_paths = {
        1: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\mizuki0.wav",
        2: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\herta0.wav",
        3: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\griso0.wav",
        4: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\bronya0.wav",
        5: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\miu0.wav"
    }

    # 定义角色对应的文本
    prompt_texts = {
        1: "要吸收和消化掉这些对吧?我会努力的!",
        2: "你也不愿意因为自己身体里埋了一颗星核,祸害空间站这么多人吧?",
        3: "不小心弄脏了,你会怪我吗?",
        4: "再这样下去,bronya的神经中枢,会坏掉的。",
        5: "我的润唇膏给你吧!之后买一支还给我就行。"
    }

    def generate_url(name, response):
        base_url = "http://127.0.0.1:9880/"
        if name in wav_paths:
            wav_path = wav_paths[name]
            prompt_text = prompt_texts[name]
        else:
            wav_path = wav_paths[1]
            prompt_text = prompt_texts[1]

        params = {
            "text": response,
            "text_lang": "zh",
            "ref_audio_path": wav_path,
            "prompt_lang": "zh",
            "prompt_text": prompt_text,
            "text_split_method": "cut5",
            "batch_size": 1,
            "media_type": "wav",
            "streaming_mode": "true"
        }

        encoded_params = urllib.parse.urlencode(params, safe='./')
        url = f"{base_url}?{encoded_params}"
        return url

    def get_audio(name, response, audio_directory, output_name):
        url = generate_url(name, response)
        try:
            response = requests.get(url)
            response.raise_for_status()
            output_path = rf'{audio_directory}\{output_name}.wav'
            with open(output_path, 'wb') as file:
                file.write(response.content)
            print(f"Audio saved to {output_path}")
        except requests.exceptions.RequestException as e:
            print("语音错误", e)

    # 调用生成音频
    get_audio(name, response, audio_directory, output_name)

# 示例调用
name = 1  # 角色ID
response = "你好, 定义了角色对应的音频文件路径和文本。"  # 文本
output_name = "output_audio"
generate_audio(response, name, output_name)

You can just modify this script especially for some endpoints and paths. Forgive me for using English, it's my first time to answer questions in github and I just want to mark it!

您好,没看到api接口中有关于 url_gpt = "http://127.0.0.1:9880/set_gpt_weights" url_sovits = "http://127.0.0.1:9880/set_sovits_weights" set_gpt_weights和set_sovits_weights 能提供一下吗? Hello, I didn't see in the API.py interface that url_gpt = "http://127.0.0.1:9880/set_gpt_weights" and url_sovits = "http://127.0.0.1:9880/set_sovits_weights". Can you provide set_gpt_weights and set_sovits_weights?

这是main的api

对的 我没在api里面看到封装这两个函数,应该是自己写的

类似的有一个

https://github.com/RVC-Boss/GPT-SoVITS/blob/95354647c87fc86a416361b39e7268afd95e193d/api.py#L705

十分感谢,我去看看

Separatee commented 2 months ago
import requests
import urllib.parse

audio_directory = "./"

def generate_audio(response, name, output_name):
    global audio_directory

    # 切换模型
    gpt_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\GPT_weights\mizuki-e15.ckpt"
    sovits_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\SoVITS_weights\mizuki_e8_s128.pth"

    url_gpt = "http://127.0.0.1:9880/set_gpt_weights"
    url_sovits = "http://127.0.0.1:9880/set_sovits_weights"
    params_gpt = {
        "weights_path": gpt_model_path
    }
    params_sovits = {
        "weights_path": sovits_model_path
    }

    try:
        response_gpt = requests.get(url_gpt, params=params_gpt)
        response_gpt.raise_for_status()  # 检查请求是否成功
        print("GPT weights set successfully:", response_gpt.json())
    except requests.exceptions.RequestException as e:
        print("Error setting GPT weights:", e)

    try:
        response_sovits = requests.get(url_sovits, params=params_sovits)
        response_sovits.raise_for_status()  # 检查请求是否成功
        print("SoVITS weights set successfully:", response_sovits.json())
    except requests.exceptions.RequestException as e:
        print("Error setting SoVITS weights:", e)

    # 输出音频
    # 定义音频文件路径
    wav_paths = {
        1: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\mizuki0.wav",
        2: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\herta0.wav",
        3: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\griso0.wav",
        4: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\bronya0.wav",
        5: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\miu0.wav"
    }

    # 定义角色对应的文本
    prompt_texts = {
        1: "要吸收和消化掉这些对吧?我会努力的!",
        2: "你也不愿意因为自己身体里埋了一颗星核,祸害空间站这么多人吧?",
        3: "不小心弄脏了,你会怪我吗?",
        4: "再这样下去,bronya的神经中枢,会坏掉的。",
        5: "我的润唇膏给你吧!之后买一支还给我就行。"
    }

    def generate_url(name, response):
        base_url = "http://127.0.0.1:9880/"
        if name in wav_paths:
            wav_path = wav_paths[name]
            prompt_text = prompt_texts[name]
        else:
            wav_path = wav_paths[1]
            prompt_text = prompt_texts[1]

        params = {
            "text": response,
            "text_lang": "zh",
            "ref_audio_path": wav_path,
            "prompt_lang": "zh",
            "prompt_text": prompt_text,
            "text_split_method": "cut5",
            "batch_size": 1,
            "media_type": "wav",
            "streaming_mode": "true"
        }

        encoded_params = urllib.parse.urlencode(params, safe='./')
        url = f"{base_url}?{encoded_params}"
        return url

    def get_audio(name, response, audio_directory, output_name):
        url = generate_url(name, response)
        try:
            response = requests.get(url)
            response.raise_for_status()
            output_path = rf'{audio_directory}\{output_name}.wav'
            with open(output_path, 'wb') as file:
                file.write(response.content)
            print(f"Audio saved to {output_path}")
        except requests.exceptions.RequestException as e:
            print("语音错误", e)

    # 调用生成音频
    get_audio(name, response, audio_directory, output_name)

# 示例调用
name = 1  # 角色ID
response = "你好, 定义了角色对应的音频文件路径和文本。"  # 文本
output_name = "output_audio"
generate_audio(response, name, output_name)

You can just modify this script especially for some endpoints and paths. Forgive me for using English, it's my first time to answer questions in github and I just want to mark it!

您好,没看到api接口中有关于 url_gpt = "http://127.0.0.1:9880/set_gpt_weights" url_sovits = "http://127.0.0.1:9880/set_sovits_weights" set_gpt_weights和set_sovits_weights 能提供一下吗? Hello, I didn't see in the API.py interface that url_gpt = "http://127.0.0.1:9880/set_gpt_weights" and url_sovits = "http://127.0.0.1:9880/set_sovits_weights". Can you provide set_gpt_weights and set_sovits_weights?

你可以在你的文件夹里使用

git switch fast_inference_

之后

git pull --force

你的文件夹里就会有多个版本的api.py了

mythzhang8 commented 3 weeks ago
import requests
import urllib.parse

audio_directory = "./"

def generate_audio(response, name, output_name):
    global audio_directory

    # 切换模型
    gpt_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\GPT_weights\mizuki-e15.ckpt"
    sovits_model_path = r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\SoVITS_weights\mizuki_e8_s128.pth"

    url_gpt = "http://127.0.0.1:9880/set_gpt_weights"
    url_sovits = "http://127.0.0.1:9880/set_sovits_weights"
    params_gpt = {
        "weights_path": gpt_model_path
    }
    params_sovits = {
        "weights_path": sovits_model_path
    }

    try:
        response_gpt = requests.get(url_gpt, params=params_gpt)
        response_gpt.raise_for_status()  # 检查请求是否成功
        print("GPT weights set successfully:", response_gpt.json())
    except requests.exceptions.RequestException as e:
        print("Error setting GPT weights:", e)

    try:
        response_sovits = requests.get(url_sovits, params=params_sovits)
        response_sovits.raise_for_status()  # 检查请求是否成功
        print("SoVITS weights set successfully:", response_sovits.json())
    except requests.exceptions.RequestException as e:
        print("Error setting SoVITS weights:", e)

    # 输出音频
    # 定义音频文件路径
    wav_paths = {
        1: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\mizuki0.wav",
        2: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\herta0.wav",
        3: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\griso0.wav",
        4: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\bronya0.wav",
        5: r"E:\AI_tools\chat-sovits\GPT-SoVITS-0519\GPT-SoVITS-0310-liuyue\output\GPT-sovits推理集\miu0.wav"
    }

    # 定义角色对应的文本
    prompt_texts = {
        1: "要吸收和消化掉这些对吧?我会努力的!",
        2: "你也不愿意因为自己身体里埋了一颗星核,祸害空间站这么多人吧?",
        3: "不小心弄脏了,你会怪我吗?",
        4: "再这样下去,bronya的神经中枢,会坏掉的。",
        5: "我的润唇膏给你吧!之后买一支还给我就行。"
    }

    def generate_url(name, response):
        base_url = "http://127.0.0.1:9880/"
        if name in wav_paths:
            wav_path = wav_paths[name]
            prompt_text = prompt_texts[name]
        else:
            wav_path = wav_paths[1]
            prompt_text = prompt_texts[1]

        params = {
            "text": response,
            "text_lang": "zh",
            "ref_audio_path": wav_path,
            "prompt_lang": "zh",
            "prompt_text": prompt_text,
            "text_split_method": "cut5",
            "batch_size": 1,
            "media_type": "wav",
            "streaming_mode": "true"
        }

        encoded_params = urllib.parse.urlencode(params, safe='./')
        url = f"{base_url}?{encoded_params}"
        return url

    def get_audio(name, response, audio_directory, output_name):
        url = generate_url(name, response)
        try:
            response = requests.get(url)
            response.raise_for_status()
            output_path = rf'{audio_directory}\{output_name}.wav'
            with open(output_path, 'wb') as file:
                file.write(response.content)
            print(f"Audio saved to {output_path}")
        except requests.exceptions.RequestException as e:
            print("语音错误", e)

    # 调用生成音频
    get_audio(name, response, audio_directory, output_name)

# 示例调用
name = 1  # 角色ID
response = "你好, 定义了角色对应的音频文件路径和文本。"  # 文本
output_name = "output_audio"
generate_audio(response, name, output_name)

You can just modify this script especially for some endpoints and paths. Forgive me for using English, it's my first time to answer questions in github and I just want to mark it!

如果做并发请求的话这个是不是不行呢?并发请求中使用的是不同的gpt模型和sovits模型