Conditional Audio Playback

Thanks for your detailed description, it really helps!

The issue is that I need to read the back audio field for the script to work. But if I do something like this:

var audio_field = `
{{Back}};
`

then anki will substitute the {{Back}} field automatically with

<a class="replay-button soundLink" href=# onclick="pycmd('play:q:2'); return false;">
    <svg class="playImage" viewBox="0 0 64 64" version="1.1">
        <circle cx="32" cy="32" r="29" />
        <path d="M56.502,32.301l-37.502,20.101l0.329,-40.804l37.173,20.703Z" />
    </svg>
</a>;

And this triggers the autoplay. Notice that the pycmd('play:q:2'); part changes with every audio added. It starts with 0 and increments +1 for every audio that will be autoplayed.

Ideally you have some other field that doesn’t include audio, but still shows us if there are synonyms. That would solve this problem.

If it was possible to just get the text you see in your field (e.g. [sound:t.mp3]) then this task would be pretty trivial. But anki changes the [sound:t.mp3] behind the scenes for you, so that audio actually works. Also see this:

So I guess my follow up question is: Do you have a field that doesn’t include audio that we could read to know if there are synonyms? Or would it be okay to create one? It doesn’t need to be displayed on the card and could include a single letter (y for yes, n for no).

1 Like