Closed JackyChan closed 2 months ago
You need to download models first and then give the model paths when chat.load_models().
here is my script to generate audio and output to file
import ChatTTS
import numpy as np
model_path = '/Users/zouguodong/.cache/modelscope/hub/pzc163/chatTTS'
chat = ChatTTS.Chat()
chat.load_models(
vocos_config_path=f"{model_path}/vocos.yaml",
vocos_ckpt_path=f"{model_path}/Vocos.pt",
dvae_config_path=f"{model_path}/dvae.yaml",
dvae_ckpt_path=f"{model_path}/DVAE.pt",
gpt_config_path=f"{model_path}/gpt.yaml",
gpt_ckpt_path=f"{model_path}/GPT.pt",
decoder_config_path=f"{model_path}/decoder.yaml",
decoder_ckpt_path=f"{model_path}/Decoder.pt",
tokenizer_path=f"{model_path}/tokenizer.pt",
device='cpu'
)
texts = ["Complaint", ]
wavs = chat.infer(texts, use_decoder=True)
audio_data = wavs[0]
audio_rate = 24000
# Convert numpy array to bytes
audio_data = (audio_data * 32767).astype(np.int16).tobytes()
# Save audio to file
output_filename = 'output_audio.wav'
with wave.open(output_filename, 'w') as wav_file:
wav_file.setnchannels(1) # Mono channel
wav_file.setsampwidth(2) # 2 bytes per sample (16-bit audio)
wav_file.setframerate(audio_rate)
wav_file.writeframes(audio_data)
print(f"Audio saved to {output_filename}")
发现感叹号、”-“会读出来 ,大家有遇到过吗?
文件save 到哪里去了呢? 找不到呀
building on @zou8944's instructions:
ensure Git LFS is installed on your system, then do git clone https://www.modelscope.cn/pzc163/chatTTS.git
and point at the models like so:
cwd = os.getcwd()
model_path = cwd + '/chatTTS'
chat.load_models(
vocos_config_path=f"{model_path}/config/vocos.yaml",
vocos_ckpt_path=f"{model_path}/asset/Vocos.pt",
dvae_config_path=f"{model_path}/config/dvae.yaml",
dvae_ckpt_path=f"{model_path}/asset/DVAE.pt",
gpt_config_path=f"{model_path}/config/gpt.yaml",
gpt_ckpt_path=f"{model_path}/asset/GPT.pt",
decoder_config_path=f"{model_path}/config/decoder.yaml",
decoder_ckpt_path=f"{model_path}/asset/Decoder.pt",
tokenizer_path=f"{model_path}/asset/tokenizer.pt",
device='cpu'
)
You need to download models first and then give the model paths when chat.load_models().
here is my script to generate audio and output to file
import ChatTTS import numpy as np model_path = '/Users/zouguodong/.cache/modelscope/hub/pzc163/chatTTS' chat = ChatTTS.Chat() chat.load_models( vocos_config_path=f"{model_path}/vocos.yaml", vocos_ckpt_path=f"{model_path}/Vocos.pt", dvae_config_path=f"{model_path}/dvae.yaml", dvae_ckpt_path=f"{model_path}/DVAE.pt", gpt_config_path=f"{model_path}/gpt.yaml", gpt_ckpt_path=f"{model_path}/GPT.pt", decoder_config_path=f"{model_path}/decoder.yaml", decoder_ckpt_path=f"{model_path}/Decoder.pt", tokenizer_path=f"{model_path}/tokenizer.pt", device='cpu' ) texts = ["Complaint", ] wavs = chat.infer(texts, use_decoder=True) audio_data = wavs[0] audio_rate = 24000 # Convert numpy array to bytes audio_data = (audio_data * 32767).astype(np.int16).tobytes() # Save audio to file output_filename = 'output_audio.wav' with wave.open(output_filename, 'w') as wav_file: wav_file.setnchannels(1) # Mono channel wav_file.setsampwidth(2) # 2 bytes per sample (16-bit audio) wav_file.setframerate(audio_rate) wav_file.writeframes(audio_data) print(f"Audio saved to {output_filename}")
Hello, I was wondering where I should put this code of yours to run? 你好,我想知道你的这段代码,我应该放到哪里去运行?
You need to download models first and then give the model paths when chat.load_models().
here is my script to generate audio and output to file
import ChatTTS import numpy as np model_path = '/Users/zouguodong/.cache/modelscope/hub/pzc163/chatTTS' chat = ChatTTS.Chat() chat.load_models( vocos_config_path=f"{model_path}/vocos.yaml", vocos_ckpt_path=f"{model_path}/Vocos.pt", dvae_config_path=f"{model_path}/dvae.yaml", dvae_ckpt_path=f"{model_path}/DVAE.pt", gpt_config_path=f"{model_path}/gpt.yaml", gpt_ckpt_path=f"{model_path}/GPT.pt", decoder_config_path=f"{model_path}/decoder.yaml", decoder_ckpt_path=f"{model_path}/Decoder.pt", tokenizer_path=f"{model_path}/tokenizer.pt", device='cpu' ) texts = ["Complaint", ] wavs = chat.infer(texts, use_decoder=True) audio_data = wavs[0] audio_rate = 24000 # Convert numpy array to bytes audio_data = (audio_data * 32767).astype(np.int16).tobytes() # Save audio to file output_filename = 'output_audio.wav' with wave.open(output_filename, 'w') as wav_file: wav_file.setnchannels(1) # Mono channel wav_file.setsampwidth(2) # 2 bytes per sample (16-bit audio) wav_file.setframerate(audio_rate) wav_file.writeframes(audio_data) print(f"Audio saved to {output_filename}")
I replaced the chat.load_models() with @benjamingwynn 's code. I am encountering this error while executing the code:-
Traceback (most recent call last):
File "C:\Users\Desktop\Workspace\Chat TTS\test1.py", line 23, in <module>
wavs = chat.infer(texts, use_decoder=True)
File "C:\Users\Desktop\Workspace\Chat TTS\.venv\lib\site-packages\ChatTTS\core.py", line 105, in infer
wav = [self.pretrain_models['vocos'].decode(i).cpu().numpy() for i in mel_spec]
File "C:\Users\Desktop\Workspace\Chat TTS\.venv\lib\site-packages\ChatTTS\core.py", line 105, in <listcomp>
wav = [self.pretrain_models['vocos'].decode(i).cpu().numpy() for i in mel_spec]
RuntimeError: Numpy is not available
WARNING:ChatTTS.utils.gpu_utils:No GPU found, use CPU instead INFO:ChatTTS.core:use cpu WARNING:ChatTTS.core:vocos not initialized. WARNING:ChatTTS.core:gpt not initialized. WARNING:ChatTTS.core:tokenizer not initialized. WARNING:ChatTTS.core:dvae not initialized. WARNING:ChatTTS.core:vocos not initialized. WARNING:ChatTTS.core:gpt not initialized. WARNING:ChatTTS.core:tokenizer not initialized. WARNING:ChatTTS.core:decoder not initialized. Traceback (most recent call last): File "/private/tmp/demo.py", line 9, in
wavs = chat.infer(texts, use_decoder=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Jacky/.venv/default/lib/python3.12/site-packages/ChatTTS/core.py", line 95, in infer
assert self.check_model(use_decoder=use_decoder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError