Modify string before TTS reads the field? (ADVANCED)

I use text-to-speech to have my French vocabulary to be read out loud on-the-fly on MacOS and iOS (on-the-fly AwesomeTTS unfortunately only works on MacOS, but not on iOS). Some of my words include brackets and/or further information that I do not want to be read by tts.

Example: For “les chaussures (f)” I would like to exclude the “(f)” and only have read out “les chaussures”.

I am using this syntax for tts on my card:
{{tts fr_FR voices=Apple_Thomas:My_Field}}

Any idea how to do this (without using AwesomeTTS)?

I’m afraid there’s no built-in feature to do this.

Thanks Damien! I noticed the new TTS functionality in 2.1.52, which enables tts to read something like:

[anki:tts lang=en_US] Here is {{Field1}} and {{Field2}} [/anki:tts]

Unfortunately however, the content of those strings cannot be changed for example with Javascript to control exactly what TTS reads out loud and what it excludes/skips. Are there any plans to include this functionality anytime soon? It doesn’t seem to complex to be implemented and could be quite powerful for language learnes, who have additional information in their fields, which should not be read (which I assume happens quite often).

I can think of some workarounds:

  • If the information you want to put between parenthesis is not bound to a particular part of the field, but just to the field, you could add an-other field under that one just to contain this particular information;
  • otherwise, there are some add-ons that allow you to show information as a tooltip (for example, tippy tooltips). This could unclutter your card, and the tooltips are probably not read by the TTS since the information is contained a tag.

In general, if you want to do something with JS, instead of having a field of the form Something (comment), and trying to cut out the (commend) part before the TTS reads it, I would suggest the opposite: store the (comment) inside a tag attribute (just like Tippy Tooltips does), and extract it with JS once the TTS has read the sentence.

3 Likes

JS doesn’t help here, as the text gets read aloud before it can be modified by the webview. Arbitrary field replacements are something we have thought about before, and they may come at one point in the future.

1 Like

JS might still be of help. Assume I have something like <span content="Hello World!"/>, and a script that extracts the content of a tag to put it in its innerText. Since it’s executed after the TTS, and since the TTS does not read tag attributes (never tried, but it would make sense to me), you can still achieve what the OP wanted, just the other way around they though of.

1 Like

Thanks BlackBeans - yes, I assume that would work, but would require additional work to update my deck and increase the time for creating new cards. I am keeping my fingers crossed that a future Anki version would allow us to control exactly the string that TTS reads. Or perhaps TTS could simply be executed after JS is executed?

That’s basically what the first add-on I’ve linked to does: provide a nice interface to add a tag around some text and put an arbitrary string in one of its attributes. All you need to do is make (only once) a JS script that extracts that information and inserts it in the DOM somewhere.

You are right. For me, personally though, adding those extra tags still adds up, as I’d need to include several of them per field. Anyway, thanks a lot for your input guys!

One alternative approach would be to split the phrase and its gender into two separate fields. You could combine them at display time if you wished to see them like before, but you could then have the phrase read without the gender being included.

https://faqs.ankiweb.net/splitting-a-field-into-multiple-fields.html