| import sys |
| import torch |
| import torchaudio |
|
|
| |
| project_path = '/data/liyangzhuo/chattts/Awesome-ChatTTS-2-main' |
| if project_path not in sys.path: |
| sys.path.insert(0, project_path) |
|
|
| import ChatTTS |
|
|
| |
| torch._dynamo.config.cache_size_limit = 64 |
| torch._dynamo.config.suppress_errors = True |
| torch.set_float32_matmul_precision('high') |
|
|
| |
| chat = ChatTTS.Chat() |
| |
| |
| model_path = '/data/liyangzhuo/chattts/ChatTTS' |
| chat.load_models(source='local', local_path=model_path, compile=False) |
|
|
| |
| texts = [ |
| "今天天气真不错,阳光暖洋洋的,感觉整个人都充满了活力。", |
| ] |
|
|
| |
| print("正在生成音频...") |
| wavs = chat.infer(texts, use_decoder=True) |
| print("音频生成完毕。") |
|
|
| |
| |
| output_path = "output_from_local_repo1.wav" |
| tensor_to_save = torch.from_numpy(wavs[0]) |
|
|
| |
| print(f"原始numpy数组形状: {wavs[0].shape}") |
| print(f"用于保存的Tensor形状: {tensor_to_save.shape}") |
|
|
| torchaudio.save(output_path, tensor_to_save, 24000) |
| print(f"音频文件已成功保存至: {output_path}") |