From d6a18d2d71021b144b7ccab7059a838bbc7914fb Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 16 Feb 2023 17:37:49 +1000 Subject: [PATCH] Handle the case where win32com.client fails to import Hopefully fixes the "no attribute 'Flags'" issue: https://forums.ankiweb.net/t/technical-issue-with-anki-desktop/27089 --- qt/aqt/tts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/qt/aqt/tts.py b/qt/aqt/tts.py index e1841afa3..c3f4d36bb 100644 --- a/qt/aqt/tts.py +++ b/qt/aqt/tts.py @@ -266,8 +266,6 @@ class WindowsVoice(TTSVoice): if is_win: - import win32com.client # pylint: disable=import-error - # language ID map from https://github.com/sindresorhus/lcid/blob/master/lcid.json LCIDS = { "4": "zh_CHS", @@ -482,8 +480,11 @@ if is_win: class WindowsTTSPlayer(TTSProcessPlayer): default_rank = -1 try: + import win32com.client # pylint: disable=import-error + speaker = win32com.client.Dispatch("SAPI.SpVoice") - except: + except Exception as exc: + print("unable to activate sapi:", exc) speaker = None def get_available_voices(self) -> list[TTSVoice]: