# Conditional Audio Playback

**URL:** <https://forums.ankiweb.net/t/conditional-audio-playback/54841>\
**Category:** Card Design\
**Created:** [January 25, 2025, 1:14am UTC](https://forums.ankiweb.net/t/conditional-audio-playback/54841 "2025-01-25T01:14:43Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Anon\_0000](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@Anon\_0000](https://forums.ankiweb.net/u/Anon_0000)\
**Post date:** [January 27, 2025, 2:40am UTC](https://forums.ankiweb.net/t/conditional-audio-playback/54841/5 "2025-01-27T02:40:33Z")

</div>

If your _B\_Audio_ field always looks like described above (having a `[sound:*.*]` followed by `<br>` followed by `[sound:*.*]`) then you could probably use js to achieve your goal. Something in the lines of the following would work:

```html
<script>
	// use multiline string
	var audio_field = `
	{{B_Audio}};
	`
	// count how many <br> there are. Also see: https://stackoverflow.com/a/4009768
	var count = (audio_field.match(/<br>/g) || []).length;
	
	// if there is more than one count, then there must be a synonym
	if (count > 1) {
		console.log("play ding");
		
		var audio = new Audio('_ding.mp3')
		audio.play();
	}
</script>

```

---

_[View the full topic](https://forums.ankiweb.net/t/conditional-audio-playback/54841)._
