Skip to content

[fast_inference] Make API Great Again And Again #923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 6, 2024
Merged

[fast_inference] Make API Great Again And Again #923

merged 9 commits into from
Apr 6, 2024

Conversation

ChasonJiang
Copy link
Contributor

@ChasonJiang ChasonJiang commented Apr 3, 2024

更新如下

  • 为fast_inference分支适配了全新的WebAPI,不完全兼容之前的api
  • 支持wav/ogg/aac/raw音频格式,流式或非流式返回。ogg不支持非流式返回,因为音频过大会导致报错。
  • 注意,需要更新LangSegment,否则可能导致LangSegment报错

状态

  • 基本可用

@ChasonJiang
Copy link
Contributor Author

ChasonJiang commented Apr 3, 2024

WebAPI文档

python api_v2.py -a 127.0.0.1 -p 9880 -c GPT_SoVITS/configs/tts_infer.yaml

执行参数:

`-a` - `绑定地址, 默认"127.0.0.1"`
`-p` - `绑定端口, 默认9880`
`-c` - `TTS配置文件路径, 默认"GPT_SoVITS/configs/tts_infer.yaml"`

调用:

推理

endpoint: /tts
GET:

http://127.0.0.1:9880/tts?text=先帝创业未半而中道崩殂,今天下三分,益州疲弊,此诚危急存亡之秋也。&text_lang=zh&ref_audio_path=archive_jingyuan_1.wav&prompt_lang=zh&prompt_text=我是「罗浮」云骑将军景元。不必拘谨,「将军」只是一时的身份,你称呼我景元便可&text_split_method=cut5&batch_size=1&media_type=wav&streaming_mode=true

POST:

{
    "text": "",                   # str.(required) text to be synthesized
    "text_lang": "",               # str.(required) language of the text to be synthesized
    "ref_audio_path": "",         # str.(required) reference audio path.
    "prompt_text": "",            # str.(optional) prompt text for the reference audio
    "prompt_lang": "",            # str.(required) language of the prompt text for the reference audio
    "top_k": 5,                   # int.(optional) top k sampling
    "top_p": 1,                   # float.(optional) top p sampling
    "temperature": 1,             # float.(optional) temperature for sampling
    "text_split_method": "cut5",  # str.(optional) text split method, see text_segmentation_method.py for details.
    "batch_size": 1,              # int.(optional) batch size for inference
    "batch_threshold": 0.75,      # float.(optional) threshold for batch splitting.
    "split_bucket": true,          # bool.(optional) whether to split the batch into multiple buckets.
    "speed_factor":1.0,           # float.(optional) control the speed of the synthesized audio.
    "fragment_interval":0.3,      # float.(optional) to control the interval of the audio fragment.
    "seed": -1,                   # int.(optional) random seed for reproducibility.
    "media_type": "wav",          # str.(optional) media type of the output audio, support "wav", "raw", "ogg", "aac".
    "streaming_mode": false,      # bool.(optional) whether to return a streaming response.
}

RESP:
成功: 直接返回 wav 音频流, http code 200
失败: 返回包含错误信息的 json, http code 400

命令控制

endpoint: /control

command:
"restart": 重新运行
"exit": 结束运行

GET:

http://127.0.0.1:9880/control?command=restart

POST:

{
    "command": "restart"
}

RESP: 无

切换GPT模型

endpoint: /set_gpt_weights

GET:

http://127.0.0.1:9880/set_gpt_weights?weights_path=GPT_SoVITS/pretrained_models/s1bert25hz-2kh-longer-epoch=68e-step=50232.ckpt

RESP:
成功: 返回"success", http code 200
失败: 返回包含错误信息的 json, http code 400

切换Sovits模型

endpoint: /set_sovits_weights

GET:

http://127.0.0.1:9880/set_sovits_weights?weights_path=GPT_SoVITS/pretrained_models/s2G488k.pth

RESP:
成功: 返回"success", http code 200
失败: 返回包含错误信息的 json, http code 400

@YYuX-1145
Copy link

不考虑开放通过启动参数调整workers吗?(这对同时处理多个请求有帮助)

@ChasonJiang
Copy link
Contributor Author

不考虑开放通过启动参数调整workers吗?(这对同时处理多个请求有帮助)

我刚刚试了,多workers似乎会有问题(直接给我整卡死了😂

@YYuX-1145
Copy link

不考虑开放通过启动参数调整workers吗?(这对同时处理多个请求有帮助)

我刚刚试了,多workers似乎会有问题(直接给我整卡死了😂

奇怪了,我这边一切正常,不过每增加一个worker内存显存消耗就会增加一倍,是不是开太多了?

@ChasonJiang
Copy link
Contributor Author

奇怪了,我这边一切正常,不过每增加一个worker内存显存消耗就会增加一倍,是不是开太多了?

有可能,我开了4个worker,占用了10G+内存

@YYuX-1145
Copy link

奇怪了,我这边一切正常,不过每增加一个worker内存显存消耗就会增加一倍,是不是开太多了?

有可能,我开了4个worker,占用了10G+内存

这样的设置需要32G内存和推荐16G显存,不够的话必掉速,如果显卡不是特别强的话开多了提升不会太明显,我这边也是开4个worker,完成同一任务从29s缩短到12s

@RVC-Boss RVC-Boss merged commit ec7647e into RVC-Boss:fast_inference_ Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants