DillonWall / generate-batch-audio-anki-addon

An addon that downloads and attaches audio to flashcards in bulk from URLs. Made for Anki, an SRS flashcard application
https://ankiweb.net/shared/info/1156270186
Apache License 2.0
14 stars 6 forks source link

Request to Download Multiple Audio Files for a Single Word #5

Open Pedrubik2000 opened 1 year ago

Pedrubik2000 commented 1 year ago

Hi there! I was wondering if it's possible to download multiple audio files for the same word, rather than just one?

I'm trying to use a randomizer to play a different audio file each time I review a flashcard, but I'm currently limited to just one audio file per word. It would be really helpful if I could access more audio files to make my review experience more diverse and engaging.

If anyone knows how I can accomplish this, I would really appreciate your help! Thank you so much in advance.

DillonWall commented 1 year ago

Hello and thanks for using my addon!

Currently, the way the addon works is that it stops searching the remaining sources after it successfully finds a source with available audio. In order to return multiple sources, it likely wouldn't be too hard of a change to implement, but the main question is how to format the anki audio field(s?) if they contain more than one audio file? If you already have a method in mind, could you show me what you are trying to use in order to randomize between audio sources?

Pedrubik2000 commented 1 year ago

Right now, I'm using a comma as a separator, but it would be great if we could choose our own. That way, we can pick something that works best for us. Example:

[sound:ForvoLocal放る1.mp3],[sound:ForvoLocal放る2.mp3],[sound:ForvoLocal放る3.mp3],[sound:ForvoLocal放る4.mp3]

And Im my card I put {{random:WordAudio}} Im using this addon:

import random

from anki.hooks import addHook

def fmod_random(txt, extra, context, tag, fullname):
    return random.choice([x.strip() for x in txt.split(',')])

addHook('fmod_random', fmod_random)
DillonWall commented 1 year ago

Thanks for the context, I think it wouldn't be too hard to implement if it's just a matter of appending with a given separator. Right now I am heading home from a vacation, but I will try to get around to implementing this when I return home and next have free time.

Pedrubik2000 commented 1 year ago

Thank you for taking the time to work on it, and have a safe trip home!