Skip to content

Commit

Permalink
0.7.0 ass format support
Browse files Browse the repository at this point in the history
  • Loading branch information
CheshireCC committed Mar 19, 2024
1 parent a8a9fe2 commit de25779
Show file tree
Hide file tree
Showing 21 changed files with 3,815 additions and 3,566 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ python39/
python310/
python*/

requirements.txt
requirements_310.txt

.vscode/
Expand Down
2 changes: 1 addition & 1 deletion config/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"QFluentWidgets": {
"ThemeColor": "#ff009faa",
"ThemeColor": "#ff3522e7",
"ThemeMode": "Light"
}
}
388 changes: 230 additions & 158 deletions en.ts

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions fasterWhisperGUIConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"model_param": {
"localModel": true,
"onlineModel": false,
"model_path": "F:/WhisperModels/faster-whisper/large-v3-float32",
"model_path": "F:/WhisperModels/faster-whisper/whisper-tiny",
"modelName": 0,
"use_v3_model": true,
"use_v3_model": false,
"device": 1,
"deviceIndex": "0",
"preciese": 0,
Expand All @@ -21,7 +21,7 @@
},
"vad_param": {
"use_VAD": true,
"threshold": 0.5,
"threshold": 0.3,
"minSpeechDuration": "250",
"minSilenceDuration": "2000",
"maxSpeechDuration": "inf",
Expand All @@ -35,16 +35,16 @@
"huggingface_user_token": "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",
"autoGoToOutputPage": 2,
"autoClearTempFiles": true,
"themeColor": "#009faa"
"themeColor": "#3522e7"
},
"Transcription_param": {
"aggregate_contents": true,
"language": 3,
"language": 1,
"task": false,
"beam_size": "5",
"best_of": "5",
"patience": "1.0",
"length_penalty": "1.0",
"length_penalty": "1.8",
"temperature": "0.0,0.2,0.4,0.6,0.8,1.0",
"compression_ratio_threshold": "2.4",
"log_prob_threshold": "-1.0",
Expand Down
2 changes: 1 addition & 1 deletion faster_whisper_GUI/UI_MainWindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def readConfigJson(self, config_file_path: str = ""):

def setConfig(self):

setTheme(Theme.DARK if self.default_theme == "dark" else Theme.LIGHT)
setTheme(Theme.DARK if self.default_theme == "dark" else Theme.LIGHT, save=True, lazy=True)
# setThemeColor("#aaff009f")
if self.model_param != {}:
self.page_model.setParam(self.model_param)
Expand Down
2 changes: 1 addition & 1 deletion faster_whisper_GUI/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@

STR_BOOL = {"False" : False, "True" : True}

SUBTITLE_FORMAT = ["SRT", "TXT", "VTT", "LRC", "SMI", "JSON"]
SUBTITLE_FORMAT = ["ASS", "JSON", "LRC", "SMI", "SRT", "TXT", "VTT"]

CAPTURE_PARA = [
{"rate": 44100
Expand Down
9 changes: 7 additions & 2 deletions faster_whisper_GUI/homePageItemLabel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding:utf-8

from PySide6.QtCore import Qt
from PySide6.QtCore import QObject, Qt
from PySide6.QtWidgets import (
QHBoxLayout,
QPushButton,
Expand All @@ -11,10 +11,15 @@
from .style_sheet import StyleSheet

class ItemLabel(QWidget):

def parent(self) -> QObject:
return super().parent()

def __init__(self, parent, title:str, subTitle:str) -> None:
# self.parent = parent
super().__init__(parent=parent)

self.parent = parent
# self.parent = parent

self.vBoxLayout = QVBoxLayout()
self.setLayout(self.vBoxLayout)
Expand Down
10 changes: 7 additions & 3 deletions faster_whisper_GUI/homePageNavigationInterface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding:utf-8

from PySide6.QtCore import QEasingCurve, Qt
from PySide6.QtCore import QEasingCurve, QObject, Qt
from .navigationInterface import NavigationBaseInterface

from .homePageItemLabel import ItemLabel
Expand All @@ -10,7 +10,11 @@


class HomePageNavigationinterface(NavigationBaseInterface):
def parent(self) -> QObject:
return super().parent()

def __init__(self, parent=None):
# self.parent = parent
super().__init__(title=self.tr("Home"), subtitle=self.tr("faster-whisper 为主要后端的 ASR 及 AVE 软件"), parent=parent)
self.steupUI()

Expand All @@ -27,8 +31,8 @@ def steupUI(self):
self.hBoxLayout.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.hBoxLayout.setAnimation(250, QEasingCurve.OutQuad)
self.addLayout(self.hBoxLayout)
self.itemLabel_demucs = ItemLabel( self,

self.itemLabel_demucs = ItemLabel( self,
self.tr("Demucs"),
self.tr("自动人声提取")
)
Expand Down
44 changes: 33 additions & 11 deletions faster_whisper_GUI/mainWindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
, InfoBarPosition
, InfoBarIcon
, MessageBox
, TableView
# , TableView
, FluentIcon
, isDarkTheme
)
Expand Down Expand Up @@ -526,7 +526,10 @@ def changeTableData(self, results) -> None:
# 标签名存在文件名列表中且文件路径在目录列表中的时候 更新相关表格的数据
if tabBarItem_objectName_fileName in file_list:
# 转写结果已经存在的情况下更新数据
self.tableModel_list[tabBarItem_objectName_fileName]._data = results[file_list.index(tabBarItem_objectName_fileName)][0]
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]
Expand All @@ -535,6 +538,24 @@ def changeTableData(self, results) -> None:
self.createResultInTable([results[file_list.index(file)]])

def showResultInTable(self, results):

# tabBarItems = self.page_output.tableTab.tabBar.items

# # 遍历表格标签
# for tabBarItem in tabBarItems:
# # 清理掉已经过时的结果
# index = tabBarItems.index(tabBarItem)
# self.page_output.tableTab.tabBar.removeTab(index)

# # 遍历stack下的表格控件
# for i in range(self.page_output.tableTab.stackedWidget.count()):
# widget = self.page_output.tableTab.stackedWidget.widget(i)
# # 移除全部表格控件
# self.page_output.tableTab.stackedWidget.removeWidget(widget)

# 创建数据表
# self.createResultInTable(results=results)

if len(self.tableModel_list) == 0:
print("Create Tables")
self.createResultInTable(results=results)
Expand Down Expand Up @@ -927,12 +948,12 @@ def aligmentOver(self, segments_path_info:list):

self.result_whisperx_aligment = segments_path_info
if self.result_whisperx_aligment is not None:
self.showResultInTable(results=self.result_whisperx_aligment)
self.current_result = self.result_whisperx_aligment
self.showResultInTable(results=self.current_result)
self.raiseSuccessInfoBar(
title=self.tr("WhisperX")
, content=self.tr("时间戳对齐结束")
)
self.current_result = self.result_whisperx_aligment

else:
self.raiseErrorInfoBar(
Expand Down Expand Up @@ -1044,13 +1065,13 @@ def speakerDiarizeOver(self, segments_path_info:list):

self.result_whisperx_speaker_diarize = segments_path_info
if self.result_whisperx_speaker_diarize is not None:
self.showResultInTable(results=self.result_whisperx_speaker_diarize)
self.current_result = self.result_whisperx_speaker_diarize
self.showResultInTable(results=self.current_result)
self.raiseSuccessInfoBar(
title=self.tr("WhisperX")
, content=self.tr("声源分离结束")
)
self.current_result = self.result_whisperx_speaker_diarize


# for segments in self.result_whisperx_speaker_diarize:
# segment_, path, info = segments
# print(path, info.language)
Expand Down Expand Up @@ -1155,7 +1176,7 @@ def openExcitedFiles(self):
file_subtitle_fileName,ext_ = QFileDialog.getOpenFileName(
self,
self.tr("选择字幕文件"),
file_subtitle_fileName,
"",
# self.page_process.fileNameListView.avDataRootDir,
"JSON file(*.json);;SRT file(*.srt)",
)
Expand Down Expand Up @@ -1208,8 +1229,10 @@ def openExcitedFiles(self):
else:
self.current_result = [(segments, file, info)]
# self.tableModel_list[file] = file_subtitle_fileName

self.createResultInTable(self.current_result)

self.showResultInTable(self.current_result)
# self.showResultInTable(self.current_result)

def reSetButton_demucs_process(self):
self.page_demucs.process_button.setText(self.tr("提取"))
Expand Down Expand Up @@ -1521,8 +1544,6 @@ def raiseInfoBar(self, title:str, content:str ):
)

def deleteResultTableEvent(self, routeKey:str):

self.outputWithDateTime("deleteTable")

print(f"len_DataModel:{len(self.tableModel_list)}")
for tb in self.tableModel_list.items():
Expand All @@ -1545,6 +1566,7 @@ def deleteResultTableEvent(self, routeKey:str):
self.current_result = None
except Exception:
pass

try:
print(f"len_result_faster_whisper_after_pop: {len(self.result_faster_whisper)}")
if self.result_faster_whisper is not None and len(self.result_faster_whisper) == 0:
Expand Down
2 changes: 1 addition & 1 deletion faster_whisper_GUI/navigationInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __initWidget(self):
self.questionButton.setToolTip(self.tr('关于'))
self.openDirButton.setToolTip(self.tr("打开主目录"))

self.themeButton.clicked.connect(lambda: toggleTheme(True))
self.themeButton.clicked.connect(lambda: toggleTheme(True,True))
# self.supportButton.clicked.connect(signalBus.supportSignal)
# self.documentButton.clicked.connect(
# lambda: QDesktopServices.openUrl(QUrl(HELP_URL)))
Expand Down
6 changes: 3 additions & 3 deletions faster_whisper_GUI/outputPageNavigationInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def setupUI(self):

# =============================================================================================
# 添加放置表格的标签导航页
self.tableTab = TabInterface()
self.tableTab = TabInterface(self)
self.tableTab.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
self.addWidget(self.tableTab)
self.tableTab.setFixedHeight(735)
Expand All @@ -113,10 +113,10 @@ def setupUI(self):
self.SpinBox_max_speaker = SpinBox()
self.SpinBox_max_speaker.setToolTip(self.tr("音频中需分出来的最多的说话人的人数"))

self.controlLabel_wshiperx = StrongBodyLabel(self.tr("whisperX 参数控制"))
self.controlLabel_whisperx = StrongBodyLabel(self.tr("whisperX 参数控制"))

self.tableTab.panelLayout.addSpacing(15)
self.tableTab.panelLayout.addWidget(self.controlLabel_wshiperx)
self.tableTab.panelLayout.addWidget(self.controlLabel_whisperx)
self.tableTab.panelLayout.addWidget(HorizontalSeparator())

self.tableTab.panelLayout.addSpacing(4)
Expand Down
6 changes: 3 additions & 3 deletions faster_whisper_GUI/settingPageNavigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,17 @@ def setColorAndThemeColorRandom(self):

self.themeColor_str = THEME_COLORS[index]
self.colorPickerButton.setColor(self.themeColor_str)
setThemeColor(self.themeColor_str)
setThemeColor(self.themeColor_str, save=True, lazy=True)
self.themeColorLineEdit.setText(self.themeColor_str)

def setThemeColorAndText(self):
self.themeColor_str = self.colorPickerButton.color.name()
self.themeColorLineEdit.setText(self.themeColor_str)
setThemeColor(self.themeColor_str)
setThemeColor(self.themeColor_str, save=True, lazy=True)

def setThemeColorWithLineEditText(self,text):
if len(text) == 7:
self.colorPickerButton.setColor(text)
setThemeColor(text)
setThemeColor(text, save=True, lazy=True)
self.themeColor_str = text

29 changes: 20 additions & 9 deletions faster_whisper_GUI/subtitleFileRead.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@
def readJSONFileToSegments(file:str, file_code = "utf8") -> List[segment_Transcribe]:

with open(os.path.abspath(file),"r", encoding= file_code) as fp:
subtitles_str = json.load(fp=fp)["body"]
segments = [ segment_Transcribe(
start=subtitle["from"],
end=subtitle["to"],
text=subtitle["content"],
words=[ Word(word["start"],word["end"],word["word"],word["probability"]) for word in subtitle["words"]],
speaker=subtitle["speaker"] or None
) for subtitle in subtitles_str
]
subtitles_str = json.load(fp=fp)["data"]
try:
segments = [ segment_Transcribe(
start=subtitle["start"]["time"] / 1000.0,
end=subtitle["end"]["time"] / 1000.0,
text=subtitle["content"],
words=[ Word(word["start"],word["end"],word["word"],word["probability"]) for word in subtitle["words"]],
speaker=subtitle["speaker"] or None
) for subtitle in subtitles_str
]
except Exception as e:
print(f"{str(e)}")
segments = [ segment_Transcribe(
start=subtitle["from"],
end=subtitle["to"],
text=subtitle["content"],
words=[],
speaker=subtitle["speaker"] or None
) for subtitle in subtitles_str
]
return segments


Expand Down
Loading

0 comments on commit de25779

Please sign in to comment.