windows10部署ChatTTS+Apifox调用
1 文件准备
准备好如下图所示的文件
2 修改ChatTTS_Win\ChatTTS\uilib\cfg.py
如下图所示,注释第34行,增加
WEB_ADDRESS = '0.0.0.0:9998'
确保局域网内的其他设备也可以请求该服务。
3 启动服务
4 发送post请求
对应的请求内容如下:
bash代码
curl --location --request POST 'http://192.168.0.121:9998/tts?text=windows%E9%83%A8%E7%BD%B2%E8%AF%AD%E9%9F%B3%E7%94%9F%E6%88%90%E6%9C%8D%E5%8A%A1&voice=1111&top_p=0.7&top_k=20&temperature=0.3&custom_voice=3531&refine_max_new_token=384' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: 192.168.0.121:9998' \
--header 'Connection: keep-alive'
python代码
import http.client
conn = http.client.HTTPSConnection("192.168.0.121", 9998)
payload = ''
headers = {
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Accept': '*/*',
'Host': '192.168.0.121:9998',
'Connection': 'keep-alive'
}
conn.request("POST", "/tts?text=windows%25E9%2583%25A8%25E7%25BD%25B2%25E8%25AF%25AD%25E9%259F%25B3%25E7%2594%259F%25E6%2588%2590%25E6%259C%258D%25E5%258A%25A1&voice=1111&top_p=0.7&top_k=20&temperature=0.3&custom_voice=3531&refine_max_new_token=384", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
javascript代码
var myHeaders = new Headers();
myHeaders.append("User-Agent", "Apifox/1.0.0 (https://apifox.com)");
myHeaders.append("Accept", "*/*");
myHeaders.append("Host", "192.168.0.121:9998");
myHeaders.append("Connection", "keep-alive");
var requestOptions = {
method: 'POST',
headers: myHeaders,
redirect: 'follow'
};
fetch("http://192.168.0.121:9998/tts?text=windows%E9%83%A8%E7%BD%B2%E8%AF%AD%E9%9F%B3%E7%94%9F%E6%88%90%E6%9C%8D%E5%8A%A1&voice=1111&top_p=0.7&top_k=20&temperature=0.3&custom_voice=3531&refine_max_new_token=384", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));