Audible Warning in All Clients

Hi,

I'm trying to set an audible warning for my vision application. I'm using the system.util.playSoundClip function to play a .WAV file. My question is: where do I need to save my .WAV file to ensure it can be played on all clients?

Currently, I'm using this function in an On Change tag Client Event Script. My .WAV file is located on the gateway, but the script is not working. I wonder if the issue is related to the file location.

Yes, Vision runs directly in the client, and expects to find the file there. You should use a project startup script that looks for the files you need locally, and if not there, use system.util.sendRequest() to retrieve the file bytes from the gateway and then write them locally.

Thanks for your reply.

I found the code below in an Ignition manual. I figured out how to save the WAV file into the project database, so now I can query the file from the database and play the sound on every client. I tested it, and it worked for me!

# This code would pull a sound clip out of a BLOB field from a database,
# playing it asynchronously at half volume.
  
query = "SELECT wavBlob FROM sounds WHERE type='alert_high'"
soundData = system.db.runScalarQuery(query)
  
system.util.playSoundClip(soundData, 0.5, 0)
2 Likes

You probably should use a Named Query for that, with caching enabled, as all of your clients will make that same request every time that alarm fires.

2 Likes

You could also stash a Sound Player component somewhere, e.g. on an always present docked window. The Sound Player embeds the audio directly inside the project, so as long as your audio file isn't too large it's a useful alternative if you want something without any external dependencies.

1 Like