Maybe something like this:
from os.path import dirname
import json
from aqt import gui_hooks
from aqt.sound import av_player
from aqt.reviewer import Reviewer
from anki.sound import SoundOrVideoTag
from aqt.theme import theme_manager
from aqt import mw
def get_sounds(config, card):
sounds = []
tags = [tag.lower() for tag in card.note().tags]
for tag in config.keys():
if tag in tags:
sounds.append(SoundOrVideoTag(filename=config[tag]))
return sounds
def my_showQuestion(self) -> None:
self._reps += 1
self.state = "question"
self.typedAnswer: str = None
c = self.card
# grab the question and play audio
q = c.q()
# play audio?
added_sounds = get_sounds(mw.addonManager.getConfig(__name__), c)
question_av_tags = c.question_av_tags()
if c.autoplay():
av_player.play_tags(added_sounds + question_av_tags)
else:
av_player.clear_queue_and_maybe_interrupt()
av_player.play_tags(added_sounds)
# render & update bottom
q = self._mungeQA(q)
q = gui_hooks.card_will_show(q, c, "reviewQuestion")
bodyclass = theme_manager.body_classes_for_card_ord(c.ord)
self.web.eval("_showQuestion(%s,'%s');" % (json.dumps(q), bodyclass))
self._drawFlag()
self._drawMark()
self._showAnswerButton()
# if we have a type answer field, focus main web
if self.typeCorrect:
self.mw.web.setFocus()
# user hook
gui_hooks.reviewer_did_show_question(c)
Reviewer._showQuestion = my_showQuestion
With a config file like this:
{
"tag1": "sound1.ogg",
"tag2": "sound2.ogg"
}