链载Ai

标题: 在pyVideoTrans软件中使用 [打印本页]

作者: 链载Ai    时间: 前天 10:04
标题: 在pyVideoTrans软件中使用

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;letter-spacing: 0.1em;">一个简单的本地网页界面,直接在网页使用ChatTTS[1]将文字合成为语音,支持中英文、数字混杂,并提供API接口。

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;letter-spacing: 0.1em;">Releases中可下载Windows整合包[2]

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;letter-spacing: 0.1em;">界面预览

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;letter-spacing: 0.1em;">试听合成语音效果

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;letter-spacing: 0.1em;">中英数字混杂效果

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 1.2em;display: table;border-bottom: 1px solid rgb(248, 57, 41);">Windows预打包版

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;letter-spacing: 0.1em;">1.从Releases[3]中下载压缩包,解压后双击 app.exe 即可使用

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 1.2em;display: table;border-bottom: 1px solid rgb(248, 57, 41);">Linux 下容器部署

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 1.1em;border-left: 4px solid rgb(248, 57, 41);">安装

ingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;font-size: 15px;letter-spacing: 0.1em;">1.拉取项目仓库

在任意路径下克隆项目,例如:

gitclonehttps://github.com/jianchang512/ChatTTS-ui.gitchat-tts-ui

2.启动 Runner

进入到项目目录:

cdchat-tts-ui

启动容器并查看初始化日志:

dockercomposeup-ddockercomposelogs-f--no-log-prefix

3.访问 ChatTTS WebUI

启动:['0.0.0.0', '9966'],也即,访问部署设备的IP:9966即可,例如:

●本机:http://127.0.0.1:9966

●服务器:http://192.168.1.100:9966

更新

1.Get the latest code from the main branch:

gitcheckoutmaingitpulloriginmain

2.Go to the next step and update to the latest image:

dockercomposedowndockercomposeup-d--builddockercomposelogs-f--no-log-prefix

Linux 下源码部署

1.配置好 python3.9+环境

2.创建空目录/data/chattts执行命令cd /data/chattts && git clonehttps://github.com/jianchang512/chatTTS-ui.

3.创建虚拟环境python3 -m venv venv

4.激活虚拟环境source ./venv/bin/activate

5.安装依赖pip3 install -r requirements.txt

6.如果不需要CUDA加速,执行pip3 install torch torchaudio

如果需要CUDA加速,执行

pip install torch torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install nvidia-cublas-cu11 nvidia-cudnn-cu11

另需安装 CUDA11.8+ ToolKit,请自行搜索安装方法 或参考 https://juejin.cn/post/7318704408727519270

除CUDA外,也可以使用AMD GPU进行加速,这需要安装ROCm和PyTorch_ROCm版本。AMG GPU借助ROCm,在PyTorch开箱即用,无需额外修改代码。

i. 请参考https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/quick-start.html来安装AMD GPU Driver及ROCm.

ii. 再通过https://pytorch.org/安装PyTorch_ROCm版本。

pip3installtorchtorchvisiontorchaudio--index-urlhttps://download.pytorch.org/whl/rocm6.0
安装完成后,可以通过rocm-smi命令来查看系统中的AMDGPU。也可以用以下Torch代码(query_gpu.py)来查询当前AMDGPUDevice.
import torch
print(torch.__version__)
if torch.cuda.is_available():device = torch.device("cuda")# a CUDA device objectprint('Using GPU:', torch.cuda.get_device_name(0))else:device = torch.device("cpu")print('Using CPU')
torch.cuda.get_device_properties(0)

使用以上代码,以AMD Radeon Pro W7900为例,查询设备如下。

$ python ~/query_gpu.py
2.4.0.dev20240401+rocm6.0
Using GPU: AMD Radeon PRO W7900

7.执行python3 app.py启动,将自动打开浏览器窗口,默认地址http://127.0.0.1:9966(注意:默认从 modelscope 魔塔下载模型,不可使用代理下载,请关闭代理)

MacOS 下源码部署

1.配置好 python3.9+环境,安装git ,执行命令brew install libsndfile git python@3.10继续执行

exportPATH="/usr/local/opt/python@3.10/binPATH"source~/.bash_profilesource~/.zshrc

2.创建空目录/data/chattts执行命令cd /data/chattts && git clonehttps://github.com/jianchang512/chatTTS-ui .3.创建虚拟环境python3 -m venv venv4.激活虚拟环境source ./venv/bin/activate5.安装依赖pip3 install -r requirements.txt6.安装torchpip3 install torch torchaudio7.执行python3 app.py启动,将自动打开浏览器窗口,默认地址http://127.0.0.1:9966(注意:默认从 modelscope 魔塔下载模型,不可使用代理下载,请关闭代理)

Windows源码部署

1.下载python3.9+,安装时注意选中Add Python to environment variables2.下载并安装git,https://github.com/git-for-windows/git/releases/download/v2.45.1.windows.1/Git-2.45.1-64-bit.exe3.创建空文件夹D:/chattts并进入,地址栏输入cmd回车,在弹出的cmd窗口中执行命令git clone https://github.com/jianchang512/chatTTS-ui .4.创建虚拟环境,执行命令python -m venv venv5.激活虚拟环境,执行.\venv\scripts\activate6.安装依赖,执行pip install -r requirements.txt7.如果不需要CUDA加速,执行pip install torch torchaudio

如果需要CUDA加速,执行

pip install torch torchaudio --index-url https://download.pytorch.org/whl/cu118

另需安装 CUDA11.8+ ToolKit,请自行搜索安装方法或参考https://juejin.cn/post/7318704408727519270

8.执行python app.py启动,将自动打开浏览器窗口,默认地址http://127.0.0.1:9966(注意:默认从 modelscope 魔塔下载模型,不可使用代理下载,请关闭代理)

源码部署注意

1.源码部署启动后,会先从 modelscope下载模型,但modelscope缺少spk_stat.pt,会报错,请点击链接https://huggingface.co/2Noise/ChatTTS/blob/main/asset/spk_stat.pt下载 spk_stat.pt,将该文件复制到项目目录/models/pzc163/chatTTS/asset/文件夹内`2.注意 modelscope 仅允许中国大陆ip下载模型,如果遇到 proxy 类错误,请关闭代理。如果你希望从 huggingface.co 下载模型,请打开app.py查看大约第50行-60行的注释。3.如果需要GPU加速,必须是英伟达显卡,并且安装 cuda版本的torch。pip install torch torchaudio --index-url https://download.pytorch.org/whl/cu118

# 默认从 modelscope 下载模型,如果想从huggingface下载模型,请将以下3行注释掉CHATTTS_DIR = snapshot_download('pzc163/chatTTS',cache_dir=MODEL_DIR)chat = ChatTTS.Chat()chat.load_models(source="local",local_path=CHATTTS_DIR)
# 如果希望从 huggingface.co下载模型,将以下注释删掉。将上方3行内容注释掉#os.environ['HF_HUB_CACHE']=MODEL_DIR#os.environ['HF_ASSETS_CACHE']=MODEL_DIR#chat = ChatTTS.Chat()#chat.load_models()

常见问题与报错解决方法

修改http地址

默认地址是http://127.0.0.1:9966,如果想修改,可打开目录下的.env文件,将WEB_ADDRESS=127.0.0.1:9966改为合适的ip和端口,比如修改为WEB_ADDRESS=192.168.0.10:9966以便局域网可访问

使用API请求 v0.5+

请求方法: POST

请求地址:http://127.0.0.1:9966/tts

请求参数:

text: str| 必须, 要合成语音的文字

voice: int| 可选,默认 2222, 决定音色的数字, 2222 | 7869 | 6653 | 4099 | 5099,可选其一,或者任意传入将随机使用音色

prompt: str| 可选,默认 空, 设定 笑声、停顿,例如 [oral_2][laugh_0][break_6]

temperature: float| 可选, 默认 0.3

top_p: float| 可选, 默认 0.7

top_k: int| 可选, 默认 20

skip_refine: int| 可选, 默认0, 1=跳过 refine text,0=不跳过

custom_voice: int| 可选, 默认0,自定义获取音色值时的种子值,需要大于0的整数,如果设置了则以此为准,将忽略voice

返回:json数据

成功返回: {code:0,msgk,audio_files:[dict1,dict2]}

其中audio_files是字典数组,每个元素dict为{filename:wav文件绝对路径,url:可下载的wav网址}

失败返回:

{code:1,msg:错误原因}
#API调用代码
import requests
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())
#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"}

在pyVideoTrans软件中使用

升级 pyVideoTrans 到 1.82+https://github.com/jianchang512/pyvideotrans

1.点击菜单-设置-ChatTTS,填写请求地址,默认应该填写http://127.0.0.1:99662.测试无问题后,在主界面中选择ChatTTS

References

[1]ChatTTS:https://github.com/2noise/chattts
[2]Releases中可下载Windows整合包:https://github.com/jianchang512/ChatTTS-ui/releases
[3]Releases:https://github.com/jianchang512/chatTTS-ui/releases






欢迎光临 链载Ai (https://www.lianzai.com/) Powered by Discuz! X3.5