# Perspective - Need help with Audio Component Event onEnded Script

**URL:** <https://forum.inductiveautomation.com/t/perspective-need-help-with-audio-component-event-onended-script/79236>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [September 15, 2023, 5:47pm UTC](https://forum.inductiveautomation.com/t/perspective-need-help-with-audio-component-event-onended-script/79236 "2023-09-15T17:47:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Lozano1](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Miguel\_Lozano1](https://forum.inductiveautomation.com/u/Miguel_Lozano1)\
**Post date:** [September 15, 2023, 5:47pm UTC](https://forum.inductiveautomation.com/t/perspective-need-help-with-audio-component-event-onended-script/79236/1 "2023-09-15T17:47:15Z")

</div>

Hello,

I'll start off by saying that this Audio component in Perspective in 8.1.22 is working correctly and plays the audio just fine. It is a 1 second "Critical Alarm" sound that plays whenever a critical-level alarm is active and unacknowledged.

Currently, I am trying to introduce a 1-second delay between the looping of that alarm audio so that the sound is not as jarring. I know that time-based delays are typically frowned-upon in scripting, so I've tried scripting the "onEnded" Component Event on the Audio component to change the volume to 0 if the current volume is 100% and to 100% if the volume is 0 (basically playing a 1 second muted audio), but the audio volume never changes. It just loops at the same volume.

Any help with this current problem, or maybe a better way to approach this would be greatly appreciated.  
Thanks!

 ![audioscrnt](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/1/e17a65bb9e6c15815cd42c01cfd090f61907c593.png)

Other

- The audio component "props.play" binding uses an expression to detect critical alarms, works fine.
- The "props.loop" property is set to True, always.
- The "props.volume" property had an old binding tied to a "Mute" button, but that's been removed.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 15, 2023, 10:45pm UTC](https://forum.inductiveautomation.com/t/perspective-need-help-with-audio-component-event-onended-script/79236/2 "2023-09-15T22:45:32Z")

</div>

Are you sure the event is even happening? (It would seem logical to me that looping would prevent it from ever ending?)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 15, 2023, 11:23pm UTC](https://forum.inductiveautomation.com/t/perspective-need-help-with-audio-component-event-onended-script/79236/3 "2023-09-15T23:23:43Z")

</div>

I'd modify the audio file and add in some silence at the end.

- Download [Audacity](https://www.audacityteam.org/download/).
- Import the audio file.
- I think you can drag the end of the file to the right to extend it with silence.
- You also have the option to add a short fade-in / fade-out if you wish.

Now you can play on infinite loop without `sleep()`.
