Commit 3ed61a1f authored by xuanweiace's avatar xuanweiace

基本改完 不同旁白不同语速的部分

parent a762942b
云扬,男,年轻人 晓颜,女,年轻人
1.00(4字/秒) 1.25(5字/秒)
\ No newline at end of file \ No newline at end of file
class Content: class Content:
StartTimeColumn = 0 StartTimeColumn = 0
ActivateColumn = 2 AsideColumnNumber = 2
ActivateColumns = [2,3]
# ColumnCount = 3 # ColumnCount = 3
ObjectName = "all_tableWidget" ObjectName = "all_tableWidget"
TimeFormatColumns = [0]
class Aside: class Aside:
StartTimeColumn = 0 StartTimeColumn = 0
AsideColumnNumber = 3 AsideColumnNumber = 3
ActivateColumns = [3,4]
ObjectName = "pb_tableWidget" ObjectName = "pb_tableWidget"
TimeFormatColumns = [0,1]
class Subtitle: class Subtitle:
ObjectName = "zm_tableWidget" ObjectName = "zm_tableWidget"
TimeFormatColumns = [0,1]
import os import os
dir_path = os.path.dirname(os.path.abspath(__file__)) dir_path = os.path.dirname(os.path.abspath(__file__))
class Pathes: class Pathes:
......
This diff is collapsed.
...@@ -528,6 +528,7 @@ QPushButton:pressed { ...@@ -528,6 +528,7 @@ QPushButton:pressed {
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="action_insert_aside_from_now"/> <addaction name="action_insert_aside_from_now"/>
<addaction name="action_operate"/> <addaction name="action_operate"/>
<addaction name="action_insert_subtitle_from_now"/>
</widget> </widget>
<widget class="QMenu" name="menu_3"> <widget class="QMenu" name="menu_3">
<property name="title"> <property name="title">
...@@ -613,6 +614,11 @@ QPushButton:pressed { ...@@ -613,6 +614,11 @@ QPushButton:pressed {
<string>当前位置插入旁白</string> <string>当前位置插入旁白</string>
</property> </property>
</action> </action>
<action name="action_insert_subtitle_from_now">
<property name="text">
<string>当前位置插入字幕</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
......
...@@ -80,12 +80,13 @@ class OperateRecord: ...@@ -80,12 +80,13 @@ class OperateRecord:
# 每一行的具体信息,"起始时间", "终止时间", "字幕", '建议', '解说脚本' # 每一行的具体信息,"起始时间", "终止时间", "字幕", '建议', '解说脚本'
class Element: class Element:
def __init__(self, st_time_sec: str, ed_time_sec: str, subtitle, suggest, aside): def __init__(self, st_time_sec: str, ed_time_sec: str, subtitle, suggest, aside, speed = "1.00(4字/秒)"):
self.st_time_sec = st_time_sec self.st_time_sec = st_time_sec
self.ed_time_sec = ed_time_sec self.ed_time_sec = ed_time_sec
self.subtitle = subtitle self.subtitle = subtitle
self.suggest = suggest self.suggest = suggest
self.aside = aside self.aside = aside
self.speed = speed
# 判断当前元素是否是字幕 # 判断当前元素是否是字幕
...@@ -97,17 +98,17 @@ class Element: ...@@ -97,17 +98,17 @@ class Element:
return not self.is_subtitle() return not self.is_subtitle()
def to_list(self): def to_list(self):
return [self.st_time_sec, self.ed_time_sec, self.subtitle, self.suggest, self.aside] return [self.st_time_sec, self.ed_time_sec, self.subtitle, self.suggest, self.aside, self.speed]
def to_short_list(self): def to_short_list(self):
return [self.st_time_sec, self.subtitle, self.aside] return [self.st_time_sec, self.subtitle, self.aside, self.speed]
def to_aside_list(self): def to_aside_list(self):
return [self.st_time_sec, self.ed_time_sec, self.suggest, self.aside] return [self.st_time_sec, self.ed_time_sec, self.suggest, self.aside, self.speed]
def to_subtitle_list(self): def to_subtitle_list(self):
return [self.st_time_sec, self.ed_time_sec, self.subtitle] return [self.st_time_sec, self.ed_time_sec, self.subtitle]
def print_self(self): def print_self(self):
print("st_time_sec:",self.st_time_sec,"ed_time_sec:",self.ed_time_sec, print("st_time_sec:",self.st_time_sec,"ed_time_sec:",self.ed_time_sec,
"subtitle:",self.subtitle,"suggest:",self.suggest, "aside", self.aside) "subtitle:",self.subtitle,"suggest:",self.suggest, "aside:", self.aside, "speed:", self.speed)
def equalTo(self, other)->bool: def equalTo(self, other)->bool:
return abs(float(self.st_time_sec) - float(other.st_time_sec)) < 0.1 return abs(float(self.st_time_sec) - float(other.st_time_sec)) < 0.1
...@@ -126,11 +127,11 @@ class ProjectContext: ...@@ -126,11 +127,11 @@ class ProjectContext:
self.speaker_info = rl[0].strip() self.speaker_info = rl[0].strip()
self.speaker_speed = rl[1].strip() self.speaker_speed = rl[1].strip()
# 一些常量 # 一些常量
self.header = ["起始时间", "终止时间", "字幕", '建议', '解说脚本'] self.header = ["起始时间", "终止时间", "字幕", '建议', '解说脚本', "语速"]
self.aside_header = ["起始时间", "终止时间", '建议', '解说脚本'] self.aside_header = ["起始时间", "终止时间", '建议', '解说脚本',"语速"]
self.subtitle_header = ["起始时间", "终止时间", "字幕"] self.subtitle_header = ["起始时间", "终止时间", "字幕"]
self.contentHeader = ["起始时间", "字幕", "旁白"] self.contentHeader = ["起始时间", "字幕", "旁白", "语速"]
self.excel_sheet_name = "旁白插入位置建议" self.excel_sheet_name = "旁白插入位置建议"
self.history_records = [] self.history_records = []
self.records_pos = 0 self.records_pos = 0
......
...@@ -4,8 +4,8 @@ from PyQt5.QtCore import *; ...@@ -4,8 +4,8 @@ from PyQt5.QtCore import *;
from PyQt5.QtGui import *; from PyQt5.QtGui import *;
from PyQt5.QtWidgets import *; from PyQt5.QtWidgets import *;
import utils
from operation_dialog_ui import Ui_Dialog from operation_dialog_ui import Ui_Dialog
from utils import validate_and_get_filepath, replace_path_suffix
#todo 注意,删除行,添加行,暂不支持【撤销与重做】功能!!! #todo 注意,删除行,添加行,暂不支持【撤销与重做】功能!!!
class Operation_Dialog(QDialog, Ui_Dialog): class Operation_Dialog(QDialog, Ui_Dialog):
...@@ -23,7 +23,7 @@ class Operation_Dialog(QDialog, Ui_Dialog): ...@@ -23,7 +23,7 @@ class Operation_Dialog(QDialog, Ui_Dialog):
self.pushButton.clicked.connect(self.check_validate_slot) self.pushButton.clicked.connect(self.check_validate_slot)
self.pushButton_2.clicked.connect(self.remake_slot) self.pushButton_2.clicked.connect(self.remake_slot)
#如果是【修改一行】,选择行的时候要瞬间更新成目前行的内容 #如果是【修改一行】,选择行的时候要瞬间更新成目前行的内容
self.pushButton_3.clicked.connect(self.row_num_change_slot) self.pushButton_3.clicked.connect(self.fill_row_info_slot)
self.buttonBox.setEnabled(False) self.buttonBox.setEnabled(False)
self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).clicked.connect(self.start_operation_slot) self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).clicked.connect(self.start_operation_slot)
...@@ -31,7 +31,8 @@ class Operation_Dialog(QDialog, Ui_Dialog): ...@@ -31,7 +31,8 @@ class Operation_Dialog(QDialog, Ui_Dialog):
self.comboBox.currentIndexChanged.connect(self.zmpb_change_slot) self.comboBox.currentIndexChanged.connect(self.zmpb_change_slot)
# 增加一行/删除一行 选择框 # 增加一行/删除一行 选择框
self.comboBox_2.currentIndexChanged.connect(self.adddel_change_slot) self.comboBox_2.currentIndexChanged.connect(self.adddel_change_slot)
self.speed_list = ["1.00(4字/秒)", "1.10(4.5字/秒)", "1.25(5字/秒)", "1.50(6字/秒)", "1.75(7字/秒)", "2.00(8字/秒)", "2.50(10字/秒)"]
self.comboBox_3.addItems(li)
self.lineEdits = [self.lineEdit, self.lineEdit_2, self.lineEdit_3, self.lineEdit_4, self.lineEdit_5, self.lineEdit_6] self.lineEdits = [self.lineEdit, self.lineEdit_2, self.lineEdit_3, self.lineEdit_4, self.lineEdit_5, self.lineEdit_6]
self.zmpb_change_slot() self.zmpb_change_slot()
...@@ -72,15 +73,30 @@ class Operation_Dialog(QDialog, Ui_Dialog): ...@@ -72,15 +73,30 @@ class Operation_Dialog(QDialog, Ui_Dialog):
except Exception as e: except Exception as e:
self.mainWindow.prompt_dialog.show_with_msg("校验失败!总行数为[%d],你的输入为[%s]!!"%(rowCount, self.lineEdit.text())) self.mainWindow.prompt_dialog.show_with_msg("校验失败!总行数为[%d],你的输入为[%s]!!"%(rowCount, self.lineEdit.text()))
return False return False
# 校验时间填写是否是hh:mm:ss格式的
try:
import re
if type(self.lineEdit_2.text())==str and len(self.lineEdit_2.text()) > 0:
x = re.match("^(([0-1]\d)|(2[0-4])):[0-5]\d:[0-5]\d(.\d{1,2})?$", self.lineEdit_2.text())
assert x != None
if type(self.lineEdit_3.text()) == str and len(self.lineEdit_3.text()) > 0:
x = re.match("^(([0-1]\d)|(2[0-4])):[0-5]\d:[0-5]\d(.\d{1,2})?$", self.lineEdit_3.text())
assert x != None
except Exception as e:
self.mainWindow.prompt_dialog.show_with_msg("校验失败!起始或结束时间输入的格式有误!应该为hh:mm:ss!!"%(rowCount, self.lineEdit.text()))
return False
# 这些是只有【add】才需要检测的 # 这些是只有【add】才需要检测的
if self.comboBox_2.currentText() == "增加一行": if self.comboBox_2.currentText() == "增加一行":
#校验起始时间、结束时间 #校验起始时间、结束时间
start_time_f, end_time_f = 0.0, 0.0 start_time_f, end_time_f = 0.0, 0.0
try: try:
start_time_f = float(self.lineEdit_2.text()) start_time_f = float(utils.trans_to_seconds(self.lineEdit_2.text()))
if self.comboBox.currentText() == "字幕": if self.comboBox.currentText() == "字幕":
end_time_f = float(self.lineEdit_3.text()) end_time_f = float(utils.trans_to_seconds(self.lineEdit_3.text()))
assert start_time_f < end_time_f assert start_time_f < end_time_f
except Exception as e: except Exception as e:
self.mainWindow.prompt_dialog.show_with_msg("校验失败!起始时间或结束时间输入有误!!" ) self.mainWindow.prompt_dialog.show_with_msg("校验失败!起始时间或结束时间输入有误!!" )
...@@ -123,6 +139,12 @@ class Operation_Dialog(QDialog, Ui_Dialog): ...@@ -123,6 +139,12 @@ class Operation_Dialog(QDialog, Ui_Dialog):
row, start_time, end_time, subtitle, suggest, aside = [x.text() for x in self.lineEdits] row, start_time, end_time, subtitle, suggest, aside = [x.text() for x in self.lineEdits]
# 将hh:mm:ss转成秒的形式传给mainWindow
if type(start_time)==str and len(start_time)>0:
start_time = str(utils.trans_to_seconds(start_time))
if type(end_time)==str and len(end_time)>0:
end_time = str(utils.trans_to_seconds(end_time))
if self.comboBox.currentText() == "字幕": if self.comboBox.currentText() == "字幕":
suggest = "" suggest = ""
aside = "" aside = ""
...@@ -144,22 +166,24 @@ class Operation_Dialog(QDialog, Ui_Dialog): ...@@ -144,22 +166,24 @@ class Operation_Dialog(QDialog, Ui_Dialog):
else: else:
self.start_del_signal.emit(row, start_time, end_time, subtitle, suggest, aside) self.start_del_signal.emit(row, start_time, end_time, subtitle, suggest, aside)
def row_num_change_slot(self): def fill_row_info_slot(self):
text = self.lineEdit.text() text = self.lineEdit.text()
print("row_num_change_slot, text:", text) print("fill_row_info_slot, text:", text)
if text is not None: if text is not None:
try: try:
rowCount = self.mainWindow.all_tableWidget.rowCount() rowCount = self.mainWindow.all_tableWidget.rowCount()
row_number = int(self.lineEdit.text()) row_number = int(self.lineEdit.text())
assert 1 <= row_number <= rowCount assert 1 <= row_number <= rowCount
elem = self.mainWindow.projectContext.all_elements[int(row_number)-1] elem = self.mainWindow.projectContext.all_elements[int(row_number)-1]
self.lineEdit_2.setText(elem.st_time_sec) self.lineEdit_2.setText(str(utils.transfer_second_to_time(elem.st_time_sec)))
self.lineEdit_3.setText(elem.ed_time_sec) self.lineEdit_3.setText(str(utils.transfer_second_to_time(elem.ed_time_sec)))
self.lineEdit_4.setText(elem.subtitle) self.lineEdit_4.setText(elem.subtitle)
self.lineEdit_5.setText(elem.suggest[elem.suggest.index("推荐字数为") + 5:]) self.lineEdit_5.setText(elem.suggest[elem.suggest.index("推荐字数为") + 5:])
self.lineEdit_6.setText(elem.aside) self.lineEdit_6.setText(elem.aside)
# 如果是旁白的话
if elem.suggest is not None and "推荐字数为" in elem.suggest: if elem.suggest is not None and "推荐字数为" in elem.suggest:
self.lineEdit_5.setText(elem.suggest[elem.suggest.index("推荐字数为")+5:]) self.lineEdit_5.setText(elem.suggest[elem.suggest.index("推荐字数为")+5:])
self.comboBox_3.setCurrentIndex(self.speed_list.index(elem.speed))
except Exception as e: except Exception as e:
print("exception:", e) print("exception:", e)
pass pass
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>680</width> <width>737</width>
<height>427</height> <height>437</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
</property> </property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>470</x> <x>480</x>
<y>350</y> <y>380</y>
<width>101</width> <width>101</width>
<height>32</height> <height>32</height>
</rect> </rect>
...@@ -324,7 +324,7 @@ ...@@ -324,7 +324,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>350</x> <x>350</x>
<y>350</y> <y>380</y>
<width>93</width> <width>93</width>
<height>28</height> <height>28</height>
</rect> </rect>
...@@ -337,7 +337,7 @@ ...@@ -337,7 +337,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>230</x> <x>230</x>
<y>350</y> <y>380</y>
<width>93</width> <width>93</width>
<height>28</height> <height>28</height>
</rect> </rect>
...@@ -378,6 +378,35 @@ ...@@ -378,6 +378,35 @@
行信息</string> 行信息</string>
</property> </property>
</widget> </widget>
<widget class="QComboBox" name="comboBox_3">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>540</x>
<y>310</y>
<width>101</width>
<height>22</height>
</rect>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label_14">
<property name="geometry">
<rect>
<x>480</x>
<y>310</y>
<width>41</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>语速:</string>
</property>
</widget>
</widget> </widget>
<resources/> <resources/>
<connections> <connections>
......
...@@ -12,10 +12,10 @@ from PyQt5 import QtCore, QtGui, QtWidgets ...@@ -12,10 +12,10 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object): class Ui_Dialog(object):
def setupUi(self, Dialog): def setupUi(self, Dialog):
Dialog.setObjectName("Dialog") Dialog.setObjectName("Dialog")
Dialog.resize(680, 427) Dialog.resize(737, 437)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setEnabled(False) self.buttonBox.setEnabled(False)
self.buttonBox.setGeometry(QtCore.QRect(470, 350, 101, 32)) self.buttonBox.setGeometry(QtCore.QRect(480, 380, 101, 32))
self.buttonBox.setToolTip("") self.buttonBox.setToolTip("")
self.buttonBox.setToolTipDuration(-1) self.buttonBox.setToolTipDuration(-1)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
...@@ -94,10 +94,10 @@ class Ui_Dialog(object): ...@@ -94,10 +94,10 @@ class Ui_Dialog(object):
self.label_12.setGeometry(QtCore.QRect(250, 270, 251, 20)) self.label_12.setGeometry(QtCore.QRect(250, 270, 251, 20))
self.label_12.setObjectName("label_12") self.label_12.setObjectName("label_12")
self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(350, 350, 93, 28)) self.pushButton.setGeometry(QtCore.QRect(350, 380, 93, 28))
self.pushButton.setObjectName("pushButton") self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Dialog) self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(230, 350, 93, 28)) self.pushButton_2.setGeometry(QtCore.QRect(230, 380, 93, 28))
self.pushButton_2.setObjectName("pushButton_2") self.pushButton_2.setObjectName("pushButton_2")
self.label_13 = QtWidgets.QLabel(Dialog) self.label_13 = QtWidgets.QLabel(Dialog)
self.label_13.setGeometry(QtCore.QRect(250, 90, 311, 21)) self.label_13.setGeometry(QtCore.QRect(250, 90, 311, 21))
...@@ -108,6 +108,14 @@ class Ui_Dialog(object): ...@@ -108,6 +108,14 @@ class Ui_Dialog(object):
self.pushButton_3 = QtWidgets.QPushButton(Dialog) self.pushButton_3 = QtWidgets.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(540, 60, 71, 61)) self.pushButton_3.setGeometry(QtCore.QRect(540, 60, 71, 61))
self.pushButton_3.setObjectName("pushButton_3") self.pushButton_3.setObjectName("pushButton_3")
self.comboBox_3 = QtWidgets.QComboBox(Dialog)
self.comboBox_3.setEnabled(True)
self.comboBox_3.setGeometry(QtCore.QRect(540, 310, 101, 22))
self.comboBox_3.setEditable(False)
self.comboBox_3.setObjectName("comboBox_3")
self.label_14 = QtWidgets.QLabel(Dialog)
self.label_14.setGeometry(QtCore.QRect(480, 310, 41, 20))
self.label_14.setObjectName("label_14")
self.retranslateUi(Dialog) self.retranslateUi(Dialog)
self.buttonBox.rejected.connect(Dialog.reject) self.buttonBox.rejected.connect(Dialog.reject)
...@@ -139,5 +147,6 @@ class Ui_Dialog(object): ...@@ -139,5 +147,6 @@ class Ui_Dialog(object):
self.label_13.setText(_translate("Dialog", "*需要填在【字幕旁白】页面中的行数")) self.label_13.setText(_translate("Dialog", "*需要填在【字幕旁白】页面中的行数"))
self.pushButton_3.setText(_translate("Dialog", "填充\n" self.pushButton_3.setText(_translate("Dialog", "填充\n"
"行信息")) "行信息"))
self.label_14.setText(_translate("Dialog", "语速:"))
...@@ -26,13 +26,17 @@ def trans_to_seconds(timePoint: str) -> float: ...@@ -26,13 +26,17 @@ def trans_to_seconds(timePoint: str) -> float:
return time_in_seconds return time_in_seconds
def transfer_second_to_time(sec: str) -> str: def transfer_second_to_time(sec: str) -> str:
"""
输入xxxx.xxx秒,输出xx:xx:xx.xx的格式(输出不一定有小数点)
"""
duration = int(float(sec)) duration = int(float(sec))
minutes = int(duration / 60) hour = int(duration/3600)
seconds = int(duration - 60 * minutes) minutes = int((duration % 3600)/60)
seconds = int(duration%60)
idx = sec.find('.') idx = sec.find('.')
if(idx == -1): if(idx == -1):
idx = len(sec) idx = len(sec)
time = "%02d:%02d%s" % (minutes, seconds, sec[idx:]) time = "%02d:%02d:%02d%s" % (hour, minutes, seconds, sec[idx:idx+3])
return time return time
def replace_path_suffix(path, new_suffix): def replace_path_suffix(path, new_suffix):
...@@ -80,3 +84,41 @@ def get_sheetHead(book_path: str) -> list: ...@@ -80,3 +84,41 @@ def get_sheetHead(book_path: str) -> list:
if __name__ == '__main__': if __name__ == '__main__':
x = transfer_second_to_time("12000.923") x = transfer_second_to_time("12000.923")
print(x) print(x)
x = transfer_second_to_time("79.925")
print(x)
y = trans_to_seconds("1:00:00.92")
print(y)
z = transfer_second_to_time("1200.923")
print(z)
import time
strtime = "1:00:00.92"
# time.strptime(strtime, "%H:%M:%S")
import re
print("------------"*10)
# tests = ["00:12:34a", "01:12:34", "10:12:34.567", "12:12:34.89", "24:12:34.8", "2:34.2", "12:34.", "12:34.0", "02:34.0", "00:34.0"]
tests = ["01:12:34", "10:12:34.567", "12:12:34.89", "24:12:34.8", "2:34.2", "12:12:34.", "01:12:34.0", "02:02:34.0", "00:00:34.0"]
for s in tests:
x = re.match("^(([0-1]\d)|(2[0-4])):[0-5]\d:[0-5]\d(.\d{1,2})?$", s)
print("当前=", s)
print(x)
if x:
print(x.group())
print(x.group(1))
print("---------------------------------")
# print(re.match("^(([0-1]\d)|(2[0-4])):[0-5]\d$", "a12:34"))
# print(re.match("^(([0-1]\d)|(2[0-4])):[0-5]\d$", "a"))
# print(re.match("[^abc]", "plain"))
# print("------------")
# q = re.match("p|(pl)ain", "plain")
# print(q)
# print(q.group())
# print("------------")
# qq = re.match("ya(msen|nsen|nsem)", "yansen’s blog")
# print(qq)
# print(qq.group())
# print(qq.group(1))
\ No newline at end of file
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