A more flexible TTS option

I use a lot of example sentences on my cards, and I use JavaScript to display a translation when I click on a word I don’t know. I’d like to have Anki pronounce the word at the same time—but after searching the forum, it appears that Anki processes audio tags before they can be modified, so I can’t simply replace the tag content. If there was just some way to modify a TTS tag, or even to add one after a card has been displayed, that would be incredible. I did find this JavaScript API for AnkiDroid TTS, which seems to be along the lines of what I’m thinking.

If anyone can think of a workaround (that doesn’t involve a paid API), please let me know. On Mac, all the TTS voices I’ll ever need are already built-in, but the problem is accessing them. I tried using a URL scheme to pronounce clicked-on words through the Shortcuts app, but this requires switching to the Shortcuts app every time, which is more intrusive than it is helpful.