@mmdj2 or @gullempalausalva
I have just had a chance to test the addon. Thanks so much!
I uploaded it here (https://ankiweb.net/shared/info/1649407720) so that you can see it. However, I don’t plan on keeping it posted, as I agree some type of config file would need to exist to make it more user friendly, and that is beyond my ability. ANH25’s solution might work for that, but I haven’t been able to test it yet.
Anyhow, is there any way for multiple add-on sounds to play consecutively. For example, if a card has both a “marked” and a “leech” tag, could it play two different sounds back to back? In the current config (as best as I can test it), it seems that it will only play a single sound, which ever tag happens to come first in the “if” order.
@abdo: I hate to ask such a dumb question that so clearly shows my lack of coding skills, but I assume that the text you wrote should go in a config file (based on your earlier comments). I’ve never created a config file before. I assume it isn’t so simple as pasting the text that you wrote into a .py file and call in “config.py”? Is there any place you can direct me that I can read about how to set up the config file? Thanks!
@abdo: Thanks again! Super helpful. I’d like to say this is my last question, but that will only be if everything works.
Anyhow, do the audio files just go in my regular media folder? I assume I should append them with an underscore, so they don’t get discovered as unused media during a Check Media, correct?
@abdo: It looks like it is working. I have posted it here (https://ankiweb.net/shared/info/400375023). I am going to keep testing it tomorrow, but have to get to bed now. Thanks for all the help. After more testing, if all looks good, you are welcome to take it and post it as one of your add-ons.
this won’t let any other add-on use _showQuestion function tho.
Monkey patching is useful in the testing stage, and while waiting for new hooks to be integrated into Anki. But please don’t rely on it long term, as monkey patching is very fragile, and will tend to break as Anki is updated in the future.
(i don’t really have that much of coding experience and have started coding just to add some functionalities/change some parts that i needed in anki. when i started, i used this method, while it was easier to work with and i could modify them better, it would break other add-ons frequently)
I don’t know much about writing hooks (I’m a beginner myself). But looking at gui_hooks.py and genhooks_gui.py, it does not seem to be hard. So maybe I’ll have a try at it
@mmdj2: You mentioned you don’t have much coding experience as did @abdo, but you are a million times further along than am, and I’m deeply grateful that you both are helping.
@mmdj2 I assume that the solution you posted doesn’t use monkey patching, correct? Also, with the code you posted, is there a way to get get multiple add-on sounds to play back-to-back (when a card has more than one tag that triggers a sound)?
hmm, it can play multiple audio files when i use Reviewer.nextCard = wrap(Reviewer.nextCard, play_sound, 'after') but not when i use Reviewer._showQuestion= wrap(Reviewer._showQuestion, play_sound, 'after')
i honestly don’t understand why i’ll try to find a way to play multiple audios with _showQuestion too. don’t know if i can tho. meanwhile you can use the code that @abdo posted if it works for you.
I do think it could be a helpful add-on for the community, and would like to eventually share it (or have one of you share it), but I’m going to pull both of them down, at least, temporarily.
@abdo’s approach can play multiple sounds consecutively, but uses monkey patching. But ANH25 is looking into submitting a new hook.
@mmdj2’s approach doesn’t use monkey patching, but isn’t playing consecutive sounds for some unknown reason. mmdj is trying to find a way around this.
For now, I have something that works , and if one of these other developments happen, we can post a full version of it then.
I’ve submitted a pull request to add two new hooks:
The add-on would look something like this with these hooks:
from aqt import gui_hooks
from anki.sound import SoundOrVideoTag
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 myhook(card, sounds):
my_sounds = get_sounds(mw.addonManager.getConfig(__name__), card)
for s in my_sounds:
sounds.insert(0, s)
gui_hooks.reviewer_will_play_question_sounds.append(myhook)
@abdo: Are you still active on Anki? You helped me earlier with an addon. It worked up until 2.1.44, but now needs a bit of help to work with 2.1.45+. Seems like there are some easy porting directions to get addons to work with 2.1.45+, but nevertheless it is over my head.
@abdo Lol. I just edited this post with this comment because I saw you had “devotee” status on here. Way to go! Stupid question for me to ask if you were still active.
@abdo Thanks for your help with this. I have edited this post, because I seem to have it working now. Thanks again so much for your help.
Because you have done so much work on this addon, I’m glad to pass along ownership of the addon to you if you prefer. But either way, I’m super grateful for the help.