#Is their a way to make only one audio source auto play on an anki card?
1 messages · Page 1 of 1 (latest)
Could you clarify a bit exactly what you mean? Do you want a card to only play sentence audio if sentence audio is available?
No I'm sorry. On the back my cards I have two audio sources, the sentence and a the word said alone. I was wondering if there is a way to make it only play the sentence audio automatically when I flip the card
Ah okay I think I understand. I don't think there's any way to make Anki only autoplay selected audio since the setting allows you to autoplay or not, so I don't think it's possible to achieve this. I'm not entirely sure why you'd want to not have the word audio play anyways since it's good to hear the word in isolation and in context since the way it sounds can differ
Ya, I didn't think it was possible from what I could find. Thanks for trying to help though. I agree having both is better, that's why I keep them both, I just don't like that it plays immediately. Have a nice evening sir
It sounds a bit weird to hear the sentence audio first and then word audio since I'm so used to it being the other way around. Usually there's a bit of quietness at the end of most word audio which makes it less jarring to go from word audio to sentence audio, so maybe you could try changing their order
Perhaps, so. I shall give it a try
Hi Pag, this is possible via the card template and JavaScript. If you provide me with your card Lay-out I can patch it up later the day / tomorrow for you.
This is my current back template. Is this what you would need? Or would you just prefer an image?
<div class="back-box" style= 'background-color: #FDFFFF;'>
<div class='wrapper'>
<div class="audio">
<div>{{SentenceAudio}}</div>
<div>{{Audio}}</div>
</div>
<div class='photo'>
{{Picture}}
</div>
</div>
<div style= 'color: #555b6e; font-size: 20px; padding-top: 25px;'> {{Reading}}<div>
<div class=reading style= 'color: #555b6e; margin-top: -20px;' >{{edit:furigana:front}}</div>
<div style= 'color: #555b6e; margin-top: -20px; font-size: 30px;'>{{Sentence}}</div>
<div class="glossary" style='font-family: Arial; font-size: 25px; color: #555b6e; margin-top: 10px;'>{{edit:Glossary}}</div>
<div style= 'padding-bottom: 20px; font-size: 30px; color: #555b6e'>{{Graph}}</div>
</div>
I may have forgotten it yesterday 😄
Basically what i did:
- on the line with "SentenceAudio" i added the
class="s_audio - on the bottom i added the section with the script
If you change the s_audio to w_audio inside the script-part (without anything else, dot etc) the word audio should play instead 🙂
<div class="back-box" style= 'background-color: #FDFFFF;'>
<div class='wrapper'>
<div class="audio">
<div class="s_audio">{{SentenceAudio}}</div>
<div class="w_audio">{{Audio}}</div>
</div>
<div class='photo'>
{{Picture}}
</div>
</div>
<div style= 'color: #555b6e; font-size: 20px; padding-top: 25px;'> {{Reading}}<div>
<div class=reading style= 'color: #555b6e; margin-top: -20px;' >{{edit:furigana:front}}</div>
<div style= 'color: #555b6e; margin-top: -20px; font-size: 30px;'>{{Sentence}}</div>
<div class="glossary" style='font-family: Arial; font-size: 25px; color: #555b6e; margin-top: 10px;'>{{edit:Glossary}}</div>
<div style= 'padding-bottom: 20px; font-size: 30px; color: #555b6e'>{{Graph}}</div>
</div>
<script>
function playAudio() {
const audio = document.querySelector(
".s_audio .soundLink, #sentenceAudio .replaybutton"
);
if (audio) {
audio.click();
}
}
playAudio();
</script>
Quick question: did you ever test this out on Ankidroid? I think it works on the latest stable release, but it completely freezes the template on the latest alpha
I never tried any alpha or whatsoever - however, it is basically the same code as the jp1k has embedded as well. It worked always for me ^^
Also, the js is that basic even old Internet Explorer could pull it off O.o
I think I found it out. It's some extremely strange combination of AnkiDroid thinking my card template is using mathjax (because one of my regex strings has \[ and \]), and something to do with mathjax not finishing properly if the audio was played for some reason
If mathjax doesn't load properly, the class mathjax-needs-to-render is never removed, which hides the entire card
I have no idea why mathjax is even related to playing audio, but 🤷
Yeah, forcing the mathjax-needs-to-render css class to have visibility: visible !important magically fixes it. What a strange bug
The other solution I was thinking of was splitting the regex string with something like "\\" + "]", but webpack optimizes it back into one full string 🤔