MeloTTS
MeloTTS copied to clipboard
Generating using CPU is too slow
code:
from melo.api import TTS
import time
start_time=time.time()
# Speed is adjustable
speed = 1.0
device = 'cpu' # or cuda:0
text = "下面请 A 0 0 1 号用户到诊室P 0 0 1就诊"
model = TTS(language='ZH', device=device)
speaker_ids = model.hps.data.spk2id
output_path = 'zh.wav'
model.tts_to_file(text, speaker_ids['ZH'], output_path, speed=speed)
end_time = time.time() # 获取当前时间
elapsed_time = end_time - start_time # 计算运行时间
print("程序运行时间:", elapsed_time, "秒")
result:
> Text split to sentences.
下面请 A 0 0 1 号用户到诊室P 0 0 1就诊
> ===========================
0%| | 0/1 [00:00<?, ?it/s]Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
Loading model cost 0.759 seconds.
Prefix dict has been built successfully.
Some weights of the model checkpoint at bert-base-multilingual-uncased were not used when initializing BertForMaskedLM: ['cls.seq_relationship.bias', 'cls.seq_relationship.weight']
- This IS expected if you are initializing BertForMaskedLM from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing BertForMaskedLM from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
[W NNPACK.cpp:53] Could not initialize NNPACK! Reason: Unsupported hardware.
100%|███████████████████████████████████████████████████████████| 1/1 [02:25<00:00, 145.41s/it]
程序运行时间: 166.48126244544983 秒
For the first sentence of each language, it needs to download some models. The downloading process takes some time
我这边用推理的结果,大概是28s,使用windows的wsl安装的ubuntu 22子系统,不知道怎么确定有没有用到显卡推理