From a70f8d4dd5aa1df964a4942bde6edae30b6d702a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 29 Nov 2022 13:04:51 +1000 Subject: [PATCH] Fix TTS handling on Windows Also update to winsdk, which unblocks Python updates on Windows --- .pylintrc | 2 +- docs/development.md | 8 ++++---- python/requirements.aqt.in | 2 +- python/requirements.win.in | 2 ++ python/requirements.win.txt | 13 +++++++++++++ python/update_win_deps.bat | 1 + qt/aqt/tts.py | 8 ++++---- 7 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 python/update_win_deps.bat diff --git a/.pylintrc b/.pylintrc index 21918469b..9cfb96505 100644 --- a/.pylintrc +++ b/.pylintrc @@ -44,4 +44,4 @@ good-names = ip, [IMPORTS] -ignored-modules = anki.*_pb2, anki.sync_pb2, win32file,pywintypes,socket,win32pipe,winrt,pyaudio,anki.scheduler_pb2 +ignored-modules = anki.*_pb2, anki.sync_pb2, win32file,pywintypes,socket,win32pipe,winsdk,pyaudio,anki.scheduler_pb2 diff --git a/docs/development.md b/docs/development.md index 9c8090ac2..574f2fd23 100644 --- a/docs/development.md +++ b/docs/development.md @@ -15,10 +15,10 @@ Pre-built Python packages are available on PyPI. They are useful if you wish to: - Get code completion when developing add-ons - Make command line scripts that modify .anki2 files via Anki's Python libraries -You will need the 64 bit version of Python 3.9 or 3.10 installed. 3.9 is -recommended, as Anki has only received minimal testing on 3.10 so far, and some -dependencies have not been fully updated yet. On Windows, currently only 3.9 -will work. You can install Python from python.org or from your distro. +You will need the 64 bit version of Python 3.9 or later installed. 3.9 is +recommended, as Anki has only received minimal testing on 3.10+ so far, and some +dependencies have not been fully updated yet. You can install Python from python.org +or from your distro. For further instructions, please see https://betas.ankiweb.net/#via-pypipip. Note that in the provided commands, `--pre` tells pip to fetch alpha/beta versions. If you remove diff --git a/python/requirements.aqt.in b/python/requirements.aqt.in index c17e196d2..a2b35ea18 100644 --- a/python/requirements.aqt.in +++ b/python/requirements.aqt.in @@ -7,4 +7,4 @@ send2trash waitress>=2.0.0 psutil; sys.platform == "win32" pywin32; sys.platform == "win32" -winrt; sys.platform == "win32" +winsdk; sys.platform == "win32" diff --git a/python/requirements.win.in b/python/requirements.win.in index 10c9d322f..b3f7ec49c 100644 --- a/python/requirements.win.in +++ b/python/requirements.win.in @@ -1 +1,3 @@ pywin32 +winsdk + diff --git a/python/requirements.win.txt b/python/requirements.win.txt index 65c2b6e3e..43b93c6d8 100644 --- a/python/requirements.win.txt +++ b/python/requirements.win.txt @@ -14,3 +14,16 @@ pywin32==305 \ --hash=sha256:9dd98384da775afa009bc04863426cb30596fd78c6f8e4e2e5bbf4edf8029504 \ --hash=sha256:a55db448124d1c1484df22fa8bbcbc45c64da5e6eae74ab095b9ea62e6d00496 # via -r requirements.win.in +winsdk==1.0.0b7 \ + --hash=sha256:0e3a07cbd1d63f046e11e87144a5d7fc592a0baf7518ed90c40d29efe1dd4708 \ + --hash=sha256:141f40a6a7819df0fe9511b7d31bebc7119cb4c643ee695e7069cea198868efc \ + --hash=sha256:51875edb889a94dbe24357277f56270eae0e3a1436acf5e596d36c95aef09977 \ + --hash=sha256:873ef6fd47f78830ccbe4fc47482056b881c6ae05eaca5ba5ddabef6fe32582e \ + --hash=sha256:955421aace349ef26cfc8dccbfaa716917a0f3c5043aaef3b1534ad7efd86bf6 \ + --hash=sha256:a49606148b3ecac1860e7fc17d31d7149925c0387c41e85be1c655572a3b24f6 \ + --hash=sha256:a653eca5a0e83f8e35f2d706a67160705ba7ac3200d29684e0821a61b00ab66c \ + --hash=sha256:b90367c2fda2f649cf2fa16dd49511d7c74db11fc0abac4a46e773d97fb340e2 \ + --hash=sha256:ccff00afe526a77f88b7f32e3a3924f3b7c83f2ea168665af449d2c0acfb4e4f \ + --hash=sha256:d2b389c3252774e5cef432e0236e7880fff1bff1a237724f9ed1ae0fc2635352 \ + --hash=sha256:e059d13117e6c57e95c6e0b3a6b67b432769b5301b89676a20d76452afdd213b + # via -r requirements.win.in diff --git a/python/update_win_deps.bat b/python/update_win_deps.bat new file mode 100644 index 000000000..2cee31f3f --- /dev/null +++ b/python/update_win_deps.bat @@ -0,0 +1 @@ +..\out\pyenv\scripts\pip-compile --resolver=backtracking --allow-unsafe --no-header --strip-extras --generate-hashes requirements.win.in diff --git a/qt/aqt/tts.py b/qt/aqt/tts.py index e8e917a2f..40906fc5e 100644 --- a/qt/aqt/tts.py +++ b/qt/aqt/tts.py @@ -552,12 +552,12 @@ if is_win: tmppath = os.path.join(tmpdir(), "tts.wav") def import_voices(self) -> None: - import winrt.windows.media.speechsynthesis as speechsynthesis # type: ignore + import winsdk.windows.media.speechsynthesis as speechsynthesis # type: ignore try: self.voice_list = speechsynthesis.SpeechSynthesizer.get_all_voices() except Exception as e: - print("winrt tts voices unavailable:", e) + print("winsdk tts voices unavailable:", e) self.voice_list = [] def get_available_voices(self) -> list[TTSVoice]: @@ -600,8 +600,8 @@ if is_win: cb() async def speakText(self, tag: TTSTag, voice_id: Any) -> None: - import winrt.windows.media.speechsynthesis as speechsynthesis # type: ignore - import winrt.windows.storage.streams as streams # type: ignore + import winsdk.windows.media.speechsynthesis as speechsynthesis # type: ignore + import winsdk.windows.storage.streams as streams # type: ignore synthesizer = speechsynthesis.SpeechSynthesizer()