Skip to content

Commit

Permalink
fix: bugs and update
Browse files Browse the repository at this point in the history
  • Loading branch information
jianchang512 committed May 1, 2024
1 parent 5d31da3 commit 180b41a
Show file tree
Hide file tree
Showing 27 changed files with 537 additions and 383 deletions.
8 changes: 4 additions & 4 deletions requirements-cpu-or-mac.txt
Expand Up @@ -115,9 +115,9 @@ pyinstaller==6.6.0
pyinstaller-hooks-contrib==2024.4
pyparsing==3.1.1
pyreadline3==3.4.1
PySide6==6.6.1
PySide6-Addons==6.6.1
PySide6-Essentials==6.6.1
PySide6==6.7.0
PySide6_Addons==6.7.0
PySide6_Essentials==6.7.0
PySoundFile==0.9.0.post1
python-dateutil==2.8.2
pytz==2023.3.post1
Expand All @@ -135,7 +135,7 @@ rsa==4.9
samplerate==0.2.1
scikit-learn==1.3.2
scipy==1.11.3
shiboken6==6.6.1
shiboken6==6.7.0
six==1.16.0
sniffio==1.3.0
soundfile==0.12.1
Expand Down
8 changes: 4 additions & 4 deletions requirements-linux-gpu.txt
Expand Up @@ -115,9 +115,9 @@ pyinstaller==6.6.0
pyinstaller-hooks-contrib==2024.4
pyparsing==3.1.1
pyreadline3==3.4.1
PySide6==6.6.1
PySide6-Addons==6.6.1
PySide6-Essentials==6.6.1
PySide6==6.7.0
PySide6_Addons==6.7.0
PySide6_Essentials==6.7.0
PySoundFile==0.9.0.post1
python-dateutil==2.8.2
pytz==2023.3.post1
Expand All @@ -135,7 +135,7 @@ rsa==4.9
samplerate==0.2.1
scikit-learn==1.3.2
scipy==1.11.3
shiboken6==6.6.1
shiboken6==6.7.0
six==1.16.0
sniffio==1.3.0
soundfile==0.12.1
Expand Down
8 changes: 4 additions & 4 deletions requirements-win-gpu.txt
Expand Up @@ -115,9 +115,9 @@ pyinstaller==6.6.0
pyinstaller-hooks-contrib==2024.4
pyparsing==3.1.1
pyreadline3==3.4.1
PySide6==6.6.1
PySide6-Addons==6.6.1
PySide6-Essentials==6.6.1
PySide6==6.7.0
PySide6_Addons==6.7.0
PySide6_Essentials==6.7.0
PySoundFile==0.9.0.post1
python-dateutil==2.8.2
pytz==2023.3.post1
Expand All @@ -135,7 +135,7 @@ rsa==4.9
samplerate==0.2.1
scikit-learn==1.3.2
scipy==1.11.3
shiboken6==6.6.1
shiboken6==6.7.0
six==1.16.0
sniffio==1.3.0
soundfile==0.12.1
Expand Down
4 changes: 2 additions & 2 deletions videotrans/__init__.py
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

VERSION="v1.64"
VERSION_NUM=11064
VERSION="v1.66"
VERSION_NUM=11066
6 changes: 6 additions & 0 deletions videotrans/language/en.json
@@ -1,5 +1,11 @@
{
"translate_language": {
"chaochu255":"The original video path and name is too long, please shorten the video name and move it to a shorter path to avoid subsequent errors.",
"teshufuhao":"Please do not include any special symbols such as + & ? : | etc. in the path or name of the original video to avoid subsequent errors.",

"notjson": "Return response is not valid json data",
"fanyicuowu2": "The number of translation errors is more than half, please check",

"azureinfo": "Did you set the speech resource key and region values",

"yuchulichucuo": "Error in preprocessing stage",
Expand Down
6 changes: 6 additions & 0 deletions videotrans/language/es.json
@@ -1,5 +1,11 @@
{
"translate_language" : {
"chaochu255":"The original video path and name is too long, please shorten the video name and move it to a shorter path to avoid subsequent errors.",
"teshufuhao":"Please do not include any special symbols such as + & ? : | etc. in the path or name of the original video to avoid subsequent errors.",

"notjson": "Return response is not valid json data",
"fanyicuowu2": "The number of translation errors is more than half, please check",

"azureinfo": "Did you set the speech resource key and region values",

"yuchulichucuo": "Error in preprocessing stage",
Expand Down
8 changes: 7 additions & 1 deletion videotrans/language/zh.json
@@ -1,5 +1,11 @@
{
"translate_language": {
"chaochu255":"视频路径加名称过长,请缩短视频名称并移动到简短路径下,避免后续出错",
"teshufuhao":"视频路径或名称中请勿存在 + & ? : | 等特殊符号,以避免后续出错",

"notjson": "返回响应不是有效json数据",
"fanyicuowu2": "翻译出错数量超过一半,请检查",

"azureinfo": "必须正确填写 Azure TTS 的相关信息",

"yuchulichucuo": "预处理阶段出错",
Expand Down Expand Up @@ -236,7 +242,7 @@
"onlyruanzimu": "正在嵌入软字幕,无配音",
"zimuhangshu": "当前字幕行数 ",
"huituicpu": "GPU上执行出错,回退到CPU执行",
"zimuwenjianbuzhengque": "字幕文件不正确,尺寸是0",
"zimuwenjianbuzhengque": "字幕文件不正确,无有效字幕",
"mansuchucuo": "视频自动慢速出错,请尝试取消‘视频自动慢速’选项",
"qianyiwenjian": "路径或名称含有空格或特殊符号,为避免后续处理出错,将移动到"
},
Expand Down
17 changes: 15 additions & 2 deletions videotrans/mainwin/secwin.py
Expand Up @@ -674,7 +674,7 @@ def model_type_change(self):

# 判断模型是否存在
def check_whisper_model(self, name):
if self.main.model_type.currentIndex() == 2:
if self.main.model_type.currentIndex() in [2,3]:
return True
slang = self.main.source_language.currentText()
if name.endswith('.en') and translator.get_code(show_text=slang) != 'en':
Expand Down Expand Up @@ -1095,6 +1095,15 @@ def check_start(self):
# 视频自动减速
# 语音模型
config.params['whisper_model'] = self.main.whisper_model.currentText()
model_index=self.main.model_type.currentIndex()
if model_index==1:
config.params['model_type']='openai'
elif model_index==2:
config.params['model_type']='GoogleSpeech'
elif model_index==3:
config.params['model_type']='zh_recogn'
else:
config.params['model_type']='faster'
# 字幕嵌入类型
config.params['subtitle_type'] = int(self.main.subtitle_type.currentIndex())

Expand Down Expand Up @@ -1295,8 +1304,12 @@ def update_status(self, type):
# 更新 UI
def update_data(self, json_data):
d = json.loads(json_data)
if d['type']=='alert':
QMessageBox.critical(self.main, config.transobj['anerror'], d['text'])
return

# 一行一行插入字幕到字幕编辑区
if d['type'] == 'set_start_btn':
elif d['type'] == 'set_start_btn':
self.main.startbtn.setText(config.transobj["running"])
elif d['type'] == "subtitle":
self.main.subtitle_area.moveCursor(QTextCursor.End)
Expand Down
16 changes: 8 additions & 8 deletions videotrans/recognition/__init__.py
Expand Up @@ -625,13 +625,13 @@ def zh_recogn(audio_file=None, cache_folder=None, set_p=None, inst=None):
tools.set_process(f"识别可能较久,请耐心等待,进度可查看zh_recogn终端", 'logs',btnkey=inst.btnkey if inst else "")
try:
res=requests.post(f"{api_url}",files=files,proxies={"http":"","https":""},timeout=3600)
config.logger.info(f'clone-voice{res=}')
config.logger.info(f'zh_recogn:{res=}')
except Exception as e:
raise Exception(e)

res = res.json()
if "code" not in res or res['code'] != 0:
raise Exception(f'{res["msg"]}')
if "data" not in res or len(res['data'])<1:
raise Exception('识别出错')
return res['data']
else:
res = res.json()
if "code" not in res or res['code'] != 0:
raise Exception(f'{res["msg"]}')
if "data" not in res or len(res['data'])<1:
raise Exception('识别出错')
return res['data']
12 changes: 6 additions & 6 deletions videotrans/separate/st.py
Expand Up @@ -15,7 +15,7 @@
import hashlib


def uvr(*,model_name=None, save_root=None, inp_path=None,source="logs"):
def uvr(*,model_name=None, save_root=None, inp_path=None,source="logs",btnkey=None):
infos = []
try:
func = AudioPre
Expand All @@ -35,7 +35,7 @@ def uvr(*,model_name=None, save_root=None, inp_path=None,source="logs"):
need_reformat = 0
pre_fun._path_audio_(
inp_path,
ins_root=save_root
ins_root=save_root,btnkey=btnkey
)
done = 1
else:
Expand All @@ -60,15 +60,15 @@ def uvr(*,model_name=None, save_root=None, inp_path=None,source="logs"):
try:
if done == 0:
pre_fun._path_audio_(
inp_path, ins_root=save_root
inp_path, ins_root=save_root,btnkey=btnkey
)
infos.append("%s->Success" % (os.path.basename(inp_path)))
yield "\n".join(infos)
except:
try:
if done == 0:
pre_fun._path_audio_(
inp_path, ins_root=save_root
inp_path, ins_root=save_root,btnkey=btnkey
)
infos.append("%s->Success" % (os.path.basename(inp_path)))
yield "\n".join(infos)
Expand Down Expand Up @@ -106,13 +106,13 @@ def convert_to_pure_eng_num(string):


# path 是需要保存vocal.wav的目录
def start(audio,path,source="logs"):
def start(audio,path,source="logs",btnkey=None):
dist=int(config.settings['separate_sec'])
try:
# 获取总时长秒
sec=tools.get_audio_time(audio)
#if sec<=dist:
gr = uvr(model_name="HP2", save_root=path, inp_path=audio,source=source)
gr = uvr(model_name="HP2", save_root=path, inp_path=audio,source=source,btnkey=btnkey)
print(next(gr))
print(next(gr))
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions videotrans/separate/utils.py
Expand Up @@ -26,7 +26,7 @@ def make_padding(width, cropsize, offset):
return left, right, roi_size


def inference(X_spec, device, model, aggressiveness, data,source="logs"):
def inference(X_spec, device, model, aggressiveness, data,source="logs",btnkey=None):
"""
data : dic configs
"""
Expand All @@ -45,7 +45,7 @@ def _execute(
if source!='logs' and config.separate_status !='ing':
return
jd=(i+1)*100/n_window
tools.set_process(f"{config.transobj['Separating background music']} {round(jd,1)}%",source)
tools.set_process(f"{config.transobj['Separating background music']} {round(jd,1)}%",source,btnkey=btnkey)
print(f"{config.transobj['Separating background music']} {round(jd,1)}%")
start = i * roi_size
X_mag_window = X_mag_pad[
Expand Down
4 changes: 2 additions & 2 deletions videotrans/separate/vr.py
Expand Up @@ -39,7 +39,7 @@ def __init__(self, agg, model_path, device, is_half, tta=False,source="logs"):
self.model = model

def _path_audio_(
self, music_file, ins_root=None, format="wav", is_hp3=False
self, music_file, ins_root=None, format="wav", is_hp3=False,btnkey=None
):
if ins_root is None:
return "No save root."
Expand Down Expand Up @@ -104,7 +104,7 @@ def _path_audio_(
}
with torch.no_grad():
pred, X_mag, X_phase = inference(
X_spec_m, self.device, self.model, aggressiveness, self.data,self.source
X_spec_m, self.device, self.model, aggressiveness, self.data,self.source,btnkey=btnkey
)
# Postprocess
if self.data["postprocess"]:
Expand Down
14 changes: 13 additions & 1 deletion videotrans/task/main_worker.py
Expand Up @@ -9,6 +9,7 @@
from videotrans.util import tools
from videotrans.util.tools import set_process, send_notification
from pathlib import Path
import re


class Worker(QThread):
Expand Down Expand Up @@ -70,6 +71,16 @@ def run(self) -> None:
return self.stop()
# 格式化每个视频信息
obj_format = tools.format_video(it.replace('\\', '/'), config.params['target_dir'])
target_dir_mp4=obj_format['output']+f"/{obj_format['raw_noextname']}.mp4"
if len(target_dir_mp4)>=250:
set_process(config.transobj['chaochu255']+"\n\n"+it, 'alert')
self.stop()
return
if re.search(r'[\&\+\:\?\|]+',it[2:]):
set_process(config.transobj['teshufuhao']+"\n\n"+it, 'alert')
self.stop()
return

videolist.append(obj_format)
self.unidlist.append(obj_format['unid'])
# 添加进度按钮 unid
Expand Down Expand Up @@ -134,7 +145,7 @@ def run(self) -> None:
return self.stop()
video.dubbing()
except Exception as e:
err=f'{config.transobj["peyinchucuo"]}:' + str(e)
err=f'{config.transobj["peiyinchucuo"]}:' + str(e)
config.errorlist[video.btnkey]=err
set_process(err, 'error', btnkey=video.btnkey)
continue
Expand All @@ -152,6 +163,7 @@ def run(self) -> None:
return self.stop()
video.move_at_end()
except Exception as e:

err=f'{config.transobj["hebingchucuo"]}:' + str(e)
config.errorlist[video.btnkey]=err
set_process(err, 'error', btnkey=video.btnkey)
Expand Down

0 comments on commit 180b41a

Please sign in to comment.