forked from jianchang512/ChatTTS-ui
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.py
70 lines (44 loc) · 1.71 KB
/
test.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os,sys
from pathlib import Path
import ChatTTS
def get_executable_path():
# 这个函数会返回可执行文件所在的目录
if getattr(sys, 'frozen', False):
# 如果程序是被“冻结”打包的,使用这个路径
return Path(sys.executable).parent.as_posix()
else:
return Path.cwd().as_posix()
ROOT_DIR=get_executable_path()
MODEL_DIR_PATH=Path(ROOT_DIR+"/models")
MODEL_DIR_PATH.mkdir(parents=True, exist_ok=True)
MODEL_DIR=MODEL_DIR_PATH.as_posix()
os.environ['HF_HUB_CACHE']=MODEL_DIR
os.environ['HF_ASSETS_CACHE']=MODEL_DIR
import torch,datetime
import torch._dynamo
torch._dynamo.config.suppress_errors = True
torch.manual_seed(1000)
print(torch.randn(768))
exit()
import soundfile as sf
import numpy as np
WAVS_DIR_PATH=Path(ROOT_DIR+"/static/wavs")
WAVS_DIR_PATH.mkdir(parents=True, exist_ok=True)
WAVS_DIR=WAVS_DIR_PATH.as_posix()
LOGS_DIR_PATH=Path(ROOT_DIR+"/logs")
LOGS_DIR_PATH.mkdir(parents=True, exist_ok=True)
LOGS_DIR=LOGS_DIR_PATH.as_posix()
chat = ChatTTS.Chat()
chat.load_models(force_redownload=True)
text="你好啊朋友们,听说今天是个好日子,难道不是吗?"
prompt='[oral_2][laugh_0][break_0]'
#
torch.manual_seed(3333)
rand_spk = chat.sample_random_speaker()
print(rand_spk)
wavs = chat.infer([text], use_decoder=True,params_infer_code={'spk_emb': rand_spk,'prompt':'[speed_1]'} ,skip_refine_text=True,params_refine_text= {'prompt': prompt})
# 初始化一个空的numpy数组用于之后的合并
combined_wavdata = np.array([], dtype=wavs[0][0].dtype) # 确保dtype与你的wav数据类型匹配
for wavdata in wavs:
combined_wavdata = np.concatenate((combined_wavdata, wavdata[0]))
sf.write("0.wav", combined_wavdata, 24000)