From 19b3a15146b3b34d64c7d8c0eba1bbc505a7547e Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 21 Jan 2020 20:39:25 +1000 Subject: [PATCH] formatting fixes --- qt/aqt/mpv.py | 4 ++-- qt/aqt/sound.py | 2 +- qt/aqt/tts.py | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/qt/aqt/mpv.py b/qt/aqt/mpv.py index d5a84c3fb..59e63947d 100644 --- a/qt/aqt/mpv.py +++ b/qt/aqt/mpv.py @@ -113,9 +113,9 @@ class MPVBase: """ self.argv = [self.executable] self.argv += self.default_argv - self.argv += ["--input-ipc-server="+self._sock_filename] + self.argv += ["--input-ipc-server=" + self._sock_filename] if self.window_id is not None: - self.argv += ["--wid="+str(self.window_id)] + self.argv += ["--wid=" + str(self.window_id)] def _start_process(self): """Start the mpv process. diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index c6a483749..9f46b0ede 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -11,10 +11,10 @@ import time import wave from abc import ABC, abstractmethod from concurrent.futures import Future +from operator import itemgetter from typing import Any, Callable, Dict, List, Optional, Tuple import pyaudio -from operator import itemgetter import anki import aqt diff --git a/qt/aqt/tts.py b/qt/aqt/tts.py index feba27d8e..c33e44fdd 100644 --- a/qt/aqt/tts.py +++ b/qt/aqt/tts.py @@ -30,10 +30,10 @@ import re import subprocess from concurrent.futures import Future from dataclasses import dataclass -from typing import List, Optional, Any, cast +from typing import Any, List, Optional, cast from anki.sound import AVTag, TTSTag -from anki.utils import tmpdir, isWin, checksum +from anki.utils import checksum, isWin, tmpdir from aqt.sound import OnDoneCallback, PlayerInterrupted, SimpleProcessPlayer @@ -88,8 +88,7 @@ class TTSPlayer: No file extension is included.""" assert isinstance(tag, TTSTag) buf = f"{voice.name}-{voice.lang}-{tag.field_text}" - return os.path.join(tmpdir(), - f"tts-{checksum(buf)}") + return os.path.join(tmpdir(), f"tts-{checksum(buf)}") class TTSProcessPlayer(SimpleProcessPlayer, TTSPlayer): @@ -188,13 +187,16 @@ class MacTTSFilePlayer(MacTTSPlayer): # then tell player to advance, which will cause the file to be played cb() + # Windows support ########################################################################## + @dataclass class WindowsVoice(TTSVoice): handle: Any + if isWin: import win32com.client @@ -401,14 +403,13 @@ if isWin: "19466": "es_NI", "20490": "es_PR", "21514": "es_US", - "31748": "zh_CHT" + "31748": "zh_CHT", } def lcid_hex_str_to_lang_code(hex: str) -> str: dec_str = str(int(hex, 16)) return LCIDS.get(dec_str, "unknown") - class WindowsTTSPlayer(TTSProcessPlayer): speaker = win32com.client.Dispatch("SAPI.SpVoice") @@ -418,9 +419,9 @@ if isWin: def _voice_to_object(self, voice: Any): lang = voice.GetAttribute("language") lang = lcid_hex_str_to_lang_code(lang) - return WindowsVoice(name=voice.GetAttribute("name"), - lang=lang, - handle=voice) + return WindowsVoice( + name=voice.GetAttribute("name"), lang=lang, handle=voice + ) def _play(self, tag: AVTag) -> None: match = self.voice_for_tag(tag) @@ -436,8 +437,7 @@ if isWin: while not self.speaker.WaitUntilDone(100): if self._terminate_flag: # stop playing - self.speaker.Skip("Sentence", 2**15) + self.speaker.Skip("Sentence", 2 ** 15) return finally: self._terminate_flag = False -