Skip to content

Commit

Permalink
完成快速导出音频功能
Browse files Browse the repository at this point in the history
  • Loading branch information
kslz committed Mar 25, 2023
1 parent 402e4ec commit d4c17be
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
28 changes: 27 additions & 1 deletion ui/mygui.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,26 @@ def go_back(self):
self.close()


class FastOutputSoundBTN(QPushButton):
def __init__(self, text, info_id, parent):
super().__init__(text, parent)
self.info_id = info_id
self.clicked.connect(self.fast_output_sound)
# self.setText("快速导出")
# info = Info.get_by_id(self.info_id)
# wav_path = info.info_raw_file_path
# start_time = info.info_start_time
# end_time = info.info_end_time

def fast_output_sound(self):
info = Info.get_by_id(self.info_id)
wav_path = info.info_raw_file_path
start_time = info.info_start_time
end_time = info.info_end_time
output_name = str(self.info_id) + ".wav"
fast_output_sound(wav_path, start_time, end_time, output_name)


class PlaySoundBTN(QPushButton):
class PlaySoundThread(QtCore.QThread):
update_signal = Signal(str, bool)
Expand Down Expand Up @@ -693,12 +713,18 @@ def refresh_table(self, page_number=0):
# self.ui.tableWidget.setItem(row, 5, QTableWidgetItem(str(info_id) + "一些操作"))

btn_shiting = PlaySoundBTN('试听', info_id, self)
btn_shiting.setMinimumWidth(50)
btn_fastoutput = FastOutputSoundBTN('快速导出', info_id, self)
btn_fastoutput.setMinimumWidth(80)
btn_bianji = QPushButton('编辑', self)
btn_shiting.clicked.connect(lambda: self.edit_info(info_id))
btn_bianji.setMinimumWidth(50)
btn_bianji.clicked.connect(lambda: self.edit_info(info_id))
self.btn_dict[f"{row}_shiting"] = btn_shiting
self.btn_dict[f"{row}_fastoutput"] = btn_fastoutput
self.btn_dict[f"{row}_bianji"] = btn_bianji
layout = QHBoxLayout()
layout.addWidget(self.btn_dict[f"{row}_shiting"])
layout.addWidget(self.btn_dict[f"{row}_fastoutput"])
layout.addWidget(self.btn_dict[f"{row}_bianji"])
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(1)
Expand Down
12 changes: 11 additions & 1 deletion utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def del_file_by_dataset_id(dataset_id):
pass


def output_wav_file(wav_path, start_time, end_time, new_path, sample_rate, channels, normalization):
def output_wav_file(wav_path, start_time, end_time, new_path, sample_rate="", channels="", normalization=""):
codec = 'pcm_s16le'
if sample_rate == "":
sample_rate = 44100
Expand Down Expand Up @@ -507,6 +507,16 @@ def merge_srt(subs, min_time=35):
return subs2


def fast_output_sound(wav_path, start_time, end_time, output_name):
workspace_path = global_obj.get_value("workspace_path")
output_path = os.path.join(workspace_path, "output", "fastoutput")
os.makedirs(output_path, exist_ok=True)
output_path = os.path.join(output_path, output_name)
output_wav_file(wav_path, start_time, end_time, output_path)
guilogger.info(f"快速导出音频文件文件 {output_path}")



def play_by_ffmpeg(wav_path, start_time, end_time):
# 将毫秒转换为ffmpeg需要的时间格式
duration = (end_time - start_time) / 1000
Expand Down

0 comments on commit d4c17be

Please sign in to comment.