Skip to content

Commit

Permalink
fixed bug #106
Browse files Browse the repository at this point in the history
  • Loading branch information
CheshireCC committed Mar 28, 2024
1 parent fc201ce commit 3ebb991
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
14 changes: 7 additions & 7 deletions fasterWhisperGUIConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
"model_param": {
"localModel": true,
"onlineModel": false,
"model_path": "F:/WhisperModels/faster-whisper/large-v3-float32",
"model_path": "",
"modelName": 0,
"use_v3_model": true,
"device": 1,
"deviceIndex": "0",
"preciese": 0,
"preciese": 5,
"thread_num": "4",
"num_worker": "1",
"download_root": "C:/Users/12059/.cache/huggingface/hub",
"download_root": "",
"local_files_only": false
},
"vad_param": {
"use_VAD": true,
"threshold": 0.5,
"threshold": 0.3,
"minSpeechDuration": "250",
"minSilenceDuration": "2000",
"maxSpeechDuration": "inf",
Expand All @@ -39,7 +39,7 @@
},
"Transcription_param": {
"aggregate_contents": true,
"language": 2,
"language": 0,
"task": false,
"beam_size": "5",
"best_of": "5",
Expand All @@ -64,10 +64,10 @@
"prompt_reset_on_temperature": "0.5"
},
"output_whisperX": {
"tabMovable": false,
"tabMovable": true,
"tabScrollable": false,
"tabShadowEnabled": false,
"tabMaxWidth": 361,
"tabMaxWidth": 259,
"closeDisplayMode": 0,
"whisperXMinSpeaker": 0,
"whisperXMaxSpeaker": 0,
Expand Down
32 changes: 18 additions & 14 deletions faster_whisper_GUI/mainWindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
from PySide6.QtGui import QTextCursor
from PySide6.QtCore import (
QCoreApplication,
QObject,
QTranslator
QObject
, Qt
, Signal
)
Expand All @@ -27,7 +26,6 @@
, InfoBarPosition
, InfoBarIcon
, MessageBox
# , TableView
, FluentIcon
, isDarkTheme
)
Expand Down Expand Up @@ -494,29 +492,33 @@ def changeTableData(self, results) -> None:

# 遍历表格标签 删除已经不存在的转写结果 并改写存在的转写结果
for tabBarItem in tabBarItems:

# print(f"tablBarItem text:{tabBarItem.text()}")
# 清理掉已经过时的结果, 标签名不存在于结果文件名列表中的时候就直接清理掉项目
if not(tabBarItem.text() in text_list):
index = tabBarItems.index(tabBarItem)
# print(f"delete item: {tabBarItem.text()}")
self.page_output.tableTab.tabBar.removeTab(index)
continue

# 从 objectName 获取文件名
print(tabBarItem.objectName())
tabBarItem_objectName_fileName = "_".join(tabBarItem.objectName().split("_")[1:]).replace("\\", "/")

print(tabBarItem.routeKey())
tabBarItem_objectName_fileName = "_".join(tabBarItem.routeKey().split("_")[1:]).replace("\\", "/")
# print(f"current tabBarItem_objectName_fileName:{tabBarItem_objectName_fileName}")
# 标签名存在文件名列表中且文件路径在目录列表中的时候 更新相关表格的数据
if tabBarItem_objectName_fileName in file_list:
# 转写结果已经存在的情况下更新数据
self.tableModel_list.pop(tabBarItem_objectName_fileName)
table_model = TableModel(results[file_list.index(tabBarItem_objectName_fileName)][0])
self.tableModel_list[tabBarItem_objectName_fileName] = table_model
# self.tableModel_list[tabBarItem_objectName_fileName]._data = results[file_list.index(tabBarItem_objectName_fileName)][0]
print(f"updata table:{tabBarItem_objectName_fileName}")
# self.tableModel_list.pop(tabBarItem_objectName_fileName)
# table_model = TableModel(results[file_list.index(tabBarItem_objectName_fileName)][0])
# self.tableModel_list[tabBarItem_objectName_fileName] = table_model
self.tableModel_list[tabBarItem_objectName_fileName]._data = results[file_list.index(tabBarItem_objectName_fileName)][0]

# 遍历转写结果列表,查找当前不存在的表格
tabBarItems_objectName_fileName = ["_".join(tabBarItem.objectName().split("_")[1:]).replace("\\", "/") for tabBarItem in self.page_output.tableTab.tabBar.items]
tabBarItems_objectName_fileName = ["_".join(tabBarItem.routeKey().split("_")[1:]).replace("\\", "/") for tabBarItem in self.page_output.tableTab.tabBar.items]
# print(f"-----tabBarItems_objectName_fileName:{tabBarItems_objectName_fileName}")
for file in file_list:
if not (file_list in tabBarItems_objectName_fileName):
if not (file in tabBarItems_objectName_fileName):
# print(f"table not exist: {[results[file_list.index(file)]]}")
self.createResultInTable([results[file_list.index(file)]])

def showResultInTable(self, results):
Expand Down Expand Up @@ -618,7 +620,7 @@ def transcribeOver(self, segments_path_info:list):
except Exception:
pass
while(self.transcribe_thread and self.transcribe_thread.isRunning()):
time.sleep(0.5)
time.sleep(0.3)

self.setStateTool(text=self.__tr("结束"), status=True)
self.transcribe_thread = None
Expand Down Expand Up @@ -650,7 +652,9 @@ def transcribeOver(self, segments_path_info:list):
if self.page_setting.combox_autoGoToOutputPage.currentIndex() == 0:
time.sleep(0.8)
self.stackedWidget.setCurrentWidget(self.page_output)

elif self.page_setting.combox_autoGoToOutputPage.currentIndex() == 2:
time.sleep(0.8)
mess_ = MessageBox(self.__tr("转写结束"),self.__tr("是否跳转到输出目录?"),self)
if mess_.exec():
time.sleep(0.8)
Expand Down
38 changes: 21 additions & 17 deletions faster_whisper_GUI/tableViewInterface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# coding:utf-8

import time
from PySide6.QtCore import (QCoreApplication, QModelIndex,
from PySide6.QtCore import (QCoreApplication,
QModelIndex,
Qt,
Signal
)
Expand Down Expand Up @@ -36,10 +37,10 @@
, TableItemDelegate
, HorizontalSeparator
, Router
, RoundMenu
, RoundMenu ,
MessageBoxBase,
SubtitleLabel,
)
from qfluentwidgets.components.dialog_box.message_box_base import MessageBoxBase
from qfluentwidgets.components.widgets.label import SubtitleLabel

from .style_sheet import StyleSheet
from .util import outputWithDateTime
Expand Down Expand Up @@ -195,7 +196,7 @@ def addSubInterface(self

if widget is None:
widget = CustomTableView()
widget.setObjectName(objectName)
# widget.setObjectName(objectName)

widget.setObjectName(objectName)

Expand All @@ -208,17 +209,25 @@ def addSubInterface(self
# 设置缩放策略
widget.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)

for i in range(self.stackedWidget.count()):
widget_i = self.stackedWidget.widget(i)
if widget_i.objectName() == objectName:
self.stackedWidget.removeWidget(widget_i)
# print(f"len_stack_items:{self.stackedWidget.count()}")

# 移除旧的结果
# for i in range(self.stackedWidget.count()):
# widget_i = self.stackedWidget.widget(i)
# if widget_i is None:
# self.stackedWidget.removeWidget(widget_i)
# break
# if widget_i.objectName() == objectName:
# print(f"excited objectName:{objectName}")
# self.stackedWidget.removeWidget(widget_i)
# break

# 添加子分页
print(f"addSubInterface:{objectName}")
self.stackedWidget.addWidget(widget)

# 已经存在的旧结果将会被清除
items = self.tabBar.items
items_rou = [item.routeKey() for item in items]
items_rou = [item.routeKey() for item in self.tabBar.items]

if objectName in items_rou:
self.tabBar.removeTab(items_rou.index(objectName))
Expand Down Expand Up @@ -248,7 +257,7 @@ def onDisplayModeChanged(self, index):
self.tabBar.setCloseButtonDisplayMode(mode)

def onCurrentIndexChanged(self, index):
print(f"currentTabIndexChangedTo:{index}")
# print(f"currentTabIndexChangedTo:{index}")
widget = self.stackedWidget.widget(index)
if not widget:
return
Expand Down Expand Up @@ -430,11 +439,6 @@ def copy_subtitle_content(self):
# content = self.model().index(index.row(), 2).data()
QApplication.clipboard().setText(content)

def custom_action_triggered(self):
index = self.currentIndex()
# 在这里执行自定义操作
print(f"Custom action triggered on row {index.row()} and column {index.column()}")

class EditSpeakerMessageBox(MessageBoxBase):
""" Custom message box """

Expand Down

0 comments on commit 3ebb991

Please sign in to comment.