mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
formatting fixes
This commit is contained in:
parent
37d2a4d43c
commit
19b3a15146
3 changed files with 14 additions and 14 deletions
|
@ -11,10 +11,10 @@ import time
|
||||||
import wave
|
import wave
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from concurrent.futures import Future
|
from concurrent.futures import Future
|
||||||
|
from operator import itemgetter
|
||||||
from typing import Any, Callable, Dict, List, Optional, Tuple
|
from typing import Any, Callable, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
import pyaudio
|
import pyaudio
|
||||||
from operator import itemgetter
|
|
||||||
|
|
||||||
import anki
|
import anki
|
||||||
import aqt
|
import aqt
|
||||||
|
|
|
@ -30,10 +30,10 @@ import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from concurrent.futures import Future
|
from concurrent.futures import Future
|
||||||
from dataclasses import dataclass
|
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.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
|
from aqt.sound import OnDoneCallback, PlayerInterrupted, SimpleProcessPlayer
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,8 +88,7 @@ class TTSPlayer:
|
||||||
No file extension is included."""
|
No file extension is included."""
|
||||||
assert isinstance(tag, TTSTag)
|
assert isinstance(tag, TTSTag)
|
||||||
buf = f"{voice.name}-{voice.lang}-{tag.field_text}"
|
buf = f"{voice.name}-{voice.lang}-{tag.field_text}"
|
||||||
return os.path.join(tmpdir(),
|
return os.path.join(tmpdir(), f"tts-{checksum(buf)}")
|
||||||
f"tts-{checksum(buf)}")
|
|
||||||
|
|
||||||
|
|
||||||
class TTSProcessPlayer(SimpleProcessPlayer, TTSPlayer):
|
class TTSProcessPlayer(SimpleProcessPlayer, TTSPlayer):
|
||||||
|
@ -188,13 +187,16 @@ class MacTTSFilePlayer(MacTTSPlayer):
|
||||||
# then tell player to advance, which will cause the file to be played
|
# then tell player to advance, which will cause the file to be played
|
||||||
cb()
|
cb()
|
||||||
|
|
||||||
|
|
||||||
# Windows support
|
# Windows support
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class WindowsVoice(TTSVoice):
|
class WindowsVoice(TTSVoice):
|
||||||
handle: Any
|
handle: Any
|
||||||
|
|
||||||
|
|
||||||
if isWin:
|
if isWin:
|
||||||
import win32com.client
|
import win32com.client
|
||||||
|
|
||||||
|
@ -401,14 +403,13 @@ if isWin:
|
||||||
"19466": "es_NI",
|
"19466": "es_NI",
|
||||||
"20490": "es_PR",
|
"20490": "es_PR",
|
||||||
"21514": "es_US",
|
"21514": "es_US",
|
||||||
"31748": "zh_CHT"
|
"31748": "zh_CHT",
|
||||||
}
|
}
|
||||||
|
|
||||||
def lcid_hex_str_to_lang_code(hex: str) -> str:
|
def lcid_hex_str_to_lang_code(hex: str) -> str:
|
||||||
dec_str = str(int(hex, 16))
|
dec_str = str(int(hex, 16))
|
||||||
return LCIDS.get(dec_str, "unknown")
|
return LCIDS.get(dec_str, "unknown")
|
||||||
|
|
||||||
|
|
||||||
class WindowsTTSPlayer(TTSProcessPlayer):
|
class WindowsTTSPlayer(TTSProcessPlayer):
|
||||||
speaker = win32com.client.Dispatch("SAPI.SpVoice")
|
speaker = win32com.client.Dispatch("SAPI.SpVoice")
|
||||||
|
|
||||||
|
@ -418,9 +419,9 @@ if isWin:
|
||||||
def _voice_to_object(self, voice: Any):
|
def _voice_to_object(self, voice: Any):
|
||||||
lang = voice.GetAttribute("language")
|
lang = voice.GetAttribute("language")
|
||||||
lang = lcid_hex_str_to_lang_code(lang)
|
lang = lcid_hex_str_to_lang_code(lang)
|
||||||
return WindowsVoice(name=voice.GetAttribute("name"),
|
return WindowsVoice(
|
||||||
lang=lang,
|
name=voice.GetAttribute("name"), lang=lang, handle=voice
|
||||||
handle=voice)
|
)
|
||||||
|
|
||||||
def _play(self, tag: AVTag) -> None:
|
def _play(self, tag: AVTag) -> None:
|
||||||
match = self.voice_for_tag(tag)
|
match = self.voice_for_tag(tag)
|
||||||
|
@ -440,4 +441,3 @@ if isWin:
|
||||||
return
|
return
|
||||||
finally:
|
finally:
|
||||||
self._terminate_flag = False
|
self._terminate_flag = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue