Play sound when cloze revealed

How do I put sound in a cloze?

I tried

{{c1::foo}}
{{c1::[sound:example.mp3]}}

but the sound played while the text was still occluded.


I found another thread that seemed related but I didn’t understand it. Cloze: play sound only when particular cloze answer is revealed - #2 by kelciour

Add the sound to a separate field and update your front/back template to add something like this:

{{#c1}}
    {{FieldName}}
{{/c1}}

Where FieldName is the name of the field containing the sound.

I can’t do this on a built-in Cloze card?

You can. Add a new field from the Fields button in the editor.

I have one note with a bunch of clozes, each containing text and a sound.

Add fields to the built-in Cloze note type, just to support this one note? That doesn’t seem like the right solution. Likewise adding a new note type just to support this one note doesn’t seem like the right solution.

What seems most natural to me is that sounds inside a cloze should not play while occluded. No?

A better solution then is to create a new cloze note type cloned from the standard one and customize it for this one note.

I agree, but this is not supported at the moment. The way Anki parses sound tags will need to be reworked to understand cloze syntax.

2 Likes

Cloze is intended to visually hide text that is in sequence with other text – to fill in the _____ in a sentence. But an audio file isn’t in sequence with the text in your field, so it doesn’t make sense to have it be occluded using cloze.

What creates this sort of limitation for how you can present your information on cards is having the audio and text in the same field to begin with. Your notes will be more flexible if you don’t do that, and keep different media – text, audio, video, images – in separate fields.

2 Likes

{{c1::foo [sound:foo.mp3]}} here it is in sequence with the text in my field, but it still plays while occluded.

Even if it’s hidden, the sound will still work. I used the following in the design:

<p style="display: none;">[sound:_05s.mp3]</p>

As far as I know, the playback algorithm simply loops through the map, collects the entire list of sounds, and plays them; it doesn’t look at the code or any complex conditions. For this type of map, if anything changes, the help should be updated to explain how this can be done.

1 Like

I understand you put them in sequence – but there’s nothing about “foo [sound:foo.mp3]” that is meaningful, or needs to be in sequence to be understood. If you just want the word on the front and the audio on the back, that’s a basic card with the word and the audio in 2 separate fields.