Commit 54e9918a authored by xuanweiace's avatar xuanweiace

upd

parent 5cf7cc82
......@@ -21,8 +21,9 @@ class Assemble_Dialog(QDialog, Ui_Dialog):
# 注意这里打包成一个list,在worker端进行解参数,避免传参过多
start_assemble_signal = pyqtSignal(list)
def __init__(self):
def __init__(self, projectContext):
super(Assemble_Dialog, self).__init__()
self.projectContext = projectContext
self.setupUi(self)
self.setWindowTitle("合成")
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setText("开始合成")
......@@ -31,10 +32,15 @@ class Assemble_Dialog(QDialog, Ui_Dialog):
self.pushButton_2.clicked.connect(self.openTableFile)
# 注意,不能直接绑定到buttonBox上。
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).clicked.connect(self.start_assemble)
# todo 把所有说话人都加上来
self.comboBox.addItem('晓秋,女,年轻人')
self.comboBox.currentText()
self.comboBox_2.addItems(["1.00(4字/秒)", "1.10(4.5字/秒)", "1.25(5字/秒)", "1.50(6字/秒)", "1.75(7字/秒)", "2.00(8字/秒)", "2.50(10字/秒)"])
self.lineEdit_3.setText(projectContext.speaker_info)
self.lineEdit_4.setText(projectContext.speaker_speed)
# self.show.connect(self.init_self_slot)
def init_self(self):
print("self.projectContext.speaker_info", self.projectContext.speaker_info)
self.lineEdit.setText(self.projectContext.video_path)
self.lineEdit_2.setText(self.projectContext.excel_path)
self.lineEdit_3.setText(self.projectContext.speaker_info)
self.lineEdit_4.setText(self.projectContext.speaker_speed)
def openFile(self):
file_info = QFileDialog.getOpenFileNames(self, '选择视频', os.getcwd(), "All Files(*);;Text Files(*.txt)")
......@@ -61,10 +67,11 @@ class Assemble_Dialog(QDialog, Ui_Dialog):
audio_dir = os.path.dirname(self.lineEdit.text())
# audio_dir = replace_path_suffix(self.lineEdit.text(), "")
sheet_path = self.lineEdit_2.text()
speed_info = self.comboBox_2.currentText()
speaker_info = self.lineEdit_3.text()
speed_info = self.lineEdit_4.text()
#todo 后续变成常量存起来,或者做成配置
caption_path = replace_path_suffix(self.lineEdit.text(), ".srt")
speaker_info = self.comboBox.currentText()
print("video_path: ",video_path)
print("audio_dir: ",audio_dir)
print("sheet_path: ",sheet_path)
......
......@@ -54,7 +54,7 @@
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>120</x>
<x>130</x>
<y>40</y>
<width>211</width>
<height>21</height>
......@@ -90,7 +90,7 @@
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>120</x>
<x>130</x>
<y>90</y>
<width>211</width>
<height>21</height>
......@@ -110,19 +110,6 @@
<string>表格路径</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>360</x>
<y>130</y>
<width>101</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>播放旁白语音</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
......@@ -149,31 +136,25 @@
<string>旁白语速:</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox">
<widget class="QLineEdit" name="lineEdit_3">
<property name="geometry">
<rect>
<x>130</x>
<y>130</y>
<width>181</width>
<height>31</height>
<y>140</y>
<width>211</width>
<height>21</height>
</rect>
</property>
<property name="currentText">
<string/>
</property>
</widget>
<widget class="QComboBox" name="comboBox_2">
<widget class="QLineEdit" name="lineEdit_4">
<property name="geometry">
<rect>
<x>130</x>
<y>190</y>
<width>151</width>
<height>31</height>
<y>200</y>
<width>211</width>
<height>21</height>
</rect>
</property>
<property name="currentText">
<string/>
</property>
</widget>
</widget>
<resources/>
......
......@@ -25,7 +25,7 @@ class Ui_Dialog(object):
self.label.setGeometry(QtCore.QRect(40, 40, 72, 15))
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(120, 40, 211, 21))
self.lineEdit.setGeometry(QtCore.QRect(130, 40, 211, 21))
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(360, 40, 101, 31))
......@@ -34,28 +34,23 @@ class Ui_Dialog(object):
self.label_2.setGeometry(QtCore.QRect(20, 90, 111, 16))
self.label_2.setObjectName("label_2")
self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_2.setGeometry(QtCore.QRect(120, 90, 211, 21))
self.lineEdit_2.setGeometry(QtCore.QRect(130, 90, 211, 21))
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(360, 90, 101, 31))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(360, 130, 101, 31))
self.pushButton_3.setObjectName("pushButton_3")
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(30, 140, 111, 16))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(30, 200, 111, 16))
self.label_4.setObjectName("label_4")
self.comboBox = QtWidgets.QComboBox(Dialog)
self.comboBox.setGeometry(QtCore.QRect(130, 130, 181, 31))
self.comboBox.setCurrentText("")
self.comboBox.setObjectName("comboBox")
self.comboBox_2 = QtWidgets.QComboBox(Dialog)
self.comboBox_2.setGeometry(QtCore.QRect(130, 190, 151, 31))
self.comboBox_2.setCurrentText("")
self.comboBox_2.setObjectName("comboBox_2")
self.lineEdit_3 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_3.setGeometry(QtCore.QRect(130, 140, 211, 21))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(Dialog)
self.lineEdit_4.setGeometry(QtCore.QRect(130, 200, 211, 21))
self.lineEdit_4.setObjectName("lineEdit_4")
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept)
......@@ -69,7 +64,6 @@ class Ui_Dialog(object):
self.pushButton.setText(_translate("Dialog", "选择文件"))
self.label_2.setText(_translate("Dialog", "旁白脚本表格:"))
self.pushButton_2.setText(_translate("Dialog", "表格路径"))
self.pushButton_3.setText(_translate("Dialog", "播放旁白语音"))
self.label_3.setText(_translate("Dialog", "旁白说话人:"))
self.label_4.setText(_translate("Dialog", "旁白语速:"))
......
class Content:
StartTimeColumn = 0
ActivateColumn = 2
# ColumnCount = 3
ObjectName = "all_tableWidget"
class Aside:
StartTimeColumn = 0
AsideColumnNumber = 4
ObjectName = "pb_tableWidget"
import os
dir_path = os.path.dirname(os.path.abspath(__file__))
class Pathes:
speaker_conf_path = os.path.join(dir_path, "speakers.json")
\ No newline at end of file
This diff is collapsed.
......@@ -27,7 +27,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="5,1">
<item>
<layout class="QHBoxLayout" name="shuiping" stretch="3,1">
<layout class="QHBoxLayout" name="shuiping" stretch="2,1">
<item>
<widget class="QWidget" name="verticalWidget_3" native="true">
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="8,0">
......@@ -348,7 +348,7 @@ QPushButton:pressed {
</sizepolicy>
</property>
<property name="text">
<string>字幕时间轴</string>
<string>时间轴</string>
</property>
</widget>
</item>
......@@ -416,7 +416,7 @@ QPushButton:pressed {
</sizepolicy>
</property>
<property name="text">
<string>旁白时间轴</string>
<string>刻度</string>
</property>
</widget>
</item>
......@@ -511,7 +511,7 @@ QPushButton:pressed {
<widget class="QStatusBar" name="statusbar"/>
<action name="actionxinjian">
<property name="text">
<string>新建</string>
<string>设置</string>
</property>
</action>
<action name="action_open_project">
......
......@@ -186,7 +186,7 @@ class Ui_MainWindow(object):
self.horizontalLayout_3.addWidget(self.pb_tableWidget)
self.tabWidget.addTab(self.pb_tab, "")
self.shuiping.addWidget(self.tabWidget)
self.shuiping.setStretch(0, 3)
self.shuiping.setStretch(0, 2)
self.shuiping.setStretch(1, 1)
self.verticalLayout.addLayout(self.shuiping)
self.verticalWidget_2 = QtWidgets.QWidget(self.centralwidget)
......@@ -321,13 +321,13 @@ class Ui_MainWindow(object):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.all_tab), _translate("MainWindow", "字幕旁白"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.zm_tab), _translate("MainWindow", "字幕"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.pb_tab), _translate("MainWindow", "旁白"))
self.zm_label.setText(_translate("MainWindow", "字幕时间轴"))
self.zm_label.setText(_translate("MainWindow", "时间轴"))
self.lab_video.setText(_translate("MainWindow", "0%"))
self.pb_label.setText(_translate("MainWindow", "旁白时间轴"))
self.pb_label.setText(_translate("MainWindow", "刻度"))
self.menu.setTitle(_translate("MainWindow", "文件"))
self.menu_2.setTitle(_translate("MainWindow", "编辑"))
self.menu_3.setTitle(_translate("MainWindow", "功能按键"))
self.actionxinjian.setText(_translate("MainWindow", "新建"))
self.actionxinjian.setText(_translate("MainWindow", "设置"))
self.action_open_project.setText(_translate("MainWindow", "打开"))
self.import_movie.setText(_translate("MainWindow", "视频导入"))
self.actions.setText(_translate("MainWindow", "内容导出"))
......
......@@ -2,10 +2,11 @@ import os.path
import threading
import traceback
import sys
import json
from enum import Enum
import datetime
import openpyxl
import constant
from openpyxl.styles import PatternFill, Alignment
from utils import replace_path_suffix
......@@ -114,13 +115,23 @@ class ProjectContext:
self.subtitle_list = []
self.aside_list = []
self.all_elements = []
self.speaker_info = '晓辰,女,年轻人'
self.speaker_speed = '1.00(4字/秒)'
# 一些常量
self.header = ["起始时间", "终止时间", "字幕", '建议', '解说脚本']
self.contentHeader = ["起始时间", "字幕", "旁白"]
self.excel_sheet_name = "旁白插入位置建议"
self.history_records = []
self.records_pos = 0
#是否处于初始化中
self.initial_ing = False
def clear(self):
self.subtitle_list = []
self.aside_list = []
self.all_elements = []
self.history_records = []
self.records_pos = 0
def Init(self, project_dir, video_name):
self.project_base_dir = project_dir
# self.video_path = os.path.join(project_dir, video_name)
......@@ -151,9 +162,13 @@ class ProjectContext:
def refresh_aside(self, row, aside: str)->None:
self.aside_list[int(row)].aside = aside
if not self.initial_ing:
save_excel_to_to_path(self.all_elements, self.excel_path, self.header, self.excel_sheet_name)
def refresh_element(self, row, aside: str):
self.all_elements[int(row)].aside = aside
if not self.initial_ing:
save_excel_to_to_path(self.all_elements, self.excel_path, self.header, self.excel_sheet_name)
# 加载整个工程,填充到ProjectContext上下文中
def load_project(self):
......@@ -161,7 +176,7 @@ class ProjectContext:
def load_excel_from_path(self):
d = read_sheet(self.excel_path)
self.all_elements = []
self.clear()
# todo:现在是只用None判断是否是字幕,后续是否也需要用""来?
for i in range(len(d["字幕"])):
st_time_sec, ed_time_sec, subtitle, suggest, aside = [d[x][i] for x in self.header]
......@@ -209,6 +224,18 @@ class ProjectContext:
# 报错
return None
def get_all_speaker_info(self):
"""获取所有说话人的名字、性别及年龄段等信息
用于显示在人机交互界面上,方便用户了解说话人并进行选择
"""
f = open(constant.Pathes.speaker_conf_path, encoding="utf-8")
content = json.load(f)
speaker_name = []
for speaker in content["speaker_details"]:
speaker_name.append(
",".join([speaker["name"], speaker["gender"], speaker["age_group"]]))
return tuple(speaker_name)
def save_excel_to_to_path(all_element, new_excel_path, header, excel_sheet_name):
......@@ -218,7 +245,7 @@ def save_excel_to_to_path(all_element, new_excel_path, header, excel_sheet_name)
try:
create_sheet(new_excel_path, "旁白插入位置建议", [header])
for element in all_element:
element.print_self()
# element.print_self()
write_to_sheet(new_excel_path, excel_sheet_name, element.to_list())
except:
exception_info = ''.join(
......
import sys
import os
from PyQt5.QtCore import *;
from PyQt5.QtGui import *;
from PyQt5.QtWidgets import *;
from setting_dialog_ui import Ui_Dialog
from utils import validate_and_get_filepath, replace_path_suffix
class Setting_Dialog(QDialog, Ui_Dialog):
# 开始合成信号,传参分别是video_path,audio_dir, sheet_path,speed_info, caption_path, speaker_info
# 注意这里打包成一个list,在worker端进行解参数,避免传参过多
start_assemble_signal = pyqtSignal(list)
def __init__(self, projectContext):
super(Setting_Dialog, self).__init__()
self.setupUi(self)
self.setWindowTitle("合成")
self.projectContext = projectContext
# todo 把所有说话人都加上来
li = self.projectContext.get_all_speaker_info()
for i in li:
self.comboBox.addItem(i)
# self.comboBox.addItem('晓秋,女,年轻人')
self.comboBox_2.addItems(["1.00(4字/秒)", "1.10(4.5字/秒)", "1.25(5字/秒)", "1.50(6字/秒)", "1.75(7字/秒)", "2.00(8字/秒)", "2.50(10字/秒)"])
self.comboBox.currentIndexChanged.connect(self.speaker_change_slot)
self.comboBox_2.currentIndexChanged.connect(self.speed_change_slot)
def speaker_change_slot(self):
self.projectContext.speaker_info = self.comboBox.currentText()
print("self.projectContext.speaker_info:", self.projectContext.speaker_info)
def speed_change_slot(self):
self.projectContext.speaker_speed = self.comboBox_2.currentText()
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("./images/eagle_2.ico"))
dialog = Setting_Dialog()
dialog.show()
sys.exit(app.exec_())
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>612</width>
<height>404</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>30</x>
<y>140</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>旁白说话人:</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>30</x>
<y>200</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>旁白语速:</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox">
<property name="geometry">
<rect>
<x>130</x>
<y>130</y>
<width>181</width>
<height>31</height>
</rect>
</property>
<property name="currentText">
<string/>
</property>
</widget>
<widget class="QComboBox" name="comboBox_2">
<property name="geometry">
<rect>
<x>130</x>
<y>190</y>
<width>151</width>
<height>31</height>
</rect>
</property>
<property name="currentText">
<string/>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'setting_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.12
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(612, 404)
self.label_3 = QtWidgets.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(30, 140, 111, 16))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(30, 200, 111, 16))
self.label_4.setObjectName("label_4")
self.comboBox = QtWidgets.QComboBox(Dialog)
self.comboBox.setGeometry(QtCore.QRect(130, 130, 181, 31))
self.comboBox.setCurrentText("")
self.comboBox.setObjectName("comboBox")
self.comboBox_2 = QtWidgets.QComboBox(Dialog)
self.comboBox_2.setGeometry(QtCore.QRect(130, 190, 151, 31))
self.comboBox_2.setCurrentText("")
self.comboBox_2.setObjectName("comboBox_2")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label_3.setText(_translate("Dialog", "旁白说话人:"))
self.label_4.setText(_translate("Dialog", "旁白语速:"))
import sys
import traceback
from PyQt5.QtCore import *;
from PyQt5.QtGui import *;
from PyQt5.QtWidgets import *;
......@@ -8,8 +9,16 @@ from main_window import MainWindow
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("./images/eagle_2.ico"))
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
\ No newline at end of file
try:
app = QApplication(sys.argv)
app.setWindowIcon(QIcon("./images/eagle_2.ico"))
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
except Exception as e:
exc_traceback = ''.join(
traceback.format_exception(*sys.exc_info()))
print("[Catch Exception in start.py]", exc_traceback)
......@@ -14,6 +14,8 @@ class SynthesisProcessor(QWidget):
synthesis_callback_signal = pyqtSignal(list, list)
def __init__(self):
super(SynthesisProcessor, self).__init__()
self.state = [None]
self.threads = []
# 对参数的加工放到processer这边
def synthesis_slot(self, param:list):
......@@ -70,7 +72,8 @@ class SynthesisProcessor(QWidget):
# 多线程同时实现语音合成+字幕导出、进度条
state = [None]
threads = []
self.state = state
self.threads = threads
from speech_synthesis import ss_and_export
t = RunThread(funcName=ss_and_export,
args=(video_path, sheet_path, audio_dir, speed,
......@@ -89,29 +92,29 @@ class SynthesisProcessor(QWidget):
print("===子线程已经开启 in synthesis===")
self.synthesis_callback_signal.emit(threads)
self.synthesis_callback_signal.emit(threads, state)
# 查询线程是否有结束的,一旦一个结束,另一个也结束
while 1:
alive = True
for t in threads:
alive = alive and t.is_alive()
if not alive:
break
time.sleep(5)
print("===已有线程结束了 in synthesis===")
for t in threads:
if t.exitcode != 0:
print("Exception in", t.getName())
self.show_warning_signal.emit("运行出错,请联系开发者处理")
# processState_2.set("任务中断")
# progress_state = progressbar_2['value']
# progressbar_2.stop()
# progressbar_2['value'] = progress_state
# startSynthesis.config(state=tk.ACTIVE)
# stopSynthesis.config(state=tk.DISABLED)
return
print("合成任务完成")
# while 1:
# alive = True
# for t in threads:
# alive = alive and t.is_alive()
# if not alive:
# break
# time.sleep(5)
# print("===已有线程结束了 in synthesis===")
# for t in threads:
# if t.exitcode != 0:
# print("Exception in", t.getName())
# self.show_warning_signal.emit("运行出错,请联系开发者处理")
# # processState_2.set("任务中断")
# # progress_state = progressbar_2['value']
# # progressbar_2.stop()
# # progressbar_2['value'] = progress_state
# # startSynthesis.config(state=tk.ACTIVE)
# # stopSynthesis.config(state=tk.DISABLED)
# return
#
# print("合成任务完成")
# processState_2.set("任务完成")
# progressbar_2.stop()
# progressbar_2['value'] = 100.0
......
No preview for this file type
......@@ -27,8 +27,8 @@ class TableWidget(QWidget):
tablewidget.setItem(0,1,ageItem)
jgItem = QTableWidgetItem("北京")
# jgItem.setFlags(Qt.ItemIsEnabled)
jgItem.setFlags(Qt.ItemFlags(32))
jgItem.setFlags(Qt.ItemIsEnabled)
# jgItem.setFlags(Qt.ItemFlags(32))
# jgItem.checkState()
tablewidget.setItem(0,2,jgItem)
self.tablewidget = tablewidget
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment