Skip to content

Commit

Permalink
Fix: ui fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed Aug 1, 2024
1 parent 97969f4 commit 54109a6
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 24 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
HTTP_PROXY=
WEB_ADDRESS=127.0.0.1:9988
ENABLE_STS=0
DEVICE=CUDA
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ static/tmp/*.wav
static/ttslist/*.wav
*.pth
*.out
*.bin
*.bin
*.7z
27 changes: 18 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
load_dotenv()

web_address = os.getenv('WEB_ADDRESS', '127.0.0.1:9988')
enable_sts = int(os.getenv('ENABLE_STS', '0'))



updatecache()
Expand Down Expand Up @@ -385,7 +387,7 @@ def onoroff():
name = request.form.get("name",'')
status_new = request.form.get("status_new",'')
if status_new=='on':
if not cfg.MYMODEL_OBJS[name] or isinstance(cfg.MYMODEL_OBJS[name],str):
if name not in cfg.MYMODEL_OBJS or not cfg.MYMODEL_OBJS[name] or isinstance(cfg.MYMODEL_OBJS[name],str):
try:
print(f'start {name}...')
res=logic.load_model(name)
Expand All @@ -401,12 +403,17 @@ def onoroff():
cfg.MYMODEL_OBJS[name]=None
#删除队列
cfg.MYMODEL_QUEUE[name]=None
return jsonify({"code":0,"msg":"已启动"})
return jsonify({"code":0,"msg":"已停止"})

@app.route('/checkupdate', methods=['GET', 'POST'])
def checkupdate():
return jsonify({'code': 0, "msg": cfg.updatetips})

@app.route('/stsstatus', methods=['GET', 'POST'])
def stsstatus():
return jsonify({'code': 0, "msg": "start" if cfg.sts_status else "stop"})



if __name__ == '__main__':

Expand All @@ -419,24 +426,25 @@ def checkupdate():
threading.Thread(target=logic.checkupdate).start()

# 如果存在默认模型则启动

if TEXT_MODEL_EXITS:
print(langlist['lang2'])
print("\n"+langlist['lang2'])
tts_thread = threading.Thread(target=ttsloop)
tts_thread.start()
else:
app.logger.error(
f"\n{langlist['lang3']}: {cfg.download_address}\n")
input(f"\n{langlist['lang3']}: {cfg.download_address}\n")
sys.exit()

if VOICE_MODEL_EXITS:
if enable_sts==1 and VOICE_MODEL_EXITS:
print(langlist['lang4'])
sts_thread = threading.Thread(target=stsloop)
sts_thread.start()
else:
app.logger.error(
f"\n{langlist['lang5']}: {cfg.download_address}\n")

#else:
# app.logger.error(
# f"\n{langlist['lang5']}: {cfg.download_address}\n")
print(langlist['lang7'])
try:
host = web_address.split(':')
Expand All @@ -447,4 +455,5 @@ def checkupdate():
except Exception as e:
print("error:" + str(e))
app.logger.error(f"[app]start error:{str(e)}")
time.sleep(30)
sys.exit()
4 changes: 2 additions & 2 deletions clone/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION=907
ver="0.907"
VERSION=908
ver="0.908"
2 changes: 2 additions & 0 deletions clone/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def get_models(path):
MYMODEL_OBJS=get_models(MYMODEL_DIR)
MYMODEL_QUEUE={}

sts_status=False


device = "cuda" if os.getenv('DEVICE','')=='CUDA' and torch.cuda.is_available() else "cpu"
q = queue.Queue(maxsize=2000)
Expand Down
19 changes: 13 additions & 6 deletions clone/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def ttsloop():
if not cfg.setorget_proxy():
print(f'.env {langlist["lang12"]}')
else:
print(langlist['lang11'])
print("\n"+langlist['lang11']+"\n")
return
except Exception as e:
print(f'{langlist["lang13"]}:{str(e)}')
Expand Down Expand Up @@ -78,17 +78,21 @@ def ttsloop():
def stsloop():
try:
tts = TTS(model_name='voice_conversion_models/multilingual/vctk/freevc24').to(cfg.device)
print(langlist['lang10'])
print("\n"+langlist['lang10']+"\n")
except aiohttp.client_exceptions.ClientOSError as e:
cfg.sts_status=False
print(f'{langlist["lang9"]}{str(e)}')
if not cfg.setorget_proxy():
print(f'.env {langlist["lang12"]}')
else:
print(f'{os.environ.get("HTTP_PROXY")} {langlist["lang11"]}')
return
except Exception as e:
cfg.sts_status=False
print(f'{langlist["lang9"]}{str(e)}')
return
else:
cfg.sts_status=True
while 1:
try:
obj = cfg.q_sts.get(block=True, timeout=1)
Expand Down Expand Up @@ -196,8 +200,11 @@ def merge_audio_segments(text_list,is_srt=True):
def openweb(web_address):
while cfg.tts_n==0:
time.sleep(5)
webbrowser.open("http://"+web_address)
print(f"\n{langlist['lang8']} http://{web_address}")
try:
webbrowser.open("http://"+web_address)
print(f"\n{langlist['lang8']} http://{web_address}")
except Exception as e:
pass

# 判断是否符合字幕格式,如果是,则直接返回
# 从字幕文件获取格式化后的字幕信息
Expand Down Expand Up @@ -346,10 +353,10 @@ def get_subtitle_from_srt0(txt):
def checkupdate():
try:
res=requests.get("https://raw.githubusercontent.com/jianchang512/clone-voice/main/version.json")
print(f"{res.status_code=}")
#print(f"{res.status_code=}")
if res.status_code==200:
d=res.json()
print(f"{d=}")
#print(f"{d=}")
if d['version_num']>clone.VERSION:
cfg.updatetips=f'New version {d["version"]}'
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion code_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def updatecache():



ttsv2 = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
#ttsv2 = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)

tts = TTS(model_name='voice_conversion_models/multilingual/vctk/freevc24').to(device)

Expand Down
Binary file removed ffmpeg.7z
Binary file not shown.
4 changes: 3 additions & 1 deletion runapp.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@echo off

%cd%\venv\scripts\python.exe %cd%\app.py
%cd%\venv\scripts\python.exe %cd%\app.py

pause
39 changes: 36 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ <h4 class="alert-heading d-flex justify-content-between">
</div>
</div>
<div id="sts-area" class="d-none">
<div class="p-2">
<label for="audioSelect2" class="form-label">
<span data-en="The sound file to be clone:" data-cn="要克隆的音色:"></span>
</label>
<select class="form-select d-inline-block w-auto" id="audioSelect2"></select>
</div>
<div>
{% if voice_model %}
<div id="dropaudio" class=" border m-2 p-5 text-center "
Expand All @@ -275,6 +281,7 @@ <h4 class="alert-heading d-flex justify-content-between">
class="d-block" src="/static/images/2.png" width="300">
</div>
{% endif %}
<div class="alert alert-danger d-none" id="sts_no"></div>
</div>
</div>

Expand Down Expand Up @@ -570,7 +577,8 @@ <h4 class="alert-heading d-flex justify-content-between">
res.forEach(it => {
html += '<option value="' + it + '">' + it + '</option>'
})
$('#audioSelect').html(html)
$('#audioSelect').html(html);
$('#audioSelect2').html(html);
}
});
}
Expand Down Expand Up @@ -640,6 +648,7 @@ <h4 class="alert-heading d-flex justify-content-between">
fun_res(res);
});
} else {
voice = $("#audioSelect2").val();
$.post('/sts', {voice: voice, name: window['sts_audio_name']}, function (res) {
fun_res(res);
});
Expand Down Expand Up @@ -684,6 +693,25 @@ <h4 class="alert-heading d-flex justify-content-between">
fileInput.click();
});
}

function sts_status(){
$.get('/stsstatus', function (res) {
if (res.code === 0) {
if(res.msg=='stop'){
$('#sts_no').removeClass('d-none').text(language=='zh'?'声音转声音 线程未启动,如果已下载了模型,请打开 .env 文件将 ENABLE_STS=0 改为 ENABLE_STS=1,然后重启软件':'The sts model has not been launched yet, please download it and set .env ENABLE_STS=0 to ENABLE_STS=1 ');
if(!window.sts_time){
window.sts_time=0;
}
window.sts_time+=5
if(window.sts_time < 300){
setTimeout(sts_status,5000);
}
}else{
$('#sts_no').addClass('d-none').text("")
}
}
});
}


// 拖拽上传声音音频
Expand All @@ -692,7 +720,7 @@ <h4 class="alert-heading d-flex justify-content-between">
var formData = new FormData();
formData.append('audio', file);
formData.append('save_dir', 'tmp')

let index=layer.load()
$.ajax({
type: 'POST',
url: '/upload', // Update with your backend endpoint
Expand All @@ -712,9 +740,10 @@ <h4 class="alert-heading d-flex justify-content-between">
dropaudio.text('Error');
},
beforeSend: function () {
dropaudio.text('Upload...');
dropaudio.text(language==='zh'?'上传中请稍等..':'Uploading... ');
},
complete: function () {
layer.close(index)
dropaudio.removeClass('dragover');
}
});
Expand Down Expand Up @@ -777,12 +806,16 @@ <h4 class="alert-heading d-flex justify-content-between">
</div>`
});
}


init();
stsinit();
check_start();
checkupdate();
switch_language();
{% if voice_model %}
sts_status();
{% endif %}

</script>

Expand Down
2 changes: 1 addition & 1 deletion tts_cache/cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"https://github.com/coqui-ai/TTS/releases/download/v0.13.0_models/speaker_encoder.pt": {"original": "https://github.com/coqui-ai/TTS/releases/download/v0.13.0_models/speaker_encoder.pt", "fn": "d6c67f0e17e8737772c0a7172844fbe40ae535bea18eb69cb212f2adaee668dd", "blocks": true, "time": 1806670143.1189804, "uid": "baefdb5c88dc96918cc04cd7b006b262"}}
{"https://github.com/coqui-ai/TTS/releases/download/v0.13.0_models/speaker_encoder.pt": {"original": "https://github.com/coqui-ai/TTS/releases/download/v0.13.0_models/speaker_encoder.pt", "fn": "d6c67f0e17e8737772c0a7172844fbe40ae535bea18eb69cb212f2adaee668dd", "blocks": true, "time": 1822501807.932532, "uid": "baefdb5c88dc96918cc04cd7b006b262"}}

0 comments on commit 54109a6

Please sign in to comment.