Skip to content

Commit

Permalink
fixed bugs #61
Browse files Browse the repository at this point in the history
  • Loading branch information
CheshireCC committed Jan 9, 2024
1 parent 3ddb113 commit 22b1b9a
Show file tree
Hide file tree
Showing 22 changed files with 439 additions and 227 deletions.
14 changes: 0 additions & 14 deletions FasterWhisperGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
faster_whisper_logger_handler.setFormatter(formatter1)
logger_faster_whisper.addHandler(faster_whisper_logger_handler)

# pyside6 日志
# logger_pyside = logging.getLogger("faster_whisper_GUI")
# logger_pyside.setLevel(logging.DEBUG)
# pyside_logger_handler = logging.FileHandler(r"./pyside.log", mode="w")
# pyside_logger_handler.setLevel(logging.DEBUG)
# formatter2 = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s",datefmt='%Y-%m-%d_%H:%M:%S')
# pyside_logger_handler.setFormatter(formatter2)
# logger_pyside.addHandler(pyside_logger_handler)

# # 将默认的递归深度修改为3000
# sys.setrecursionlimit(7000)

Expand All @@ -43,20 +34,17 @@

from qfluentwidgets import ProgressBar


class MySplashScreen(QSplashScreen):
# 鼠标点击事件
def mousePressEvent(self, event):
pass

from resource import rc_Image


# 启动一个Qt程序,并使用传入的系统参数
app = QApplication(sys.argv)
app.setObjectName("FasterWhisperGUIAPP")


#设置启动界面
splash = MySplashScreen()

Expand Down Expand Up @@ -84,8 +72,6 @@ def mousePressEvent(self, event):
# 显示启动界面
splash.show()



# app.processEvents() # 处理主进程事件

import os
Expand Down
6 changes: 6 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"QFluentWidgets": {
"ThemeColor": "#ffdb4437",
"ThemeMode": "Light"
}
}
13 changes: 7 additions & 6 deletions fasterWhisperGUIConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"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": 5,
"thread_num": "4",
"num_worker": "1",
"download_root": "C:/Users/12059/.cache/huggingface/hub",
"download_root": "",
"local_files_only": false
},
"vad_param": {
Expand All @@ -34,16 +34,17 @@
"language": 2,
"huggingface_user_token": "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",
"autoGoToOutputPage": 2,
"autoClearTempFiles": true
"autoClearTempFiles": true,
"themeColor": "#009faa"
},
"Transcription_param": {
"language": 0,
"language": 1,
"task": false,
"beam_size": "5",
"best_of": "1",
"patience": "1.0",
"length_penalty": "1.0",
"temperature": "0.5",
"temperature": "0.3",
"compression_ratio_threshold": "2.4",
"log_prob_threshold": "-1.0",
"no_speech_threshold": "0.6",
Expand All @@ -65,7 +66,7 @@
"tabMovable": false,
"tabScrollable": true,
"tabShadowEnabled": false,
"tabMaxWidth": 300,
"tabMaxWidth": 403,
"closeDisplayMode": 0,
"whisperXMinSpeaker": 2,
"whisperXMaxSpeaker": 2,
Expand Down
27 changes: 23 additions & 4 deletions faster_whisper_GUI/UI_MainWindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
NavigationAvatarWidget,
NavigationInterface
, setTheme
, setThemeColor
, Theme
, FluentIcon
, NavigationItemPosition
Expand Down Expand Up @@ -86,9 +87,20 @@ def tr(self, text):
# app.installTranslator(self.translator)


def readConfigJson(self):
def readConfigJson(self, config_file_path: str = ""):
self.default_theme = "light"
self.model_param = {}
self.setting = {}
self.demucs = {}
self.Transcription_param = {}
self.output_whisperX_param = {}
self.vad_param = {}

if not config_file_path:
return

self.use_auth_token_speaker_diarition= ""
with open(r"./fasterWhisperGUIConfig.json","r", encoding="utf8") as fp:
with open(os.path.abspath(config_file_path),"r", encoding="utf8") as fp:
json_data = json.load(fp)

try:
Expand Down Expand Up @@ -130,6 +142,7 @@ def readConfigJson(self):
def setConfig(self):

setTheme(Theme.DARK if self.default_theme == "dark" else Theme.LIGHT)
# setThemeColor("#aaff009f")
if self.model_param != {}:
self.page_model.setParam(self.model_param)
if not self.model_param["download_root"]:
Expand Down Expand Up @@ -165,7 +178,6 @@ def __init__(self, translator:QTranslator=None):
else:
self.translator = translator

# TODO: 无边框窗口方案需要等待 pyside6>6.5.0 支持
# self.setWindowFlags(Qt.FramelessWindowHint)
# self.setAttribute(Qt.WA_TranslucentBackground)

Expand All @@ -186,17 +198,24 @@ def __init__(self, translator:QTranslator=None):
self.initWin()

# 读配置文件
self.readConfigJson()
self.readConfigJson(r"./fasterWhisperGUIConfig.json")
# 设置配置
self.setConfig()

try:
self.setWidgetsStatusFromConfig()
except Exception as e:
print(str(e))

def setWidgetsStatusFromConfig(self):
# 根据读取的配置设置完控件状态之后,根据控件状态设置相关属性
self.page_output.tableTab.onDisplayModeChanged(self.page_output.tableTab.closeDisplayModeComboBox.currentIndex())
self.page_output.tableTab.tabBar.setMovable(self.page_output.tableTab.movableCheckBox.isChecked())
self.page_output.tableTab.tabBar.setScrollable(self.page_output.tableTab.scrollableCheckBox.isChecked())
self.page_output.tableTab.tabBar.setTabShadowEnabled(self.page_output.tableTab.shadowEnabledCheckBox.isChecked())
self.page_output.tableTab.tabBar.setTabMaximumWidth(self.page_output.tableTab.tabMaxWidthSpinBox.value())


def initWin(self):

self.setObjectName("FramlessMainWin")
Expand Down
28 changes: 28 additions & 0 deletions faster_whisper_GUI/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,31 @@
"GB2312":"gb18030",
"ANSI":"ansi"
}

THEME_COLORS = [
"#009faa",
"#ff009f",
"#84BE84",
"#aaff00",
"#FF9500",
"#00CD00",
"#DB4437",
"#23CD5E",
"#E61D34",
"#00FF00",
"#FF00FF",
"#1ABC9C",
"#FF3300",
"#FFFF00",
"#FFC019",
"#FF6600",
"#00FFFF",
"#FF7A1D",
"#E71A1B",
"#FF8800",
"#3388FF",
"#F4B400",
"#0069B7",
"#FFCC00",
"#0078D4",
]
15 changes: 10 additions & 5 deletions faster_whisper_GUI/de_mucs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run(self) -> None:
self.file_process_status.emit({"file":"", "status":False, "task": "load model"})
if self.model is None:
try:
self.loadModel(self.model_path,device=device)
self.loadModel(self.model_path, device=device)
except Exception as e:
print(f"load model error: \n{str(e)}")
self.signal_vr_over.emit(False)
Expand All @@ -78,7 +78,9 @@ def run(self) -> None:

try:
samples = self.reSampleAudio(audio, 44100, device=device)
samples = torch.tensor(samples,dtype=torch.float32).to(device)
samples = np.asarray(samples)
print("samples shape: ", samples.shape)
# samples = torch.tensor(samples,dtype=torch.float32).to(device)
except Exception as e:
print(f"resample audio error:\n{str(e)}")
self.signal_vr_over.emit(False)
Expand All @@ -96,15 +98,16 @@ def run(self) -> None:
self.file_process_status.emit({"file":audio, "status":False, "task": "separate sources"})

try:
sources = self.separate_sources(self.model,
sources = self.separate_sources(
self.model,
samples[None],
self.segment,
self.overlap,
device,
self.sampleRate
)
except Exception as e:
print(f"separate audio sources error:\n{str(e)}")
print(f"\nseparate audio sources error:\n {str(e)}")
self.signal_vr_over.emit(False)
self.stop()

Expand Down Expand Up @@ -192,7 +195,8 @@ def separate_sources(self,
be on `device`, while the entire tracks will be stored on `mix.device`.
"""
if device is None:
device = mix.device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
else:
device = device

Expand All @@ -211,6 +215,7 @@ def separate_sources(self,
return None

chunk = mix[:, :, start:end]
chunk = torch.tensor(chunk, dtype=torch.float32).to(device)
with torch.no_grad():
out = model.forward(chunk)

Expand Down
Loading

0 comments on commit 22b1b9a

Please sign in to comment.