Playing a .wav file from the database on FPMI clients

This will allow you to play sound files on any FactoryPMI client. The approach only downloads the audio when it needs to be played and does not rely on any shared network or local media to store the files - it uses the SQL database.

This script reads the audio file (stored in a BLOB format) from the database, writes it to the local cache, then uses the windows sound recorder to play it. it’s a modification of the fpmi.system.execute() example from the help file. It seems to work surprisingly smoothly.

query = "SELECT wav FROM soundTable WHERE id=1"
sound = fpmi.db.runScalarQuery(query)
filename = "temp.wav"
fpmi.file.writeFile(filename, sound)
if fpmi.file.fileExists(filename):
    fpmi.system.execute(["sndrec32", "/play", "/close", "/embedding", filename])

There is no sndrec32 in Windows 7, What should I use instead?

From what I’ve read, sndrec32 has been renamed to “SoundRecorder.exe” and exists in the %systemroot%/Windows/System32 folder.

When I substitute SoundRecorder for sndrec32 I get the same error SoundRecorder not found
fpmi.system.execute([“SoundRecorder”, “/play”, “/close”, “/embedding”, filename])

Traceback (innermost last): File "<TimerScript:alarm_ack_popup (10000) [Delay, Shared]>", line 12, in ? java.io.IOException: Cannot run program "SoundRecorder": CreateProcess error=2, The system cannot find the file specified

David,

SoundRecorder.exe under Windows 7 doesn’t have the ability to play a sound file. It can only record.

You can use Windows Media Player (i.e., “c:\Program Files\Windows Media Player\wmplayer.exe”) but it will stay open on the desktop as the “/play” and “/close” command line parameters are no longer valid.

filename = "C:\Users\lab_2\Desktop\Lab Alarm" if fpmi.file.fileExists(filename): fpmi.system.execute(["C:\Program Files\Windows Media Player\wmplayer.exe", "/play", filename])
Ok this works; however you have to manualy close media player everytime it plays the file or you get file not found error. There has to be a better way. I would prefer there not be windows opening to play file.

This is an ancient thread. You can use the sound player component in modern version of FactoryPMI.

Well that solves all the problems. A timer and a sound component works great. Just as a note though, there is currently no command line function to play sounds in Windows 7 without a gui