Spaces:
Paused
Paused
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,231 +1,7 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
-
|
| 8 |
-
- 支持加载多模型,可以将多个模型合并为一个新的id对应角色模型的映射表
|
| 9 |
-
<details><summary>点击预览返回的映射表</summary><pre><code>
|
| 10 |
-
[
|
| 11 |
-
{
|
| 12 |
-
"0": "綾地寧々"
|
| 13 |
-
},
|
| 14 |
-
{
|
| 15 |
-
"1": "在原七海"
|
| 16 |
-
},
|
| 17 |
-
{
|
| 18 |
-
"2": "小茸"
|
| 19 |
-
},
|
| 20 |
-
{
|
| 21 |
-
"3": "唐乐吟"
|
| 22 |
-
},
|
| 23 |
-
{
|
| 24 |
-
"...": "..."
|
| 25 |
-
},
|
| 26 |
-
{
|
| 27 |
-
"196": "ルイズ"
|
| 28 |
-
},
|
| 29 |
-
{
|
| 30 |
-
"197": "ティファニア"
|
| 31 |
-
}
|
| 32 |
-
]
|
| 33 |
-
</code></pre></details>
|
| 34 |
-
|
| 35 |
-
# 如何部署
|
| 36 |
-
|
| 37 |
-
## Docker部署
|
| 38 |
-
|
| 39 |
-
### docker镜像拉取脚本
|
| 40 |
-
|
| 41 |
-
```
|
| 42 |
-
bash -c "$(wget -O- https://gist.githubusercontent.com/Artrajz/b2c02499f91c3a51b8b48f1a3c9a7ead/raw/e3033f1b222868b4b0f1b522e52e18217460ff91/moegoe-simple-api-installer-latest.sh)"
|
| 43 |
-
```
|
| 44 |
-
|
| 45 |
-
镜像大小为5g,所以拉取会比较慢,拉取成功后由于没有导入vits模型所以无法使用,需要按以下步骤导入模型
|
| 46 |
-
|
| 47 |
-
### 下载VITS模型
|
| 48 |
-
|
| 49 |
-
VITS模型放入`/usr/local/moegoe-simple-api/Model`文件夹中,模型文件夹中要有.pth和config.json文件
|
| 50 |
-
|
| 51 |
-
<details><summary>点击查看模型目录结构</summary><pre><code>
|
| 52 |
-
├─Model
|
| 53 |
-
│ ├─g
|
| 54 |
-
│ │ config.json
|
| 55 |
-
│ │ G_953000.pth
|
| 56 |
-
│ │
|
| 57 |
-
│ ├─Nene_Nanami_Rong_Tang
|
| 58 |
-
│ │ 1374_epochs.pth
|
| 59 |
-
│ │ config.json
|
| 60 |
-
│ │
|
| 61 |
-
│ └─Zero_no_tsukaima
|
| 62 |
-
│ 1158_epochs.pth
|
| 63 |
-
│ config.json
|
| 64 |
-
</code></pre></details>
|
| 65 |
-
|
| 66 |
-
### 修改模型路径
|
| 67 |
-
|
| 68 |
-
在 `/usr/local/moegoe-simple-api/config.py` 中修改模型路径
|
| 69 |
-
|
| 70 |
-
<details><summary>点击查看config.py模型路径填写示例</summary><pre><code>
|
| 71 |
-
vits模型路径填写方法,MODEL_LIST中的每一行是
|
| 72 |
-
[ABS_PATH+"/Model/{模型文件夹}/{.pth模型}", ABS_PATH+"/Model/{模型文件夹}/config.json"],
|
| 73 |
-
也可以写相对路径或绝对路径,由于windows和linux路径写法不同,用上面的写法或绝对路径最稳妥
|
| 74 |
-
示例:
|
| 75 |
-
MODEL_LIST = [
|
| 76 |
-
[ABS_PATH+"/Model/Nene_Nanami_Rong_Tang/1374_epochs.pth", ABS_PATH+"/Model/Nene_Nanami_Rong_Tang/config.json"],
|
| 77 |
-
[ABS_PATH+"/Model/Zero_no_tsukaima/1158_epochs.pth", ABS_PATH+"/Model/Zero_no_tsukaima/config.json"],
|
| 78 |
-
[ABS_PATH+"/Model/g/G_953000.pth", ABS_PATH+"/Model/g/config.json"],
|
| 79 |
-
]
|
| 80 |
-
</code></pre></details>
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
### 开始使用!
|
| 84 |
-
|
| 85 |
-
终端输入`docker compose up -d`
|
| 86 |
-
|
| 87 |
-
或再次执行拉取脚本
|
| 88 |
-
|
| 89 |
-
### 镜像更新方法
|
| 90 |
-
|
| 91 |
-
重新执行docker镜像拉取脚本即可
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
## 直接部署
|
| 95 |
-
|
| 96 |
-
1. 下载VITS模型并放入`Model`文件夹中
|
| 97 |
-
2. 在 `config.py` 中修改模型路径
|
| 98 |
-
3. 安装python依赖(建议用conda虚拟环境) `pip install -r requirements.txt`
|
| 99 |
-
4. 开始使用!`python app.py`
|
| 100 |
-
|
| 101 |
-
# 参数
|
| 102 |
-
|
| 103 |
-
## 语音合成voice
|
| 104 |
-
|
| 105 |
-
| Name | Parameter | Is must | Default | Value | Instruction |
|
| 106 |
-
| ------------- | --------- | ------- | ------- | ------------ | ------------------------------------------------ |
|
| 107 |
-
| 合成文本 | text | true | | text | |
|
| 108 |
-
| 角色id | id | false | 0 | (number) | |
|
| 109 |
-
| 音频格式 | format | false | wav | wav,ogg,silk | silk支持tx系语音 |
|
| 110 |
-
| 文本语言 | lang | false | mix | zh,ja,mix | 当lang=mix时,文本应该用[ZH] 或 [JA] 包裹 |
|
| 111 |
-
| 语音长度/语速 | speed | false | 1.0 | (number) | 调节语音长度,相当于调节语速,该数值越大语速越慢 |
|
| 112 |
-
|
| 113 |
-
## 语音转换voice conversion
|
| 114 |
-
|
| 115 |
-
| Name | Parameter | Is must | Default | Value | Instruction |
|
| 116 |
-
| ---------- | ----------- | ------- | ------- | ---------- | ---------------------- |
|
| 117 |
-
| 上传音频 | upload | true | | audio file | 只支持wav和ogg |
|
| 118 |
-
| 源角色id | original_id | true | | (number) | 上传文件所使用的角色id |
|
| 119 |
-
| 目标角色id | target_id | true | | (number) | 要转换的目标角色id |
|
| 120 |
-
|
| 121 |
-
# 调用方法
|
| 122 |
-
|
| 123 |
-
## GET
|
| 124 |
-
|
| 125 |
-
- GET/POST http://127.0.0.1:23456/voice/speakers
|
| 126 |
-
|
| 127 |
-
返回id对应角色的映射表(json格式)
|
| 128 |
-
|
| 129 |
-
- GET http://127.0.0.1/voice?text=[JA]text[JA][ZH]text[ZH]&id=0&format=wav&lang=mix
|
| 130 |
-
|
| 131 |
-
返回wav音频文件
|
| 132 |
-
|
| 133 |
-
- GET http://127.0.0.1/voice?text=[JA]text[JA][ZH]text[ZH]&id=0&format=ogg&lang=mix
|
| 134 |
-
|
| 135 |
-
返回ogg音频文件
|
| 136 |
-
|
| 137 |
-
- GET http://127.0.0.1/voice?text=text&lang=zh
|
| 138 |
-
|
| 139 |
-
设定语言为zh,则文本无需[ZH]包裹
|
| 140 |
-
|
| 141 |
-
- GET http://127.0.0.1/voice?text=text&lang=ja
|
| 142 |
-
|
| 143 |
-
设定语言为ja,则文本无需[JA]包裹
|
| 144 |
-
|
| 145 |
-
- GET http://127.0.0.1/voice?text=text&id=142&format=wav&lang=zh&speed=1.4
|
| 146 |
-
|
| 147 |
-
文本为text,角色id为142,音频格式为wav,文本语言为zh,语速为1.4
|
| 148 |
-
|
| 149 |
-
## POST
|
| 150 |
-
|
| 151 |
-
- python
|
| 152 |
-
|
| 153 |
-
```python
|
| 154 |
-
import re
|
| 155 |
-
import requests
|
| 156 |
-
import json
|
| 157 |
-
import os
|
| 158 |
-
import random
|
| 159 |
-
import string
|
| 160 |
-
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
| 161 |
-
|
| 162 |
-
abs_path = os.path.dirname(__file__)
|
| 163 |
-
|
| 164 |
-
def voice_speakers():
|
| 165 |
-
url = "http://127.0.0.1:23456/voice/speakers"
|
| 166 |
-
|
| 167 |
-
res = requests.post(url=url)
|
| 168 |
-
json = res.json()
|
| 169 |
-
for i in json:
|
| 170 |
-
print(i)
|
| 171 |
-
|
| 172 |
-
def voice():
|
| 173 |
-
post_json = json.dumps({
|
| 174 |
-
"text":"需要合成的文本",
|
| 175 |
-
"id":142,
|
| 176 |
-
"format":"wav",
|
| 177 |
-
"lang":"zh",
|
| 178 |
-
"speed":1.4,
|
| 179 |
-
})
|
| 180 |
-
headers={'content-type':'application/json'}
|
| 181 |
-
url = "http://127.0.0.1:23456/voice"
|
| 182 |
-
|
| 183 |
-
res = requests.post(url=url,data=post_json,headers=headers)
|
| 184 |
-
fname = re.findall("filename=(.+)", res.headers["Content-Disposition"])[0]
|
| 185 |
-
path = f"{abs_path}/{fname}"
|
| 186 |
-
with open(path, "wb") as f:
|
| 187 |
-
f.write(res.content)
|
| 188 |
-
|
| 189 |
-
def voice_conversion(upload_name):
|
| 190 |
-
upload_path = f'{abs_path}/{upload_name}'
|
| 191 |
-
upload_type = f'audio/{upload_name.split(".")[1]}' #wav,ogg
|
| 192 |
-
|
| 193 |
-
fields = {
|
| 194 |
-
"upload": (upload_name, open(upload_path,'rb'),upload_type),
|
| 195 |
-
"original_id": "142",
|
| 196 |
-
"target_id": "92",
|
| 197 |
-
}
|
| 198 |
-
boundary = '----VoiceConversionFormBoundary' \
|
| 199 |
-
+ ''.join(random.sample(string.ascii_letters + string.digits, 16))
|
| 200 |
-
m = MultipartEncoder(fields=fields, boundary=boundary)
|
| 201 |
-
|
| 202 |
-
headers = {"Content-Type": m.content_type}
|
| 203 |
-
url = "http://127.0.0.1:23456/voice/conversion"
|
| 204 |
-
|
| 205 |
-
res = requests.post(url=url,data=m,headers=headers)
|
| 206 |
-
fname = re.findall("filename=(.+)", res.headers["Content-Disposition"])[0]
|
| 207 |
-
path = f"{abs_path}/{fname}"
|
| 208 |
-
with open(path, "wb") as f:
|
| 209 |
-
f.write(res.content)
|
| 210 |
-
```
|
| 211 |
-
|
| 212 |
-
# 可能遇到的问题
|
| 213 |
-
|
| 214 |
-
~~本人遇到过的问题~~
|
| 215 |
-
|
| 216 |
-
### 运行后服务器无响应
|
| 217 |
-
|
| 218 |
-
可能是内存不足,可以尝试减少模型加载数量。
|
| 219 |
-
|
| 220 |
-
### 模型推理时服务器无响应
|
| 221 |
-
|
| 222 |
-
可能是同时处理多个推理任务导致CPU堵塞,可以尝试在*voice.py*中取消以下**两行**代码的注释,意思是让pytorch只使用1个物理CPU核心,防止一个任务抢占过多CPU资源。
|
| 223 |
-
|
| 224 |
-
```python
|
| 225 |
-
import torch
|
| 226 |
-
torch.set_num_threads(1)
|
| 227 |
-
```
|
| 228 |
-
|
| 229 |
-
# 鸣谢
|
| 230 |
-
|
| 231 |
-
该项目基于[CjangCjengh](https://github.com/CjangCjengh)的[MoeGoe](https://github.com/CjangCjengh/MoeGoe)
|
|
|
|
| 1 |
+
- title: MoeGoe Simple API
|
| 2 |
+
- emoji: 🌍
|
| 3 |
+
- colorFrom: yellow
|
| 4 |
+
- colorTo: purple
|
| 5 |
+
- sdk: docker
|
| 6 |
+
- pinned: false
|
| 7 |
+
- license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|