| import torch |
| import os |
| rootdir=os.getcwd() |
| os.environ['TTS_HOME']=rootdir |
|
|
| from TTS.api import TTS |
| from dotenv import load_dotenv |
| load_dotenv() |
|
|
| print("源码部署需要先运行该文件,以便同意coqou-ai协议,当弹出协议时,请输入 y \n同时需要连接墙外下载或更新模型,请在 .env 中 HTTP_PROXY=设置代理地址") |
|
|
| def updatecache(): |
| |
| file=os.path.join(rootdir,'tts_cache/cache') |
| if file: |
| import json,time |
| j=json.load(open(file,'r',encoding='utf-8')) |
| for i,it in enumerate(j): |
| if "time" in it and "fn" in it: |
| cache_file=os.path.join(rootdir,f'tts_cache/{it["fn"]}') |
| if os.path.exists(cache_file) and os.path.getsize(cache_file)>17000000: |
| it['time']=time.time() |
| j[i]=it |
| json.dump(j,open(file,'w',encoding='utf-8')) |
|
|
| updatecache() |
|
|
|
|
| device = "cuda" if torch.cuda.is_available() else "cpu" |
|
|
|
|
|
|
| |
|
|
| tts = TTS(model_name='voice_conversion_models/multilingual/vctk/freevc24').to(device) |
|
|
| |
| |
|
|
| |
|
|
| |
| |
|
|
|
|
|
|
|
|