Here’s my code if you want to compare.
Like @ODeer it works on Anki Desktop (and Mobile for me).
I put the function before but I think it works even if I put after the sounds.
<script>
{
function randomInt(max) {
return Math.floor(Math.random() * max);
}
const audios = [...document.querySelectorAll(".soundLink")];
setTimeout(function() {
audios[randomInt(audios.length)].click();
}, 10);
}
</script>
<div style='font-family: Hoefler Text; font-size: 70px;'>{{Pinyin}}</div>
{{Audio}}
{{tts zh_CN voices=Apple_Ting-Ting:Hanzi}}
{{tts zh_CN voices=Apple_Li-mu:Hanzi}}
{{tts zh_CN voices=Apple_Yu-shu:Hanzi}}
{{tts zh_TW voices=Apple_Mei-Jia:Hanzi}}
I also attach a screenshot of what it’s supposed to look like on the front of a “card 2” on my setup (pinyin + audio)