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 30, 2024
1 parent fd558c2 commit 993f262
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 50 deletions.
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.81"
VERSION_NUM=110781
VERSION="v1.82"
VERSION_NUM=110782
64 changes: 24 additions & 40 deletions videotrans/box/win.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,36 +129,7 @@ def initUI(self):
self.tts_type.currentTextChanged.connect(self.tts_type_change)
self.tts_issrt.stateChanged.connect(self.tts_issrt_change)

# tab-5 格式转换
# self.geshi_input = TextGetdir()
# sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
# sizePolicy.setHorizontalStretch(0)
# sizePolicy.setVerticalStretch(0)
# sizePolicy.setHeightForWidth(self.geshi_result.sizePolicy().hasHeightForWidth())
# self.geshi_input.setSizePolicy(sizePolicy)
# self.geshi_input.setMinimumSize(300, 0)
#
# self.geshi_input.setPlaceholderText(config.transobj['tuodongdaoci'])
#
# self.geshi_importbtn = QtWidgets.QPushButton(self.tab_6)
# self.geshi_importbtn.setObjectName("geshi_importbtn")
# self.geshi_importbtn.setFixedWidth(100)
# self.geshi_importbtn.setText(config.box_lang['import audio or video'])
# self.geshi_importbtn.clicked.connect(lambda: self.geshi_import_fun(self.geshi_input))
# self.horizontalLayout_14.insertWidget(0, self.geshi_importbtn)
#
# self.geshi_layout.insertWidget(0, self.geshi_input)
# self.geshi_mp4.clicked.connect(lambda: self.geshi_start_fun("mp4"))
# self.geshi_avi.clicked.connect(lambda: self.geshi_start_fun("avi"))
# self.geshi_mov.clicked.connect(lambda: self.geshi_start_fun("mov"))
# self.geshi_mp3.clicked.connect(lambda: self.geshi_start_fun("mp3"))
# self.geshi_wav.clicked.connect(lambda: self.geshi_start_fun("wav"))
# self.geshi_aac.clicked.connect(lambda: self.geshi_start_fun("aac"))
# self.geshi_m4a.clicked.connect(lambda: self.geshi_start_fun("m4a"))
# self.geshi_flac.clicked.connect(lambda: self.geshi_start_fun("flac"))
# self.geshi_output.clicked.connect(lambda: self.opendir_fn(f'{config.homedir}/conver'))
# if not os.path.exists(f'{config.homedir}/conver'):
# os.makedirs(f'{config.homedir}/conver', exist_ok=True)


# 混流
self.hun_file1btn.clicked.connect(lambda: self.hun_get_file('file1'))
Expand Down Expand Up @@ -698,7 +669,7 @@ def listen_voice_fun(self):


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

obj = {
Expand Down Expand Up @@ -753,6 +724,13 @@ def hecheng_start_fun(self):
self.tts_type.setCurrentText('edgeTTS')
QMessageBox.critical(self, config.transobj['anerror'], config.transobj['nogptsovitslanguage'])
return
if tts_type == 'ChatTTS' and langcode[:2] not in ['zh', 'en']:
# 除此指望不支持
config.params['tts_type'] = 'edgeTTS'
self.tts_type.setCurrentText('edgeTTS')
QMessageBox.critical(self, config.transobj['anerror'], config.transobj['onlycnanden'])
return

if rate >= 0:
rate = f"+{rate}%"
else:
Expand Down Expand Up @@ -822,10 +800,17 @@ def tts_type_change(self, type):
self.volume_rate.setDisabled(True)
self.pitch_rate.setDisabled(True)


code = translator.get_code(show_text=self.hecheng_language.currentText())
if type == 'gtts':
self.hecheng_role.clear()
self.hecheng_role.addItems(['gtts'])
elif type=='ChatTTS':
if code and code != '-' and code[:2] not in ['zh', 'en']:
self.tts_type.setCurrentText('edgeTTS')
QMessageBox.critical(self, config.transobj['anerror'], config.transobj['onlycnanden'])
return
self.hecheng_role.clear()
self.hecheng_role.addItems(['No']+list(config.ChatTTS_voicelist.keys()) )
elif type == "openaiTTS":
self.hecheng_role.clear()
self.hecheng_role.addItems(config.params['openaitts_role'].split(","))
Expand All @@ -844,7 +829,6 @@ def tts_type_change(self, type):
self.hecheng_role.clear()
self.hecheng_role.addItems(config.params['ttsapi_voice_role'].split(","))
elif type == 'GPT-SoVITS':
code = translator.get_code(show_text=self.hecheng_language.currentText())
if code and code != '-' and code[:2] not in ['zh', 'ja', 'en']:
self.tts_type.setCurrentText('edgeTTS')
QMessageBox.critical(self, config.transobj['anerror'], config.transobj['nogptsovitslanguage'])
Expand All @@ -860,6 +844,13 @@ def hecheng_language_fun(self, t):
# 除此指望不支持
QMessageBox.critical(self, config.transobj['anerror'], config.transobj['nogptsovitslanguage'])
self.tts_type.setCurrentText('edgeTTS')
return
if code and code != '-' and self.tts_type.currentText() == 'ChatTTS' and code[:2] not in ['zh', 'en']:
self.tts_type.setCurrentText('edgeTTS')
# 除此指望不支持
QMessageBox.critical(self, config.transobj['anerror'], config.transobj['onlycnanden'])
return

if self.tts_type.currentText() not in ["edgeTTS", "AzureTTS"]:
return
self.hecheng_role.clear()
Expand Down Expand Up @@ -908,13 +899,6 @@ def hun_fun(self):
file1 = self.hun_file1.text()
file2 = self.hun_file2.text()

#rs, newfile1, _ = tools.rename_move(file1, is_dir=False)
#if rs:
# file1 = newfile1
#rs, newfile2, _ = tools.rename_move(file2, is_dir=False)
#if rs:
# file2 = newfile2

cmd = ['-y', '-i', file1, '-i', file2, '-filter_complex',
"[0:a][1:a]amix=inputs=2:duration=first:dropout_transition=2", '-ac', '2', savename]
self.geshi_task = Worker([cmd], "hunhe", self)
Expand Down
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,TransapiForm,ArticleForm,AzurettsForm,ZhrecognForm
YoutubeForm, OttForm,CloneForm,SeparateForm,TtsapiForm,GPTSoVITSForm,TransapiForm,ArticleForm,AzurettsForm,ZhrecognForm,ChatttsForm

__all__ = [
"BaiduForm",
Expand All @@ -9,5 +9,5 @@
"DeepLXForm",
"TencentForm",
"ElevenlabsForm",
"InfoForm", "AzureForm", "GeminiForm", "SetLineRole", "ElevenlabsForm", "YoutubeForm","OttForm","CloneForm","SeparateForm","TtsapiForm","TransapiForm","ArticleForm","AzurettsForm","ZhrecognForm"
"InfoForm", "AzureForm", "GeminiForm", "SetLineRole", "ElevenlabsForm", "YoutubeForm","OttForm","CloneForm","SeparateForm","TtsapiForm","TransapiForm","ArticleForm","AzurettsForm","ZhrecognForm","ChatttsForm"
]
7 changes: 7 additions & 0 deletions videotrans/component/set_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from videotrans.ui.azure import Ui_azureform
from videotrans.ui.baidu import Ui_baiduform
from videotrans.ui.chatgpt import Ui_chatgptform
from videotrans.ui.chattts import Ui_chatttsform
from videotrans.ui.deepl import Ui_deeplform
from videotrans.ui.deeplx import Ui_deeplxform
from videotrans.ui.gptsovits import Ui_gptsovitsform
Expand Down Expand Up @@ -155,6 +156,12 @@ def __init__(self, parent=None):
self.setupUi(self)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowIcon(QIcon(f"{config.rootdir}/videotrans/styles/icon.ico"))
class ChatttsForm(QDialog, Ui_chatttsform): # <===
def __init__(self, parent=None):
super(ChatttsForm, self).__init__(parent)
self.setupUi(self)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.setWindowIcon(QIcon(f"{config.rootdir}/videotrans/styles/icon.ico"))

class ZhrecognForm(QDialog, Ui_zhrecognform): # <===
def __init__(self, parent=None):
Expand Down
4 changes: 3 additions & 1 deletion videotrans/configure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def parse_init():

clone_voicelist=["clone"]

ChatTTS_voicelist={"boy1":2222,"boy2":7869,"boy3":6653,"girl1":4099,"girl2":5099}

openaiTTS_rolelist = "alloy,echo,fable,onyx,nova,shimmer"
chatgpt_model_list = [ it.strip() for it in settings['chatgpt_model'].split(',')]
# 存放 edget-tts 角色列表
Expand Down Expand Up @@ -227,7 +229,7 @@ def parse_init():
"listen_text_hu": "Helló kedves barátom. Remélem minden napod szép és kellemes!",

"tts_type": "edgeTTS", # 所选的tts==edge-tts:openaiTTS|coquiTTS|elevenlabsTTS
"tts_type_list": ["edgeTTS","gtts","AzureTTS", "GPT-SoVITS","clone-voice","openaiTTS", "elevenlabsTTS","TTS-API"],
"tts_type_list": ["edgeTTS","ChatTTS","gtts","AzureTTS", "GPT-SoVITS","clone-voice","openaiTTS", "elevenlabsTTS","TTS-API"],

"whisper_type": "all",
"whisper_model": "tiny",
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": {
"onlycnanden": "ChatTTS only support Chinese and English",

"peiyindayu31": "The number of dubbing errors is greater than 1/3, please check the",

"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.",
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" : {
"onlycnanden": "ChatTTS only support Chinese and English",

"peiyindayu31": "The number of dubbing errors is greater than 1/3, please check the",

"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.",
Expand Down
2 changes: 2 additions & 0 deletions videotrans/language/zh.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"translate_language": {
"onlycnanden": "ChatTTS仅支持中文和英文配音",

"peiyindayu31": "配音出错数量大于1/3,请检查",

"chaochu255":"视频路径加名称过长,请缩短视频名称并移动到简短路径下,避免后续出错",
Expand Down
29 changes: 25 additions & 4 deletions videotrans/mainwin/secwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,18 +772,26 @@ def tts_type_change(self, type):
self.main.tts_type.setCurrentText(config.params['tts_type_list'][0])
self.main.subform.set_gptsovits()
return
if type == 'ChatTTS' and not config.params['chattts_api']:
self.main.tts_type.setCurrentText(config.params['tts_type_list'][0])
self.main.subform.set_chattts_address()
return

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'])
return
if lang and lang != '-' and type == 'ChatTTS' and lang[:2] not in ['zh', 'en']:
self.main.tts_type.setCurrentText(config.params['tts_type_list'][0])
QMessageBox.critical(self.main, config.transobj['anerror'], config.transobj['onlycnanden'])
return

config.params['tts_type'] = type
config.params['line_roles'] = {}
if type=='gtts':
self.main.voice_role.clear()
self.main.current_rolelist = ["gtts"]

self.main.voice_role.addItems(self.main.current_rolelist)
elif type == "openaiTTS":
self.main.voice_role.clear()
Expand All @@ -806,7 +814,10 @@ def tts_type_change(self, type):
self.main.current_rolelist = config.clone_voicelist
self.main.voice_role.addItems(self.main.current_rolelist)
threading.Thread(target=tools.get_clone_role).start()

elif type =='ChatTTS':
self.main.voice_role.clear()
self.main.current_rolelist = list(config.ChatTTS_voicelist.keys())
self.main.voice_role.addItems(['No']+self.main.current_rolelist)
elif type == 'TTS-API':
self.main.voice_role.clear()
self.main.current_rolelist = config.params['ttsapi_voice_role'].strip().split(',')
Expand Down Expand Up @@ -837,7 +848,7 @@ def listen_voice_fun(self):
volume=int(self.main.volume_rate.value())
pitch=int(self.main.pitch_rate.value())
voice_file = f"{voice_dir}/{config.params['tts_type']}-{lang}-{lujing_role}-{volume}-{pitch}.mp3"
if config.params['tts_type'] == 'GPT-SoVITS':
if config.params['tts_type'] in ['GPT-SoVITS','ChatTTS']:
voice_file += '.wav'

obj = {
Expand Down Expand Up @@ -889,6 +900,11 @@ def set_voice_role(self, t):
config.params['tts_type'] = 'edgeTTS'
self.main.tts_type.setCurrentText('edgeTTS')
return QMessageBox.critical(self.main, config.transobj['anerror'], config.transobj['nogptsovitslanguage'])
if code and code != '-' and config.params['tts_type'] == 'ChatTTS' and code[:2] not in ['zh','en']:
# 除此指望不支持
config.params['tts_type'] = 'edgeTTS'
self.main.tts_type.setCurrentText('edgeTTS')
return QMessageBox.critical(self.main, config.transobj['anerror'], config.transobj['onlycnanden'])

# 除 edgeTTS外,其他的角色不会随语言变化
if config.params['tts_type'] not in ['edgeTTS', 'AzureTTS']:
Expand Down Expand Up @@ -1162,7 +1178,6 @@ def check_start(self):

try:
voice_rate = int(self.main.voice_rate.value())
# voice_rate = 0 if not voice_rate else int(voice_rate)
config.params['voice_rate'] = f"+{voice_rate}%" if voice_rate >= 0 else f"{voice_rate}%"
except Exception:
config.params['voice_rate'] = '+0%'
Expand Down Expand Up @@ -1255,6 +1270,12 @@ def check_start(self):
QMessageBox.critical(self.main, config.transobj['anerror'], rs)
return False

if self.main.app_mode !='hebing' and config.params['target_language']!='-':
code=translator.get_code(show_text=config.params['target_language'])
if code not in ['zh-cn','zh-tw','en'] and config.params['tts_type']=='ChatTTS' and config.params['voice_role']!='No':
return QMessageBox.critical(self.main, config.transobj['anerror'], config.transobj['onlycnanden'])


# 存在视频
config.params['only_video'] = False
if config.params['voice_role'] == 'No':
Expand Down
5 changes: 5 additions & 0 deletions videotrans/mainwin/spwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def bind_action(self):
if config.params['tts_type'] == 'clone-voice':
self.voice_role.addItems(config.clone_voicelist)
threading.Thread(target=tools.get_clone_role).start()
elif config.params['tts_type']=='ChatTTS':
self.voice_role.addItems(['No']+list(config.ChatTTS_voicelist.keys()))
elif config.params['tts_type'] == 'TTS-API':
self.voice_role.addItems(config.params['ttsapi_voice_role'].strip().split(','))
elif config.params['tts_type'] == 'GPT-SoVITS':
Expand Down Expand Up @@ -290,6 +292,7 @@ def bind_action(self):
self.actiondeepLX_address.triggered.connect(self.subform.set_deepLX_address)
self.actionott_address.triggered.connect(self.subform.set_ott_address)
self.actionclone_address.triggered.connect(self.subform.set_clone_address)
self.actionchattts_address.triggered.connect(self.subform.set_chattts_address)
self.actiontts_api.triggered.connect(self.subform.set_ttsapi)
self.actionzhrecogn_api.triggered.connect(self.subform.set_zh_recogn)
self.actiontrans_api.triggered.connect(self.subform.set_transapi)
Expand Down Expand Up @@ -426,6 +429,7 @@ def get_setting(self):
config.params["deeplx_address"] = self.settings.value("deeplx_address", "")
config.params["ott_address"] = self.settings.value("ott_address", "")
config.params["clone_api"] = self.settings.value("clone_api", "")
config.params["chattts_api"] = self.settings.value("chattts_api", "")
config.params["tencent_SecretId"] = self.settings.value("tencent_SecretId", "")
config.params["tencent_SecretKey"] = self.settings.value("tencent_SecretKey", "")

Expand Down Expand Up @@ -497,6 +501,7 @@ def save_setting(self):
self.settings.setValue("only_video", config.params['only_video'])
self.settings.setValue("tts_type", config.params['tts_type'])
self.settings.setValue("clone_api", config.params['clone_api'])
self.settings.setValue("chattts_api", config.params['chattts_api'])
self.settings.setValue("video_autorate", config.params['video_autorate'])
self.settings.setValue("append_video", config.params['append_video'])
self.settings.setValue("clone_voicelist", ','.join(config.clone_voicelist))
53 changes: 53 additions & 0 deletions videotrans/mainwin/subform.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,59 @@ def save():
self.main.clonw.test.clicked.connect(test)
self.main.clonw.show()

def set_chattts_address(self):
class TestTTS(QThread):
uito = Signal(str)

def __init__(self, *, parent=None, text=None):
super().__init__(parent=parent)
self.text = text

def run(self):
from videotrans.tts.chattts import get_voice
try:
get_voice(text=self.text, role="boy1", set_p=False, filename=config.homedir + "/test.mp3")

self.uito.emit("ok")
except Exception as e:
self.uito.emit(str(e))

def feed(d):
if d == "ok":
tools.pygameaudio(config.homedir + "/test.mp3")
QtWidgets.QMessageBox.information(self.main.chatttsw, "ok", "Test Ok")
else:
QtWidgets.QMessageBox.critical(self.main.chatttsw, config.transobj['anerror'], d)
self.main.chatttsw.test.setText('测试' if config.defaulelang == 'zh' else 'Test')

def test():
if not self.main.chatttsw.chattts_address.text().strip():
QtWidgets.QMessageBox.critical(self.main.chatttsw, config.transobj['anerror'], '必须填写http地址')
return
config.params['chattts_api'] = self.main.chatttsw.chattts_address.text().strip()
task = TestTTS(parent=self.main.chatttsw,
text="你好啊我的朋友" if config.defaulelang == 'zh' else 'hello,my friend'
)
self.main.chatttsw.test.setText('测试中请稍等...' if config.defaulelang == 'zh' else 'Testing...')
task.uito.connect(feed)
task.start()

def save():
key = self.main.chatttsw.chattts_address.text().strip()
key = key.rstrip('/')
key = 'http://' + key.replace('http://', '').replace('/tts','')
self.main.settings.setValue("chattts_api", key)
config.params["chattts_api"] = key
self.main.chatttsw.close()

from videotrans.component import ChatttsForm
self.main.chatttsw = ChatttsForm()
if config.params["chattts_api"]:
self.main.chatttsw.chattts_address.setText(config.params["chattts_api"])
self.main.chatttsw.set_chattts.clicked.connect(save)
self.main.chatttsw.test.clicked.connect(test)
self.main.chatttsw.show()

def set_zh_recogn(self):
class Test(QThread):
uito = Signal(str)
Expand Down
2 changes: 2 additions & 0 deletions videotrans/tts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def text_to_speech(
# lasterror=get_voice(text=text, role=role, rate=rate,language=language, filename=filename,set_p=set_p,inst=inst)
elif tts_type =='gtts':
from .gtts import get_voice
elif tts_type=='ChatTTS':
from .chattts import get_voice
# lasterror=get_voice(text=text, role=role, rate=rate, language=language,filename=filename,set_p=set_p,inst=inst)
if get_voice:
get_voice(
Expand Down
Loading

0 comments on commit 993f262

Please sign in to comment.