Skip to content

Commit

Permalink
update:readme faq
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed Jun 1, 2024
1 parent 491dabc commit 2492beb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

> 界面预览
>
> ![image](https://github.com/jianchang512/ChatTTS-ui/assets/3378335/51108df5-e7d8-4337-8a30-7175765c64a3)
> ![image](https://github.com/jianchang512/ChatTTS-ui/assets/3378335/6ed7c993-3882-4c34-9abd-f0635b133012)
>

Expand Down Expand Up @@ -115,50 +115,66 @@ chat.load_models(source="local",local_path=CHATTTS_DIR)
默认地址是 `http://127.0.0.1:9966`,如果想修改,可打开目录下的 `.env`文件,将 `WEB_ADDRESS=127.0.0.1:9966`改为合适的ip和端口,比如修改为`WEB_ADDRESS=192.168.0.10:9966`以便局域网可访问
## 使用API请求
## 使用API请求 v0.5+
**请求方法:** POST
**请求地址:** http://127.0.0.1:9966/tts
**请求参数:**
text: str 必须, 要合成语音的文字
text: str| 必须, 要合成语音的文字
voice: int 可选,默认 2222, 决定音色的数字, 2222 | 7869 | 6653 | 4099 | 5099,可选其一,或者任意传入将随机使用音色
voice: int| 可选,默认 2222, 决定音色的数字, 2222 | 7869 | 6653 | 4099 | 5099,可选其一,或者任意传入将随机使用音色
prompt: str 可选,默认 空, 设定 笑声、停顿,例如 [oral_2][laugh_0][break_6]
prompt: str| 可选,默认 空, 设定 笑声、停顿,例如 [oral_2][laugh_0][break_6]
temperature: float 可选, 默认 0.3
temperature: float| 可选, 默认 0.3
top_p: float 可选, 默认 0.7
top_p: float| 可选, 默认 0.7
top_k: int 可选, 默认 20
top_k: int| 可选, 默认 20
skip_refine: int 可选, 默认0, 1=跳过 refine text,0=不跳过
skip_refine: int| 可选, 默认0, 1=跳过 refine text,0=不跳过
custom_voice: int 可选, 默认0,自定义获取音色值时的种子值,需要大于0的整数,如果设置了则以此为准,将忽略 `voice`
custom_voice: int| 可选, 默认0,自定义获取音色值时的种子值,需要大于0的整数,如果设置了则以此为准,将忽略 `voice`
**返回:json数据**
成功返回:
{code:0,msg:ok,audio_files:[dict1,dict2]}
其中 audio_files 是字典数组,每个元素dict为 {filename:wav文件绝对路径,url:可下载的wav网址}
code=0 成功,filename=wav文件名,url=可下载的wav网址
失败返回:
code=1 失败,msg=错误原因
{code:1,msg:错误原因}
```

# API调用代码

import requests

res=requests.post('http://127.0.0.1:9966/tts',data={"text":"你好啊亲爱的朋友。[laugh]","voice":2222,"prompt":'[oral_2][laugh_0][break_6]'})
res = requests.post('http://127.0.0.1:9966/tts', data={
"text": "若不懂无需填写",
"prompt": "",
"voice": "3333",
"temperature": 0.3,
"top_p": 0.7,
"top_k": 20,
"skip_refine": 0,
"custom_voice": 0
})
print(res.json())

#成功
{code:0,msg:'ok',filename:1.wav,url:http://${location.host}/static/wavs/1.wav}
#ok
{code:0, msg:'ok', audio_files:[{filename: E:/python/chattts/static/wavs/20240601-22_12_12-c7456293f7b5e4dfd3ff83bbd884a23e.wav, url: http://127.0.0.1:9966/static/wavs/20240601-22_12_12-c7456293f7b5e4dfd3ff83bbd884a23e.wav}]}

#error
{code:1, msg:"error"}

#error
{code:1,msg:"error"}

```
Expand Down
14 changes: 8 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
torch._dynamo.config.suppress_errors = True
torch.set_float32_matmul_precision('high')
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
VERSION='0.6'

def get_executable_path():
# 这个函数会返回可执行文件所在的目录
if getattr(sys, 'frozen', False):
# 如果程序是被“冻结”打包的,使用这个路径
return Path(sys.executable).parent.as_posix()
else:
return Path.cwd().as_posix()
VERSION='0.5'

ROOT_DIR=get_executable_path()

Expand Down Expand Up @@ -44,13 +45,9 @@ def get_executable_path():
from modelscope import snapshot_download
import numpy as np
import time


# 读取 .env 变量
WEB_ADDRESS = os.getenv('WEB_ADDRESS', '127.0.0.1:9966')



# 默认从 modelscope 下载模型,如果想从huggingface下载模型,请将以下3行注释掉
CHATTTS_DIR = snapshot_download('pzc163/chatTTS',cache_dir=MODEL_DIR)
chat = ChatTTS.Chat()
Expand Down Expand Up @@ -178,8 +175,13 @@ def tts():
"inference_time": inference_time_rounded,
"audio_duration": audio_duration_rounded
})
result_dict={"code": 0, "msg": "ok", "audio_files": audio_files}
# 兼容pyVideoTrans接口调用
if len(audio_files)==1:
result_dict["filename"]=audio_files[0]['filename']
result_dict["url"]=audio_files[0]['url']

return jsonify({"code": 0, "msg": "ok", "audio_files": audio_files})
return jsonify(result_dict)

def ClearWav(directory):
# 获取../static/wavs目录中的所有文件和目录
Expand Down
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h1 class="text-center">ChatTTS WebUI & API<span class="fs-6">(v{{version}})</sp
<div>推理时长: ${audio.inference_time} 秒</div>
<div>音频时长: ${audio.audio_duration} 秒</div>
<button class="btn btn-info mt-2 show-js-btn" data-js-code="${encodeURIComponent(jsCode)}">显示API调用</button>
<div class="m-2 bg-black text-white d-none code-container"></div>
<div class="m-2 bg-black text-white d-none code-container p-1"></div>
</div>
`);
});
Expand Down

0 comments on commit 2492beb

Please sign in to comment.