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 Mar 11, 2024
1 parent e1a47b4 commit 0fdef96
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 52 deletions.
10 changes: 2 additions & 8 deletions about.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,12 @@ Contribute to the project to help with its ongoing maintenance
- 兔宝宝(QQ) / 2024-3-6 捐助 6.66 元
- 你De世界、只允许有(QQ) / 2024-3-6 捐助 10 元
- *雨(solielune) / 2024-3-7 捐助 199 元
<<<<<<< HEAD
- *式 / 2024-3-8 捐助 10 元
- *) / 2024-3-8 捐助 10 元
=======

- *~ / 2024-3-10 捐助 10 元
- *雀 / 2024-3-10 捐助 3 元

**未标注付款方式的即为微信支付,括号内标注为GitHub用户名,感谢所有支持者,软件的每一点进步都离不开您的支持和帮助。**





>>>>>>> a4b372ba35151676791c5fb6e78bd1274dd571c6

3 changes: 0 additions & 3 deletions ffmpeg/you-get.exe

This file was deleted.

Binary file added ffmpeg/ytdarwin
Binary file not shown.
Binary file added ffmpeg/ytlinux
Binary file not shown.
3 changes: 3 additions & 0 deletions ffmpeg/ytwin32.exe
Git LFS file not shown
9 changes: 4 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ pyinstaller==6.3.0
pyinstaller-hooks-contrib==2023.9
pyparsing==3.1.1
pyreadline3==3.4.1
PySide6==6.6.1
PySide6-Addons==6.6.1
PySide6-Essentials==6.6.1
PySide6==6.6.2
PySide6-Addons==6.6.2
PySide6-Essentials==6.6.2
PySoundFile==0.9.0.post1
python-dateutil==2.8.2
pytz==2023.3.post1
Expand Down Expand Up @@ -157,5 +157,4 @@ wcwidth==0.2.12
websockets==12.0
Werkzeug==3.0.1
wrapt==1.15.0
yarl==1.9.2
you-get==0.4.1650
yarl==1.9.2
13 changes: 11 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@
# # 如果是WAV音频流,获取原始音频数据
# with open("success.wav", 'wb') as f:
# f.write(response.content)
from videotrans.util import tools

tools.create_video_byimg(img="./101.jpg", fps=2, scale=[1116,628], totime="00:00:00.001", out="ceshi.mp4")







import requests
response = requests.get(url="https://transapi.pyvideotrans.com/?text=你好啊我的朋友们&source_language=zh&target_language=en&secret=123456")

print(response.json())
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.27 pyvideotrans.com"
VERSION_NUM=11027
VERSION="v1.29 pyvideotrans.com"
VERSION_NUM=11029
4 changes: 2 additions & 2 deletions videotrans/component/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from videotrans.component.set_form import BaiduForm, \
ChatgptForm, DeepLForm, DeepLXForm, TencentForm, ElevenlabsForm, InfoForm, AzureForm, GeminiForm, SetLineRole, \
YoutubeForm, OttForm,CloneForm,SeparateForm,TtsapiForm,GPTSoVITSForm
YoutubeForm, OttForm,CloneForm,SeparateForm,TtsapiForm,GPTSoVITSForm,TransapiForm

__all__ = [
"BaiduForm",
Expand All @@ -9,5 +9,5 @@
"DeepLXForm",
"TencentForm",
"ElevenlabsForm",
"InfoForm", "AzureForm", "GeminiForm", "SetLineRole", "ElevenlabsForm", "YoutubeForm","OttForm","CloneForm","SeparateForm","TtsapiForm"
"InfoForm", "AzureForm", "GeminiForm", "SetLineRole", "ElevenlabsForm", "YoutubeForm","OttForm","CloneForm","SeparateForm","TtsapiForm","TransapiForm"
]
9 changes: 9 additions & 0 deletions videotrans/component/set_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from videotrans.ui.setlinerole import Ui_setlinerole
from videotrans.ui.tencent import Ui_tencentform
from videotrans.ui.elevenlabs import Ui_elevenlabsform
from videotrans.ui.transapi import Ui_transapiform
from videotrans.ui.ttsapi import Ui_ttsapiform
from videotrans.ui.youtube import Ui_youtubeform
from videotrans.ui.separate import Ui_separateform
Expand Down Expand Up @@ -76,6 +77,14 @@ def __init__(self, parent=None):
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowIcon(QIcon(f"{config.rootdir}/videotrans/styles/icon.ico"))

class TransapiForm(QDialog, Ui_transapiform): # <===
def __init__(self, parent=None):
super(TransapiForm, self).__init__(parent)
self.setupUi(self)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowIcon(QIcon(f"{config.rootdir}/videotrans/styles/icon.ico"))


class GPTSoVITSForm(QDialog, Ui_gptsovitsform): # <===
def __init__(self, parent=None):
super(GPTSoVITSForm, self).__init__(parent)
Expand Down
9 changes: 8 additions & 1 deletion videotrans/configure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ def parse_init():


# 语言
defaulelang = locale.getdefaultlocale()[0][:2].lower()
try:
defaulelang = locale.getdefaultlocale()[0][:2].lower()
except:
defaulelang = "zh"

# 初始化一个字典变量
settings = parse_init()
# default language 如果 ini中设置了,则直接使用,否则自动判断
Expand Down Expand Up @@ -219,6 +223,9 @@ def parse_init():
"ttsapi_voice_role":"",
"ttsapi_extra":"pyvideotrans",

"trans_api_url":"",
"trans_secret":"",

"gptsovits_url":"",
"gptsovits_role":"",
"gptsovits_extra":"pyvideotrans"
Expand Down
2 changes: 2 additions & 0 deletions videotrans/language/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"translate_language": {
"qiegeshujuhaoshi": "If the video is very large, this step will be time-consuming, so please be patient.",
"youtubehasdown": "The download has begun, please check the progress in the pop-up download interface, WARNING: message do not need to pay attention to, just ignore it!",
"starting...": "Processing will start and progress will be shown later",
"dubbing speed up": "Dub speed up",
"video speed down": "Video slowdown",
Expand Down
2 changes: 2 additions & 0 deletions videotrans/language/es.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"translate_language" : {
"qiegeshujuhaoshi": "If the video is very large, this step will be time-consuming, so please be patient.",
"youtubehasdown": "The download has begun, please check the progress in the pop-up download interface, WARNING: message do not need to pay attention to, just ignore it!",
"starting...": "Processing will start and progress will be shown later",
"dubbing speed up": "Dub speed up",
"video speed down": "Video slowdown",
Expand Down
4 changes: 3 additions & 1 deletion videotrans/language/zh.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"translate_language": {
"qiegeshujuhaoshi": "若视频很大,此步会比较耗时,请耐心等待",
"youtubehasdown": "已开始下载,请在控制台界面中查看具体进度,WARNING:信息无需理会\n点击保存目录按钮后的文本框可打开下载文件保存目录",
"starting...": "开始处理,稍后显示进度,请耐心等待",
"dubbing speed up": "配音加速 ",
"video speed down": "视频慢放 ",
Expand Down Expand Up @@ -41,7 +43,7 @@
"Click to start the next step immediately": "点击立即开始执行下一步操作",
"zimubianjitishi": "出现暂停按钮并点击暂停后,可在此修改字幕,以便处理更准确",
"test google": "正在测试连接..",
"Select Out Dir": "下载到..",
"Select Out Dir": "选择保存目录",
"downing...": "下载中...",
"start download": "立即下载",
"Down done succeed": "下载完成",
Expand Down
83 changes: 77 additions & 6 deletions videotrans/mainwin/secwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from videotrans.task.separate_worker import SeparateWorker
from videotrans.util import tools
warnings.filterwarnings('ignore')
from videotrans.translator import is_allow_translate, get_code
from videotrans.translator import is_allow_translate, get_code, TRANSAPI_NAME
from videotrans.util.tools import show_popup, set_proxy, get_edge_rolelist, get_elevenlabs_role, get_subtitle_from_srt, get_clone_role
from videotrans.configure import config

Expand Down Expand Up @@ -744,8 +744,7 @@ def download():
from videotrans.task.download_youtube import Download
down = Download(proxy=proxy,url=url,out=outdir, parent=self.main)
down.start()
self.main.youw.set.setDisabled(True)

self.main.youw.set.setText(config.transobj["downing..."])
def selectdir():
dirname = QFileDialog.getExistingDirectory(self.main, "Select Dir", outdir).replace('\\', '/')
self.main.youw.outputdir.setText(dirname)
Expand Down Expand Up @@ -1041,7 +1040,17 @@ def feed(d):
self.main.ttsapiw.test.setText('测试api' if config.defaulelang=='zh' else 'Test api')
def test():
url = self.main.ttsapiw.api_url.text()
extra = self.main.ttsapiw.extra.text()
role = self.main.ttsapiw.voice_role.text().strip()

self.main.settings.setValue("ttsapi_url", url)
self.main.settings.setValue("ttsapi_extra", extra if extra else "pyvideotrans")
self.main.settings.setValue("ttsapi_voice_role", role)

config.params["ttsapi_url"] = url
config.params["ttsapi_extra"] = extra
config.params["ttsapi_voice_role"] = role

task=TestTTS(parent=self.main.ttsapiw,
text="你好啊我的朋友" if config.defaulelang=='zh' else 'hello,my friend',
role=self.main.ttsapiw.voice_role.text().strip().split(',')[0],
Expand Down Expand Up @@ -1079,6 +1088,66 @@ def save():
self.main.ttsapiw.test.clicked.connect(test)
self.main.ttsapiw.show()

def set_transapi(self):
class Test(QThread):
uito = Signal(str)
def __init__(self, *,parent=None,text=None):
super().__init__(parent=parent)
self.text=text

def run(self):
from videotrans.translator.transapi import trans
try:
print('start')

t=trans(self.text, target_language="en", set_p=False,source_code="zh",is_test=True)
self.uito.emit(f"ok:{self.text}\n{t}")
except Exception as e:
print(e)
self.uito.emit(str(e))
def feed(d):
if d.startswith("ok:"):
QMessageBox.information(self.main.transapiw,"ok",d[3:])
else:
QMessageBox.critical(self.main.transapiw,config.transobj['anerror'],d)
self.main.transapiw.test.setText('测试api' if config.defaulelang=='zh' else 'Test api')
def test():
url = self.main.transapiw.api_url.text()
config.params["ttsapi_url"] = url
if not url:
return QMessageBox.critical(self.main.transapiw,config.transobj['anerror'],"必须填写自定义翻译的url" if config.defaulelang=='zh' else "The url of the custom translation must be filled in")
url = self.main.transapiw.api_url.text()
miyue = self.main.transapiw.miyue.text()
self.main.settings.setValue("trans_api_url", url)
self.main.settings.setValue("trans_secret", miyue)
config.params["trans_api_url"] = url
config.params["trans_secret"] = miyue
task=Test(parent=self.main.transapiw, text="你好啊我的朋友")
self.main.transapiw.test.setText('测试中请稍等...' if config.defaulelang=='zh' else 'Testing...')
task.uito.connect(feed)
task.start()

def save():
url = self.main.transapiw.api_url.text()
miyue = self.main.transapiw.miyue.text()
self.main.settings.setValue("trans_api_url", url)
self.main.settings.setValue("trans_secret", miyue)
config.params["trans_api_url"] = url
config.params["trans_secret"] = miyue
self.main.transapiw.close()

from videotrans.component import TransapiForm
self.main.transapiw = TransapiForm()
if config.params["trans_api_url"]:
self.main.transapiw.api_url.setText(config.params["trans_api_url"])
if config.params["trans_secret"]:
self.main.transapiw.miyue.setText(config.params["trans_secret"])

self.main.transapiw.save.clicked.connect(save)
self.main.transapiw.test.clicked.connect(test)
self.main.transapiw.show()


def set_gptsovits(self):
class TestTTS(QThread):
uito = Signal(str)
Expand Down Expand Up @@ -1224,6 +1293,9 @@ def set_translate_type(self, name):
rs = 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:
self.set_transapi()

return
config.params['translate_type'] = name
except Exception as e:
Expand Down Expand Up @@ -1845,9 +1917,8 @@ def update_data(self, json_data):
self.usetype.setText(d['text'])

elif d['type'] == 'update_download' and self.main.youw is not None:
if d['text']=='ok' or d['text'].find('[error]')>-1:
self.main.youw.set.setDisabled(False)
self.main.youw.logs.setText(config.transobj['Down done succeed'] if d['text'] == 'ok' else f"{d['text']}")
self.main.youw.logs.setText(config.transobj['youtubehasdown'])
self.main.youw.set.setText(config.transobj['start download'])
elif d['type'] == 'open_toolbox':
self.open_toolbox(0, True)
elif d['type']=='set_clone_role' and config.params['tts_type']=='clone-voice':
Expand Down
4 changes: 4 additions & 0 deletions videotrans/mainwin/spwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def bind_action(self):
self.actionott_address.triggered.connect(self.util.set_ott_address)
self.actionclone_address.triggered.connect(self.util.set_clone_address)
self.actiontts_api.triggered.connect(self.util.set_ttsapi)
self.actiontrans_api.triggered.connect(self.util.set_transapi)
self.actiontts_gptsovits.triggered.connect(self.util.set_gptsovits)
self.action_ffmpeg.triggered.connect(lambda: self.util.open_url('ffmpeg'))
self.action_git.triggered.connect(lambda: self.util.open_url('git'))
Expand Down Expand Up @@ -421,6 +422,9 @@ def get_setting(self):
config.params["ttsapi_extra"] = self.settings.value("ttsapi_extra", "pyvideotrans")
config.params["ttsapi_voice_role"] = self.settings.value("ttsapi_voice_role", "")

config.params["trans_api_url"] = self.settings.value("trans_api_url", "")
config.params["trans_secret"] = self.settings.value("trans_secret", "")

config.params["gptsovits_url"] = self.settings.value("gptsovits_url", "")
config.params["gptsovits_extra"] = self.settings.value("gptsovits_extra", "pyvideotrans")
config.params["gptsovits_role"] = self.settings.value("gptsovits_role", "")
Expand Down
11 changes: 6 additions & 5 deletions videotrans/recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def all_recogn(*, detect_language=None, audio_file=None, cache_folder=None,model
wavfile=audio_file
if not os.path.exists(wavfile):
raise Exception(f'[error]not exists {wavfile}')
print(f"bbadas{bool(config.settings['vad'])}")
segments, info = model.transcribe(wavfile,
beam_size=config.settings['beam_size'],
best_of=config.settings['best_of'],
Expand Down Expand Up @@ -174,6 +173,9 @@ def split_recogn(*, detect_language=None, audio_file=None, cache_folder=None,mod
else:
if config.current_status != 'ing' and config.box_recogn != 'ing':
raise config.Myexcept("stop")
if inst and inst.precent < 55:
inst.precent += 0.1
tools.set_process(config.transobj['qiegeshujuhaoshi'])
nonsilent_data = shorten_voice(normalized_sound)
with open(nonslient_file, 'w') as outfile:
json.dump(nonsilent_data, outfile)
Expand All @@ -188,14 +190,10 @@ def split_recogn(*, detect_language=None, audio_file=None, cache_folder=None,mod
except Exception as e:
raise Exception(str(e.args))
for i, duration in enumerate(nonsilent_data):
print(f'{duration=}')
# config.temp = {}
if config.current_status != 'ing' and config.box_recogn != 'ing':
del model
return None
start_time, end_time, buffered = duration
# if start_time == end_time:
# end_time += 200

chunk_filename = tmp_path + f"/c{i}_{start_time // 1000}_{end_time // 1000}.wav"
audio_chunk = normalized_sound[start_time:end_time]
Expand Down Expand Up @@ -322,6 +320,9 @@ def split_recogn_openai(*, detect_language=None, audio_file=None, cache_folder=N
else:
if config.current_status != 'ing' and config.box_recogn != 'ing':
raise config.Myexcept("stop")
if inst and inst.precent < 55:
inst.precent += 0.1
tools.set_process(config.transobj['qiegeshujuhaoshi'])
nonsilent_data = shorten_voice_old(normalized_sound)
with open(nonslient_file, 'w') as outfile:
json.dump(nonsilent_data, outfile)
Expand Down
18 changes: 8 additions & 10 deletions videotrans/task/download_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ def __init__(self, *,url=None,proxy=None,out=None,parent=None):

def run(self):
set_process(config.transobj["downing..."],'update_download')
from you_get.extractors import youtube
try:
youtube.download(self.url,
output_dir=self.out,
merge=True,
extractor_proxy=self.proxy if self.proxy.startswith("http") or self.proxy.startswith('sock') else None
)
except Exception as e:
set_process("[error]"+str(e),'update_download')
pwd=config.rootdir+f"/ffmpeg/yt{sys.platform}"
proxy=self.proxy if self.proxy.startswith("http") or self.proxy.startswith('sock') else None
proxy="" if not proxy else f' --proxy {proxy} '
cmd=f'{pwd} -c -P {self.out} {proxy} --windows-filenames --force-overwrites --ignore-errors --merge-output-format mp4 {self.url}'
print(f'{cmd=}')
subprocess.run(cmd)

return
set_process('ok','update_download')
except Exception as e:
pass
Loading

0 comments on commit 0fdef96

Please sign in to comment.