Playing Anki TTS only on Mobile Version of Card

I am trying to figure out how I can get it so that Anki TTS will play only when the card is being reviewed on mobile (so no TTS plays when being reviewed on desktop).

I have got the visibility of the audio player correct through having the class containing the TTS be not displayed on desktop:

.mobile .speech {

}
.mac .speech {
	display: none;
}

However the TTS audio continues to play even with the player not being visible. Any suggestions appreciated.

  1. What is the Anki TTS that you’re talking about?
  2. What files are you playing? Are those file like .mp3, or actual local text read by TTS?

TTS being used is the built in Anki text to speech feature (see here: Section 7.1 - Text to Speech for individual fields in the anki manual)

1 Like

[The link for convenience: Field Replacements - Anki Manual]

Oh, I see. Unfortunately i cannot test it myself because there are no tts voices that anki could use on linux (well, without addons, that is). Can you see what the tts is generating using the dev tools? If it’s a python command, then I don’t think you can selectively turn it off.

Otherwise it might be possible, depending on how the audio gets played.

Have you tried hiding the field replacement itself? The idea is wrap your {{Field}} in TTS tags and hide that in desktop. Then have another {{Field}} without TTS tags and hide this one on mobile.

Edit: If you’ve got auto-play on it probably wouldn’t work.

Idea #1 – This discussion of ways to conditionally include code on different platforms seems like it might have some ideas you could use.


Idea #2 – Is this for AnkiDroid or AnkiMobile? In AnkiDroid, have you tried using the legacy Android-specific <tts> tags? AnkiDroid User Manual


Idea #3 – You haven’t posted your TTS code. What happens if you use a TTS language/voice that only exists on that device, and no fallback voice? Field Replacements - Anki Manual

1 Like