mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
add a helper for caching generated files
This commit is contained in:
parent
b00a9010be
commit
37d2a4d43c
1 changed files with 10 additions and 1 deletions
|
@ -33,7 +33,7 @@ from dataclasses import dataclass
|
||||||
from typing import List, Optional, Any, cast
|
from typing import List, Optional, Any, cast
|
||||||
|
|
||||||
from anki.sound import AVTag, TTSTag
|
from anki.sound import AVTag, TTSTag
|
||||||
from anki.utils import tmpdir, isWin
|
from anki.utils import tmpdir, isWin, checksum
|
||||||
from aqt.sound import OnDoneCallback, PlayerInterrupted, SimpleProcessPlayer
|
from aqt.sound import OnDoneCallback, PlayerInterrupted, SimpleProcessPlayer
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,6 +82,15 @@ class TTSPlayer:
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def temp_file_for_tag_and_voice(self, tag: AVTag, voice: TTSVoice) -> str:
|
||||||
|
"""Return a hashed filename, to allow for caching generated files.
|
||||||
|
|
||||||
|
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)}")
|
||||||
|
|
||||||
|
|
||||||
class TTSProcessPlayer(SimpleProcessPlayer, TTSPlayer):
|
class TTSProcessPlayer(SimpleProcessPlayer, TTSPlayer):
|
||||||
# mypy gets confused if rank_for_tag is defined in TTSPlayer
|
# mypy gets confused if rank_for_tag is defined in TTSPlayer
|
||||||
|
|
Loading…
Reference in a new issue