|
|
|
|
|
import torch |
|
import ChatTTS |
|
import os,sys |
|
from common_test import * |
|
|
|
now_dir = os.getcwd() |
|
sys.path.append(now_dir) |
|
from tool.logger import get_logger |
|
|
|
|
|
torch._dynamo.config.cache_size_limit = 64 |
|
torch._dynamo.config.suppress_errors = True |
|
torch.set_float32_matmul_precision('high') |
|
|
|
logger= get_logger("api") |
|
|
|
chat = ChatTTS.Chat() |
|
if chat.load(source="custom", custom_path="D:\\chenjgspace\\ai-model\\chattts",coef=None): |
|
print("Models loaded successfully.") |
|
else: |
|
print("Models load failed.") |
|
sys.exit(1) |
|
|
|
|
|
texts = [ |
|
"我真的不敢相信,他那么年轻武功居然这么好", |
|
] |
|
|
|
|
|
|
|
rand_spk = chat.sample_random_speaker() |
|
print(rand_spk) |
|
|
|
params_infer_code = ChatTTS.Chat.InferCodeParams( |
|
spk_emb = rand_spk, |
|
temperature = .3, |
|
top_P = 0.7, |
|
top_K = 20, |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
params_refine_text = ChatTTS.Chat.RefineTextParams( |
|
prompt='[oral_2][laugh_0][break_6]', |
|
) |
|
|
|
wavs = chat.infer( |
|
texts, |
|
params_refine_text=params_refine_text, |
|
params_infer_code=params_infer_code, |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prefix_name = "D:\\Download\\" + get_date_time() |
|
|
|
for index, wav in enumerate(wavs): |
|
save_mp3_file(wav, index, prefix_name) |
|
|
|
|
|
|
|
|
|
|