Per field audio autoplay (again…)

Is your feature request related to a problem? Please describe.
I have a couple of cards with multiple audio recordings - mostly one with the vocabulary and then a bunch of example sentences. While I prefer to have the sole vocabulary to be read-out, having auto-play of all sentences is just annoying…

Describe the solution you’d like
It would be great to have field configuration option in NoteType which would controll if the audios of particular field should be auto-played or not.

Describe alternatives you’ve considered
There is a bunch of topics with various hacks/workarounds (mostly using <script/> to do that but it just feel so fragile. Having an option right there would be way better.

An alternative implementation has additional attributes for [sound:] and [anki:tts][/anki:tts], which could be used to specify whether the sound should be played automatically or not.

Actually in both cases I’m using [sound:…] with my own generated audio files so I’m not sure that would help.

Having actually control on per-field basis seems reasonable (and still - you may want to autoplay some sound and some tts tags still…

Uhm… other threads:

I would REALLY appreciate having this as an option. Currently, having sound in example sentences makes using Anki quite annoying as the sound from the example autoplays and quite often trigger recollection from the context…

I think we want very similar things here, some way to selectively turn off autoplay.

Yeah, kinda similar. Though I think your case is somewhat more complex. Would having per-field configuration option work in your case?

A better solution is per file configuration.

But how would you decide on that? Without too much hassle?

In my case - I add audio using AwesomeTTS plugin, which inserts [sound:…] tag. How would you like to handle that? You mentioned using special attributed on divs for example, but IMHO that while it may give you a lot of flexibility it’s not very user-friendly…

If you want user-friendlyness you can have something like [no-play:sound: ] but divs of course are more flexible as you can make template changes with it. And also disable auto-play on whole fields.

I just thought of a (potentially) better option!

Two custom field prefixes like {{mute:Audio}} and {{autoplay:Audio}}. The former is self explanatory. The latter would be require that:

  1. It auto plays even if “Don’t play audio automatically” is enabled.
  2. It would autoplay that particular field and wait until it’s finished before auto playing other fields.
  3. It does not autoplay the field when placed inside a hidden/display: none div.

This does not work with tts and individual audio files.
Ideally, have a special class instead.

<span class="muteAudio">{{Audio}}</span>
<span class="autoplayAudio">{{Audio}}</span>

<span class="muteAudio">[sound: ]</span>
<span class="autoplayAudio">[sound: ]</span>

<span class="muteAudio">{{tts en_US:Front}}</span>
<span class="autoplayAudio">{{tts en_US:Front}}</span>

<span class="muteAudio">[anki:tts lang=en_US] This text should be read. Here is {{Field1}} and {{Field2}}[/anki:tts]</span>
<span class="autoplayAudio">[anki:tts lang=en_US] This text should be read. Here is {{Field1}} and {{Field2}}[/anki:tts]</span>

Or maybe have a special class + a no-play flag for sound tags.

This still requires dabbing in sources of (cards/templates) and if you want to globally disable autoplay for audio in a field then you would have to do search&replace – I’d argue somewhat inconvenient.

There is another issue at play here - how to handle two-level auto-play configuration (eg global and per-field)?

What do do if you have per-field auto-play on but disable it globally - should the fields that have it on play automatically still?

In some UI widgets you have tri-state checkbox (off/on/between, which may mean impartial selection). Qt does seem to support that (QCheckBox - Qt for Python) so maybe using it with the intention:

  1. settings on/off (globally)
  2. per-field tri-state (on - always autoplays; partially checked - follows global; off - always off)

If you have the right deck options, auto-play is always on by default so you shouldn’t even need an extra class for that.

That’s what point 1 in my suggestion is about.

Isn’t that more complicated for no reason? Plus, it’d be completely useless for me because I share my decks on AnkiWeb. I can imagine the downvotes from “audio plays automatically and I can’t change it in deck options. fix it”.

“This deck uses a custom template to do such and such. If you don’t like that, go to the template and replace {{autoplay:Audio}} with {{Audio}}

I’ve already seen decks/templates that do a similar thing.

Though, to be honest, I doubt my suggestion would solve my issue with randomly playing a file. We need someone who knows how the code works to come up with an idea.

people are dumb in my country, won’t work lol. but to be serious, it actually won’t work. the templates are fairly complex and took me a lot of time to understand even with my somewhat decent understanding of HTML etc.

To do this, you will need to change the card template.