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 Apr 29, 2024
1 parent dcf505f commit b005f0b
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 90 deletions.
3 changes: 3 additions & 0 deletions run2.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

call %cd%\\venv\\scripts\\python.exe app.py
4 changes: 2 additions & 2 deletions videotrans/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

VERSION="v1.62"
VERSION_NUM=11062
VERSION="v1.63"
VERSION_NUM=11063
5 changes: 1 addition & 4 deletions videotrans/azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ You are a language translation specialist who specializes in translating arbitra
### Skills ###

#### Skill 1: Translate text ####
- Recognizes user-entered text and translates it literally.

#### Skill 2: Abbreviate and condense translations ####
- Abbreviates and condenses translations, shortening translated sentences by 20% to 50% while keeping the meaning intact.
- Recognizes user-entered text and translates it literally, keeping the result short and concise


##################################
Expand Down
6 changes: 1 addition & 5 deletions videotrans/chatgpt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ You are a language translation specialist who specializes in translating arbitra
### Skills ###

#### Skill 1: Translate text ####
- Recognizes user-entered text and translates it literally.

#### Skill 2: Abbreviate and condense translations ####
- Abbreviates and condenses translations, shortening translated sentences by 20% to 50% while keeping the meaning intact.

- Recognizes user-entered text and translates it literally, keeping the result short and concise

##################################

Expand Down
3 changes: 2 additions & 1 deletion videotrans/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@
"uk": "Ukrainian",
"id": "Indonesian",
"ms": "Malay",
"kk": "Kazakh"
"kk": "Kazakh",
"cs":"Czech"
}
}
3 changes: 2 additions & 1 deletion videotrans/language/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@
"uk": "Ukrainian",
"id": "Indonesian",
"ms": "Malay",
"kk": "Kazakh"
"kk": "Kazakh",
"cs":"Czech"
}
}
5 changes: 3 additions & 2 deletions videotrans/language/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"What language do you want to translate into": "你希望翻译为哪种语言",
"Dubbing role": "配音角色",
"No is not dubbing": "选No代表不进行配音",
"From base to large v3, the effect is getting better and better, but the speed is also getting slower and slower": "base到large,效果越来越好,但也需要更多计算机资源,8G以下GPU不要使用large模型",
"From base to large v3, the effect is getting better and better, but the speed is also getting slower and slower": "从 tiny 到 large-v3,效果越来越好,但也需要更多计算机资源\nCUDA加速时,12G以下GPU不建议使用large系模型,可能闪退\nen后缀模型只用于识别英文视频",
"Overall recognition is suitable for videos with or without background music and noticeable silence": "整体识别适合有无背景音乐,有明显静音的视频。",
"Embed subtitles": "嵌入字幕",
"shuoming02": "硬字幕无论在哪里播放始终显示字幕,不可隐藏。\n软字幕如果播放器支持,可在播放器中控制显示或隐藏。\n如果你想网页中播放时显示字幕,请选择硬字幕。\n硬字幕可在 videotrans/set.ini 中修改fontsize控制大小",
Expand Down Expand Up @@ -411,6 +411,7 @@
"uk": "乌克兰语",
"id": "印度尼西亚",
"ms": "马来语",
"kk": "哈萨克语"
"kk": "哈萨克语",
"cs":"捷克语"
}
}
111 changes: 66 additions & 45 deletions videotrans/mainwin/secwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from videotrans import configure
from videotrans.task.job import start_thread
from videotrans.util import tools
from videotrans.translator import is_allow_translate, get_code, TRANSAPI_NAME, FREECHATGPT_NAME
from videotrans import translator
from videotrans.configure import config
from pathlib import Path

Expand Down Expand Up @@ -49,7 +49,10 @@ def __init__(self,parent=None):
def setTarget(self, url):
self.target_dir = url
def setMsg(self, text):
if text and config.defaulelang=='zh':
text+='\n\n请尝试在文档站 pyvideotrans.com 搜索错误解决方案\n'
self.msg = text


def setText(self, text):
if self.progress_bar:
Expand Down Expand Up @@ -601,14 +604,30 @@ def reset_timeid(self):
# 翻译渠道变化时,检测条件
def set_translate_type(self, name):
try:
rs = is_allow_translate(translate_type=name, only_key=True)
rs = translator.is_allow_translate(translate_type=name, only_key=True)
if rs is not True:
QMessageBox.critical(self.main, config.transobj['anerror'], rs)
if name == TRANSAPI_NAME:
if name == translator.TRANSAPI_NAME:
self.main.subform.set_transapi()
elif name == translator.CHATGPT_NAME:
self.main.subform.set_chatgpt_key()
elif name == translator.GEMINI_NAME:
self.main.subform.set_gemini_key()
elif name == translator.AZUREGPT_NAME:
self.main.subform.set_azure_key()
elif name == translator.BAIDU_NAME:
self.main.subform.set_transapi()
elif name == translator.TENCENT_NAME:
self.main.subform.set_transapi()
elif name == translator.DEEPL_NAME:
self.main.subform.set_transapi()
elif name == translator.DEEPLX_NAME:
self.main.subform.set_transapi()
elif name == translator.OTT_NAME:
self.main.subform.set_transapi()
return
config.params['translate_type'] = name
if name == FREECHATGPT_NAME:
if name == translator.FREECHATGPT_NAME:
self.main.translate_label1.show()
else:
self.main.translate_label1.hide()
Expand Down Expand Up @@ -638,7 +657,7 @@ def model_type_change(self):
self.main.whisper_type.setDisabled(True)
elif self.main.model_type.currentIndex() == 3:
lang=self.main.source_language.currentText()
if get_code(show_text=lang) not in ['zh-cn','zh-tw']:
if translator.get_code(show_text=lang) not in ['zh-cn','zh-tw']:
self.main.model_type.setCurrentIndex(0)
return QMessageBox.critical(self.main,config.transobj['anerror'],'zh_recogn 仅支持中文语音识别' if config.defaulelang=='zh' else 'zh_recogn Supports Chinese speech recognition only')

Expand All @@ -658,7 +677,7 @@ def check_whisper_model(self, name):
if self.main.model_type.currentIndex() == 2:
return True
slang = self.main.source_language.currentText()
if name.endswith('.en') and get_code(show_text=slang) != 'en':
if name.endswith('.en') and translator.get_code(show_text=slang) != 'en':
QMessageBox.critical(self.main, config.transobj['anerror'], config.transobj['enmodelerror'])
return False
if config.params['model_type'] == 'openai':
Expand Down Expand Up @@ -712,7 +731,7 @@ def tts_type_change(self, type):
self.main.tts_type.setCurrentText(config.params['tts_type_list'][0])
self.main.subform.set_gptsovits()
return
lang = get_code(show_text=self.main.target_language.currentText())
lang = translator.get_code(show_text=self.main.target_language.currentText())
if lang and lang != '-' and type == 'GPT-SoVITS' and lang[:2] not in ['zh', 'ja', 'en']:
self.main.tts_type.setCurrentText(config.params['tts_type_list'][0])
QMessageBox.critical(self.main, config.transobj['anerror'], config.transobj['nogptsovitslanguage'])
Expand Down Expand Up @@ -759,7 +778,7 @@ def tts_type_change(self, type):

# 试听配音
def listen_voice_fun(self):
lang = get_code(show_text=self.main.target_language.currentText())
lang = translator.get_code(show_text=self.main.target_language.currentText())
text = config.params[f'listen_text_{lang}']
role = self.main.voice_role.currentText()
if not role or role == 'No':
Expand Down Expand Up @@ -816,7 +835,7 @@ def set_voice_role(self, t):
role = self.main.voice_role.currentText()
# 如果tts类型是 openaiTTS,则角色不变
# 是edgeTTS时需要改变
code = get_code(show_text=t)
code = translator.get_code(show_text=t)
if code and code != '-' and config.params['tts_type'] == 'GPT-SoVITS' and code[:2] not in ['zh', 'ja', 'en']:
# 除此指望不支持
config.params['tts_type'] = 'edgeTTS'
Expand Down Expand Up @@ -1055,7 +1074,7 @@ def check_start(self):

# 原始语言
config.params['source_language'] = self.main.source_language.currentText()
if self.main.model_type.currentIndex==3 and get_code(show_text=config.params['source_language']) not in ['zh-cn','zh-tw']:
if self.main.model_type.currentIndex==3 and translator.get_code(show_text=config.params['source_language']) not in ['zh-cn','zh-tw']:
self.update_status('stop')
return QMessageBox.critical(self.main,config.transobj['anerror'],'zh_recogn 仅支持中文语音识别' if config.defaulelang=='zh' else 'zh_recogn Supports Chinese speech recognition only')
if self.main.model_type.currentIndex==3 and not config.params['zh_recogn_api']:
Expand Down Expand Up @@ -1159,7 +1178,7 @@ def check_start(self):
config.params['translate_type'] = self.main.translate_type.currentText()
# 如果需要翻译,再判断是否符合翻译规则
if not self.dont_translate():
rs = is_allow_translate(translate_type=config.params['translate_type'],
rs = translator.is_allow_translate(translate_type=config.params['translate_type'],
show_target=config.params['target_language'])
if rs is not True:
# 不是True,有错误
Expand Down Expand Up @@ -1197,42 +1216,44 @@ def check_start(self):

# 设置按钮上的日志信息
def set_process_btn_text(self, text, btnkey="", type="logs"):
if btnkey and btnkey in self.main.processbtns:
if btnkey != 'srt2wav' and btnkey not in self.main.task.tasklist:
return
if type == 'succeed':
text, basename = text.split('##')
self.main.processbtns[btnkey].setTarget(text)
if not btnkey or btnkey not in self.main.processbtns:
return
if not self.main.task:
return
if btnkey=='srt2wav' and self.main.task and self.main.task.video:
jindu = f' {round(self.main.task.video.precent, 1)}% '
self.main.processbtns[btnkey].progress_bar.setValue(int(self.main.task.video.precent))
raw_name = self.main.task.video.raw_basename
self.main.processbtns[btnkey].setText(f'{config.transobj["running"].replace("..", "")} [{jindu}] {raw_name} / {config.transobj["endopendir"]} {text}')
return

if type == 'succeed':
text, basename = text.split('##')
self.main.processbtns[btnkey].setTarget(text)
self.main.processbtns[btnkey].setCursor(Qt.PointingHandCursor)
text = f'{config.transobj["endandopen"]} {basename}'
self.main.processbtns[btnkey].setText(text)
self.main.processbtns[btnkey].progress_bar.setValue(100)
self.main.processbtns[btnkey].setToolTip(config.transobj['mubiao'])
elif type == 'error' or type == 'stop':
self.main.processbtns[btnkey].progress_bar.setStyleSheet('color:#ff0000')
if type=='error':
self.main.processbtns[btnkey].setCursor(Qt.PointingHandCursor)
text = f'{config.transobj["endandopen"]} {basename}'
self.main.processbtns[btnkey].setText(text)
self.main.processbtns[btnkey].progress_bar.setValue(100)
self.main.processbtns[btnkey].setToolTip(config.transobj['mubiao'])
elif type == 'error' or type == 'stop':
self.main.processbtns[btnkey].setStyleSheet('color:#ff0000')
self.main.processbtns[btnkey].progress_bar.setStyleSheet('color:#ff0000')
if type=='error':
self.main.processbtns[btnkey].setCursor(Qt.PointingHandCursor)
self.main.processbtns[btnkey].setMsg(
text+f'{config.errorlist[btnkey] if btnkey in config.errorlist else "" }'
)
self.main.processbtns[btnkey].setText(text[:180])
elif btnkey != 'srt2wav':
jindu = ""
if self.main.task and btnkey in self.main.task.tasklist:
jindu = f' {round(self.main.task.tasklist[btnkey].precent, 1)}% '
self.main.processbtns[btnkey].progress_bar.setValue(int(self.main.task.tasklist[btnkey].precent))
raw_name = self.main.task.tasklist[btnkey].raw_basename
self.main.processbtns[btnkey].setText(
f'{config.transobj["running"].replace("..", "")} [{jindu}] {raw_name} / {config.transobj["endopendir"]} {text}')
self.main.processbtns[btnkey].setMsg(
text+f'\n\n{config.errorlist[btnkey] if btnkey in config.errorlist and config.errorlist[btnkey]!=text else "" }'
)
self.main.processbtns[btnkey].setToolTip('点击查看详细报错' if config.defaulelang=='zh' else 'Click to view the detailed error report')
else:
jindu = ""
if self.main.task and self.main.task.video:
jindu = f' {round(self.main.task.video.precent, 1)}% '
self.main.processbtns[btnkey].progress_bar.setValue(int(self.main.task.video.precent))
raw_name = self.main.task.video.raw_basename
self.main.processbtns[btnkey].setText(
f'{config.transobj["running"].replace("..", "")} [{jindu}] {raw_name} / {config.transobj["endopendir"]} {text}')
self.main.processbtns[btnkey].setToolTip('')
self.main.processbtns[btnkey].setText(text[:120])
elif btnkey in self.main.task.tasklist:
jindu = f' {round(self.main.task.tasklist[btnkey].precent, 1)}% '
self.main.processbtns[btnkey].progress_bar.setValue(int(self.main.task.tasklist[btnkey].precent))
raw_name = self.main.task.tasklist[btnkey].raw_basename
self.main.processbtns[btnkey].setToolTip(config.transobj["endopendir"])
self.main.processbtns[btnkey].setText(
f'{config.transobj["running"].replace("..", "")} [{jindu}] {raw_name} / {config.transobj["endopendir"]} {text}')


# 更新执行状态
def update_status(self, type):
Expand Down
36 changes: 23 additions & 13 deletions videotrans/task/trans_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ def move_at_end(self):
# 如果移动了,删除移动后的文件
if self.obj and self.obj['output'] != self.obj['linshi_output']:
shutil.rmtree(self.obj['linshi_output'], ignore_errors=True)
# 提取时,删除
if self.app_mode=='tiqu':
Path(f'{self.obj["output"]}/{self.source_language_code}.srt').unlink(missing_ok=True)
Path(f'{self.obj["output"]}/{self.target_language_code}.srt').unlink(missing_ok=True)
#删除临时文件
shutil.rmtree(self.cache_folder, ignore_errors=True)
# 批量不允许编辑字幕
Expand Down Expand Up @@ -388,29 +392,29 @@ def recogn(self):
cache_folder=self.cache_folder,
is_cuda=self.config_params['cuda'],
inst=self)
self._unlink(self.shibie_audio)
except Exception as e:
msg = f'{str(e)}{str(e.args)}'
if re.search(r'cub[a-zA-Z0-9_.-]+?\.dll', msg, re.I | re.M) is not None:
msg = f'【缺少cuBLAS.dll】请点击菜单栏-帮助/支持-下载cublasxx.dll,或者切换为openai模型 ' if config.defaulelang == 'zh' else f'[missing cublasxx.dll] Open menubar Help&Support->Download cuBLASxx.dll or use openai model'
self.regcon_end = True
raise Exception(f'{msg}')
finally:
self._unlink(self.shibie_audio)


if not raw_subtitles or len(raw_subtitles) < 1:
self.regcon_end = True
self._unlink(self.shibie_audio)
raise Exception(self.obj['raw_basename'] + config.transobj['recogn result is empty'].replace('{lang}',
self.config_params['source_language']))
self._save_srt_target(raw_subtitles, self.targetdir_source_sub)
if self.obj and self.obj['output'] != self.obj['linshi_output']:
shutil.copy2(self.targetdir_source_sub, f'{self.obj["output"]}/{Path(self.targetdir_source_sub).name}')
# 仅提取字幕
if self.app_mode=='tiqu':
shutil.copy2(self.targetdir_source_sub, f'{self.obj["output"]}/{self.obj["raw_noextname"]}.srt')
if self.config_params['target_language'] == '-' or self.config_params['target_language'] == self.config_params['source_language']:
self.compose_end=True


# 删除识别音频
try:
os.unlink(self.shibie_audio)
except Exception:
pass
self._unlink(self.shibie_audio)
self.regcon_end = True
return True

Expand Down Expand Up @@ -453,9 +457,9 @@ def trans(self):
time.sleep(2)
# 如果不存在原字幕,或已存在目标语言字幕则跳过,比如使用已有字幕,无需翻译时
if not tools.vail_file(self.targetdir_source_sub) or tools.vail_file(self.targetdir_target_sub):
self.trans_end = True
if self.app_mode == 'tiqu':
self.compose_end = True
self.trans_end = True
if self.obj and self.obj['output']!=self.obj['linshi_output'] and tools.vail_file(self.targetdir_target_sub):
shutil.copy2(self.targetdir_target_sub,f'{self.obj["output"]}/{Path(self.targetdir_target_sub).name}')
return True
Expand All @@ -475,22 +479,28 @@ def trans(self):
inst=self,
source_code=self.source_language_code)
except Exception as e:
self.trans_end = True
raise Exception(e)
self._save_srt_target(target_srt, self.targetdir_target_sub)
if self.app_mode == 'tiqu':
self.compose_end = True
self.trans_end = True
if self.obj and self.obj['output'] != self.obj['linshi_output']:
shutil.copy2(self.targetdir_target_sub, f'{self.obj["output"]}/{Path(self.targetdir_target_sub).name}')
# 仅提取,该名字删原
if self.app_mode == 'tiqu':
shutil.copy2(self.targetdir_target_sub,f'{self.obj["output"]}/{self.obj["raw_noextname"]}-{self.target_language_code}.srt')
self.compose_end = True
return True

# 配音处理
def dubbing(self):
self.precent += 3
config.task_countdown = 0 if self.app_mode == 'biaozhun_jd' else config.settings['countdown_sec']
if self.app_mode in ['tiqu']:
self.compose_end=True
return True

# 不需要配音
if self.app_mode in ['tiqu', 'hebing'] or \
if self.app_mode in ['hebing'] or \
self.config_params['voice_role'] == 'No' or \
not tools.vail_file(self.targetdir_target_sub):
self.dubb_end = True
Expand Down

0 comments on commit b005f0b

Please sign in to comment.