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
This commit is contained in:
Damien Elmes 2023-02-16 17:37:49 +10:00
parent bf10bbbb62
commit d6a18d2d71

View file

@ -266,8 +266,6 @@ class WindowsVoice(TTSVoice):
if is_win: if is_win:
import win32com.client # pylint: disable=import-error
# language ID map from https://github.com/sindresorhus/lcid/blob/master/lcid.json # language ID map from https://github.com/sindresorhus/lcid/blob/master/lcid.json
LCIDS = { LCIDS = {
"4": "zh_CHS", "4": "zh_CHS",
@ -482,8 +480,11 @@ if is_win:
class WindowsTTSPlayer(TTSProcessPlayer): class WindowsTTSPlayer(TTSProcessPlayer):
default_rank = -1 default_rank = -1
try: try:
import win32com.client # pylint: disable=import-error
speaker = win32com.client.Dispatch("SAPI.SpVoice") speaker = win32com.client.Dispatch("SAPI.SpVoice")
except: except Exception as exc:
print("unable to activate sapi:", exc)
speaker = None speaker = None
def get_available_voices(self) -> list[TTSVoice]: def get_available_voices(self) -> list[TTSVoice]: