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 23, 2024
1 parent 615f488 commit 9c04192
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 13 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ apt-get install ffmpeg
# 源码部署问题说明
1. 默认使用 ctranslate2的4.x版本,仅支持CUDA12.x版本,如果你的cuda低于12,并且无法升级cuda到12.x,请执行命令卸载ctranslate2然后重新安装
```

pip uninstall -y ctranslate2

pip install ctranslate2==3.24.0

```
2. 可能会遇到 `xx module not found ` 之类错误,请打开 requirements.txt,搜索该 xx 模块,然后将xx后的 ==及等会后的版本号去掉
# 使用教程和文档
请查看 https://pyvideotrans.com/guide.html
Expand Down
Binary file removed ffmpeg.zip
Binary file not shown.
5 changes: 5 additions & 0 deletions ffmpeg下载.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
windows������ffmpeg�󣬽�binĿ¼�µ� ffmpeg.exe��ffprobe.exe �ļ����Ƶ���ǰĿ¼�µ� ffmpeg �ļ�����

���ص�ַ

https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2023-11-30-12-55/ffmpeg-n6.0.1-win64-gpl-6.0.zip
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ click==7.1.2
colorama==0.4.6
coloredlogs==15.0.1
contourpy==1.1.1
ctranslate2==3.24.0
ctranslate2
cycler==0.12.1
decorator==4.4.2
deepl==1.16.1
Expand Down
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.78"
VERSION_NUM=110708
VERSION="v1.79"
VERSION_NUM=110709
90 changes: 88 additions & 2 deletions videotrans/box/win.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import shutil
from videotrans.ui.toolboxen import Ui_MainWindow
from videotrans.util.tools import get_azure_rolelist, get_edge_rolelist
from pathlib import Path


class MainWindow(QMainWindow, Ui_MainWindow):
Expand Down Expand Up @@ -120,6 +121,7 @@ def initUI(self):
self.hecheng_role.addItems(['No'])
self.hecheng_language.currentTextChanged.connect(self.hecheng_language_fun)
self.hecheng_startbtn.clicked.connect(self.hecheng_start_fun)
self.listen_btn.clicked.connect(self.listen_voice_fun)
self.hecheng_opendir.clicked.connect(lambda: self.opendir_fn(self.hecheng_out.text().strip()))
# 设置 tts_type
self.tts_type.addItems([i for i in config.params['tts_type_list']])
Expand Down Expand Up @@ -238,11 +240,24 @@ def fanyi_import_fun(self, obj=None):

def hecheng_import_fun(self):
fnames, _ = QFileDialog.getOpenFileNames(self, "Select srt", config.last_opendir,
"Text files(*.srt)")
"Text files(*.srt *.txt)")
if len(fnames) < 1:
return
for (i, it) in enumerate(fnames):
fnames[i] = it.replace('\\', '/').replace('file:///', '')
it=it.replace('\\', '/').replace('file:///', '')
if it.endswith('.txt'):
shutil.copy2(it,f'{it}.srt')
# 使用 "r+" 模式打开文件:读取和写入
with open(f'{it}.srt', 'r+', encoding='utf-8') as file:
# 读取原始文件内容
original_content = file.readlines()
# 将文件指针移动到文件开始位置
file.seek(0)
# 将新行内容与原始内容合并,并写入文件
file.writelines(["1\n","00:00:00,000 --> 05:00:00,000\n"] + original_content)

it+='.srt'
fnames[i] = it

if len(fnames) > 0:
config.last_opendir = os.path.dirname(fnames[0])
Expand Down Expand Up @@ -649,6 +664,73 @@ def disabled_shibie(self, type):
self.shibie_language.setDisabled(type)
self.shibie_model.setDisabled(type)


# 试听配音
def listen_voice_fun(self):
lang = translator.get_code(show_text=self.hecheng_language.currentText())
if not lang or lang=='-':
return QMessageBox.critical(self, config.transobj['anerror'], "选择字幕语言" if config.defaulelang=='zh' else 'Please target language')
text = config.params[f'listen_text_{lang}']
role = self.hecheng_role.currentText()
if not role or role == 'No':
return QMessageBox.critical(self, config.transobj['anerror'], config.transobj['mustberole'])
voice_dir = os.environ.get('APPDATA') or os.environ.get('appdata')
if not voice_dir or not Path(voice_dir).exists():
voice_dir = config.rootdir + "/tmp/voice_tmp"
else:
voice_dir = voice_dir.replace('\\', '/') + "/pyvideotrans"
if not Path(voice_dir).exists():
Path(voice_dir).mkdir(parents=True,exist_ok=True)
lujing_role = role.replace('/', '-')

rate = int(self.hecheng_rate.value())
tts_type = self.tts_type.currentText()

if rate >= 0:
rate = f"+{rate}%"
else:
rate = f"{rate}%"
volume=int(self.volume_rate.value())
pitch=int(self.pitch_rate.value())
volume=f'+{volume}%' if volume>=0 else f'{volume}%'
pitch=f'+{pitch}Hz' if pitch>=0 else f'{volume}Hz'



voice_file = f"{voice_dir}/{config.params['tts_type']}-{lang}-{lujing_role}-{volume}-{pitch}.mp3"
if config.params['tts_type'] == 'GPT-SoVITS':
voice_file += '.wav'

obj = {
"text": text,
"rate": '+0%',
"role": role,
"voice_file": voice_file,
"tts_type": config.params['tts_type'],
"language": lang,
"volume":volume,
"pitch":pitch,
}

if config.params['tts_type'] == 'clone-voice' and role == 'clone':
return
# 测试能否连接clone
if config.params['tts_type'] == 'clone-voice':
try:
tools.get_clone_role(set_p=True)
except:
QMessageBox.critical(self, config.transobj['anerror'],
config.transobj['You must deploy and start the clone-voice service'])
return

def feed(d):
QMessageBox.critical(self, config.transobj['anerror'], d)

from videotrans.task.play_audio import PlayMp3
t = PlayMp3(obj, self)
t.mp3_ui.connect(feed)
t.start()

# tab-4 语音合成
def hecheng_start_fun(self):
txt = self.hecheng_plaintext.toPlainText().strip()
Expand Down Expand Up @@ -700,6 +782,10 @@ def hecheng_start_fun(self):


issrt = self.tts_issrt.isChecked()
if len(self.hecheng_files)>0:
self.tts_issrt.setChecked(True)
issrt=True

self.hecheng_task = WorkerTTS(self,
files=self.hecheng_files if len(self.hecheng_files) > 0 else txt,
role=role,
Expand Down
10 changes: 5 additions & 5 deletions videotrans/box/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ def merge_audio_segments(self, *, segments=None, queue_tts=None, video_time=0, o
if diff >= 0:
it['end_time'] += diff
offset += diff
else:
#else:
# 配音小于原时长,添加静音
merged_audio += AudioSegment.silent(duration=abs(diff))
# merged_audio += AudioSegment.silent(duration=abs(diff))

if i > 0:
silence_duration = it['start_time'] - queue_tts[i - 1]['end_time']
Expand All @@ -495,10 +495,10 @@ def merge_audio_segments(self, *, segments=None, queue_tts=None, video_time=0, o
queue_tts[i] = it
merged_audio += segment

if video_time > 0 and (len(merged_audio) < video_time):
#if video_time > 0 and (len(merged_audio) < video_time):
# 末尾补静音
silence = AudioSegment.silent(duration=video_time - len(merged_audio))
merged_audio += silence
# silence = AudioSegment.silent(duration=video_time - len(merged_audio))
# merged_audio += silence
# 创建配音后的文件
try:
merged_audio.export(out, format="wav")
Expand Down
2 changes: 2 additions & 0 deletions videotrans/recognition/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def recogn(*,
if config.exit_soft or (config.current_status != 'ing' and config.box_recogn != 'ing'):
del model
return None
if not segment.words or len(segment.words)<1:
continue
sidx += 1
start = int(segment.words[0].start * 1000)
end = int(segment.words[-1].end * 1000)
Expand Down
7 changes: 7 additions & 0 deletions videotrans/ui/toolboxen.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ def setupUi(self, MainWindow):
self.hecheng_role.setObjectName("hecheng_role")
self.formLayout_4.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.hecheng_role)
self.horizontalLayout_10.addLayout(self.formLayout_4)

self.listen_btn = QtWidgets.QPushButton(self.tab_2)
self.listen_btn.setFixedWidth(80)
self.listen_btn.setToolTip(config.uilanglist.get("shuoming01"))
self.listen_btn.setText(config.uilanglist.get("Trial dubbing"))
self.horizontalLayout_10.addWidget(self.listen_btn)



self.formLayout_5 = QtWidgets.QFormLayout()
Expand Down
16 changes: 13 additions & 3 deletions videotrans/util/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,22 @@ def get_subtitle_from_srt(srtfile, *, is_file=True):
raise Exception(f'get srtfile error:{str(e)}')
else:
content = srtfile.strip().splitlines()
# remove whitespace
content=[c for c in content if c.strip()]

if len(content) < 1:
raise Exception("srt content is 0")

raise Exception("srt content is empty")
result = format_srt(content)

# txt 文件转为一条字幕
if len(result) < 1:
return []
if is_file and srtfile.endswith('.txt'):
result= [
{"line":1,"time":"00:00:00,000 --> 05:00:00,000","text":"\n".join(content)}
]
else:
return []

new_result = []
line = 1
Expand Down

0 comments on commit 9c04192

Please sign in to comment.