forked from xszyou/Fay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgptsovits.py
41 lines (35 loc) · 1.18 KB
/
gptsovits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import requests
import time
from utils import util
import wave
class Speech:
def connect(self):
pass
def close(self):
pass
def to_sample(self, text, style) :
url = "http://127.0.0.1:9880"
data = {
"text": text,
"text_language": "zh",
"cut_punc": ",。"
}
try:
response = requests.post(url, json=data)
file_url = './samples/sample-' + str(int(time.time() * 1000)) + '.wav'
if response.status_code == 200:
with wave.open(file_url, 'wb') as wf:
wf.setnchannels(1)
wf.setsampwidth(2)
wf.setframerate(16000)
wf.writeframes(response.content)
return file_url
else:
util.log(1, "[x] 语音转换失败!")
util.log(1, "[x] 原因: " + str(response.text))
return None
except Exception as e :
util.log(1, "[x] 语音转换失败!")
util.log(1, "[x] 原因: " + str(str(e)))
file_url = None
return file_url