Skip to content

Commit

Permalink
fix TranscribeModelEnum inconsistent problem
Browse files Browse the repository at this point in the history
  • Loading branch information
philpw99 committed Jan 21, 2025
1 parent 978df66 commit e9eedad
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/core/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class Type(Enum):
audio_save_path: Optional[str] = None

# 转录(转录模型)
transcribe_model: Optional[TranscribeModelEnum] = TranscribeModelEnum.JIANYING
transcribe_model: Optional[TranscribeModelEnum] = TranscribeModelEnum.JIANYING.value
transcribe_language: Optional[TranscribeLanguageEnum] = LANGUAGES[TranscribeLanguageEnum.ENGLISH.value]
use_asr_cache: bool = True
need_word_time_stamp: bool = False
Expand Down
22 changes: 11 additions & 11 deletions app/core/thread/create_task_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def create_file_task(self, file_path, soft_sub: bool, need_video: bool):
video_info = VideoInfo(**video_info)

match cfg.transcribe_model.value:
case TranscribeModelEnum.WHISPER:
case TranscribeModelEnum.WHISPER.value:
whisper_type = f"-{cfg.whisper_model.value.value}-{cfg.transcribe_language.value.value}"
case TranscribeModelEnum.WHISPER_API:
case TranscribeModelEnum.WHISPER_API.value:
whisper_type = f"-{cfg.whisper_api_model.value}-{cfg.transcribe_language.value.value}"
case TranscribeModelEnum.FASTER_WHISPER:
case TranscribeModelEnum.FASTER_WHISPER.value:
whisper_type = f"-{cfg.faster_whisper_model.value.value}-{cfg.transcribe_language.value.value}"
case _:
whisper_type = ""
Expand All @@ -89,7 +89,7 @@ def create_file_task(self, file_path, soft_sub: bool, need_video: bool):
else:
subtitle_style_srt = None

need_word_time_stamp = cfg.transcribe_model.value in [TranscribeModelEnum.JIANYING, TranscribeModelEnum.BIJIAN]
need_word_time_stamp = cfg.transcribe_model.value in [TranscribeModelEnum.JIANYING.value, TranscribeModelEnum.BIJIAN.value]

# 创建 Task 对象
task = Task(
Expand Down Expand Up @@ -178,18 +178,18 @@ def create_url_task(self, url, soft_sub: bool, need_video: bool):
file_name = file_full_path.stem

match cfg.transcribe_model.value:
case TranscribeModelEnum.WHISPER:
case TranscribeModelEnum.WHISPER.value:
whisper_type = f"{cfg.whisper_model.value.value}-{cfg.transcribe_language.value.value}"
case TranscribeModelEnum.WHISPER_API:
whisper_type = f"{cfg.whisper_api_model.value}-{cfg.transcribe_language.value.value}"
case TranscribeModelEnum.FASTER_WHISPER:
case TranscribeModelEnum.WHISPER_API.value:
whisper_type = f"{cfg.whisper_api_model.value.value}-{cfg.transcribe_language.value.value}"
case TranscribeModelEnum.FASTER_WHISPER.value:
whisper_type = f"{cfg.faster_whisper_model.value.value}-{cfg.transcribe_language.value.value}"
case _:
whisper_type = ""

# 定义各个路径
audio_save_path = task_work_dir / f"{self.tr("【音频】")}{Path(video_file_path).stem}.wav"
original_subtitle_save_path = task_work_dir / f"{self.tr("【原始字幕】")}{cfg.transcribe_model.value.value}-file_name-{whisper_type}.srt" if not subtitle_file_path else subtitle_file_path
original_subtitle_save_path = task_work_dir / f"{self.tr("【原始字幕】")}{cfg.transcribe_model.value}-file_name-{whisper_type}.srt" if not subtitle_file_path else subtitle_file_path
result_subtitle_save_path = task_work_dir / ( cfg.subtitle_file_prefix.value + file_name + cfg.subtitle_file_suffix.value + "." + cfg.subtitle_output_format.value.value )
video_save_path = task_work_dir / f"{self.tr("【生成】")}{Path(video_file_path).name}"

Expand All @@ -198,7 +198,7 @@ def create_url_task(self, url, soft_sub: bool, need_video: bool):
if video_info.audio_codec in ["mp3", "pcm"]:
audio_format = "copy"

if cfg.transcribe_model.value in [TranscribeModelEnum.JIANYING, TranscribeModelEnum.BIJIAN]:
if cfg.transcribe_model.value in [TranscribeModelEnum.JIANYING.value, TranscribeModelEnum.BIJIAN.value]:
need_word_time_stamp = True
else:
need_word_time_stamp = False
Expand Down Expand Up @@ -300,7 +300,7 @@ def create_transcription_task(self, file_path):
audio_format = "copy"

audio_save_path = task_work_dir / f"Audio_{file_name}.wav"
original_subtitle_save_path = task_work_dir / f"【原始字幕】{file_name}-{cfg.transcribe_model.value.value}-{whisper_type}.srt"
original_subtitle_save_path = task_work_dir / f"【原始字幕】{file_name}-{cfg.transcribe_model.value}-{whisper_type}.srt"
result_subtitle_save_path = file_full_path.parent / ( cfg.subtitle_file_prefix.value + file_name + cfg.subtitle_file_suffix.value + "." + cfg.subtitle_output_format.value.value )

if cfg.subtitle_output_format.value.value == "ass":
Expand Down
12 changes: 6 additions & 6 deletions app/core/thread/transcript_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def run(self):
"need_word_time_stamp": self.task.need_word_time_stamp,
}
match self.task.transcribe_model:
case TranscribeModelEnum.WHISPER:
case TranscribeModelEnum.WHISPER.value:
args["language"] = self.task.transcribe_language
args["whisper_model"] = self.task.whisper_model
args["use_cache"] = False
args["need_word_time_stamp"] = True
self.asr = WhisperASR(self.task.audio_save_path, **args)
case TranscribeModelEnum.WHISPER_API:
case TranscribeModelEnum.WHISPER_API.value:
args["language"] = self.task.transcribe_language
args["whisper_model"] = self.task.whisper_api_model
args["api_key"] = self.task.whisper_api_key
Expand All @@ -122,7 +122,7 @@ def run(self):
args["use_cache"] = False
args["need_word_time_stamp"] = True
self.asr = WhisperAPI(self.task.audio_save_path, **args)
case TranscribeModelEnum.FASTER_WHISPER:
case TranscribeModelEnum.FASTER_WHISPER.value:
args["faster_whisper_path"] = cfg.faster_whisper_program.value
args["whisper_model"] = self.task.faster_whisper_model.value
args["model_dir"] = str(MODEL_PATH)
Expand Down Expand Up @@ -153,9 +153,9 @@ def run(self):
args["repetition_penalty"] = self.task.faster_whisper_repetion_penalty

self.asr = FasterWhisperASR(self.task.audio_save_path, **args)
case TranscribeModelEnum.BIJIAN:
case TranscribeModelEnum.BIJIAN.value:
self.asr = BcutASR(self.task.audio_save_path, **args)
case TranscribeModelEnum.JIANYING:
case TranscribeModelEnum.JIANYING.value:
self.asr = JianYingASR(self.task.audio_save_path, **args)
case _:
raise ValueError(self.tr("无效的转录模型: ") + str(self.task.transcribe_model))
Expand Down Expand Up @@ -215,5 +215,5 @@ def progress_callback(self, value, message):

# Is the current config is using FasterWhipser and translate to English?
def isFasterWhisperTranslate(self):
return cfg.transcribe_model.value == TranscribeModelEnum.FASTER_WHISPER and cfg.faster_whisper_translate_to_english.value
return cfg.transcribe_model.value == TranscribeModelEnum.FASTER_WHISPER.value and cfg.faster_whisper_translate_to_english.value

2 changes: 1 addition & 1 deletion app/view/batch_process_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def update_tooltip(self):
if self.task.portrait_background:
strategy_text += "\n" + self.tr("竖屏背景:") + self.task.portrait_background

tooltip = self.tr("任务类型:") + self.task.type.value + " " + self.tr("转录模型:") + self.task.transcribe_model.value + "\n"
tooltip = self.tr("任务类型:") + self.task.type.value + " " + self.tr("转录模型:") + self.task.transcribe_model + "\n"
if len(self.task.file_path) > 100:
tooltip += self.tr("文件: ") + self.task.file_path[:50] + "..." + Path(self.task.file_path).name + "\n"
else:
Expand Down
2 changes: 1 addition & 1 deletion app/view/setting_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, parent=None):
FIF.MICROPHONE,
self.tr('转录模型'),
self.tr('语音转换文字要使用的转录模型'),
texts=[model.value for model in cfg.transcribe_model.validator.options],
texts=[ model.value for model in TranscribeModelEnum ],
parent=self.transcribeGroup
)
self.whisperSettingCard = HyperlinkCard(
Expand Down
15 changes: 8 additions & 7 deletions app/view/task_creation_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def on_target_language_changed(self, language: str):
self.target_language_card.comboBox.setCurrentText(language)

def setup_values(self):
self.transcription_model_card.setValue(cfg.transcribe_model.value.value)
self.transcription_model_card.setValue(cfg.transcribe_model.value)
self.target_language_card.setValue(cfg.target_language.value.value)
self.subtitle_optimization_card.setChecked(cfg.need_optimize.value)
self.subtitle_translation_card.setChecked(cfg.need_translate.value)
Expand All @@ -312,12 +312,13 @@ def setup_values(self):

def on_transcription_model_changed(self, value):
"""当转录模型改变时触发"""
cfg.set(cfg.transcribe_model, TranscribeModelEnum(value))
self.whisper_setting_button.setVisible(
value == TranscribeModelEnum.WHISPER.value or
value == TranscribeModelEnum.WHISPER_API.value or
value == TranscribeModelEnum.FASTER_WHISPER.value
)
if value in [model.value for model in TranscribeModelEnum]:
cfg.set(cfg.transcribe_model, value)
self.whisper_setting_button.setVisible(
value == TranscribeModelEnum.WHISPER.value or
value == TranscribeModelEnum.WHISPER_API.value or
value == TranscribeModelEnum.FASTER_WHISPER.value
)

def show_whisper_settings(self):
"""显示Whisper设置对话框"""
Expand Down
12 changes: 8 additions & 4 deletions app/view/transcription_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def setup_signals(self):

def show_whisper_settings(self):
"""显示Whisper设置对话框"""
if cfg.transcribe_model.value == TranscribeModelEnum.WHISPER:
if cfg.transcribe_model.value == TranscribeModelEnum.WHISPER.value:
dialog = WhisperSettingDialog(self.window())
if dialog.exec_():
return True
elif cfg.transcribe_model.value == TranscribeModelEnum.WHISPER_API:
elif cfg.transcribe_model.value == TranscribeModelEnum.WHISPER_API.value:
dialog = WhisperAPISettingDialog(self.window())
if dialog.exec_():
return True
elif cfg.transcribe_model.value == TranscribeModelEnum.FASTER_WHISPER:
elif cfg.transcribe_model.value == TranscribeModelEnum.FASTER_WHISPER.value:
dialog = FasterWhisperSettingDialog(self.window())
if dialog.exec_():
return True
Expand All @@ -159,7 +159,11 @@ def show_whisper_settings(self):
def on_start_button_clicked(self):
"""开始转录按钮点击事件"""
if self.task.status == Task.Status.TRANSCRIBING:
need_whisper_settings = cfg.transcribe_model.value in [TranscribeModelEnum.WHISPER, TranscribeModelEnum.WHISPER_API, TranscribeModelEnum.FASTER_WHISPER]
need_whisper_settings = cfg.transcribe_model.value in [
TranscribeModelEnum.WHISPER.value,
TranscribeModelEnum.WHISPER_API.value,
TranscribeModelEnum.FASTER_WHISPER.value
]
if need_whisper_settings and not self.show_whisper_settings():
return
self.progress_ring.show()
Expand Down

0 comments on commit e9eedad

Please sign in to comment.