# Playing a .wav file from the database on FPMI clients

**URL:** <https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224>\
**Category:** Archived Topics\
**Created:** [February 28, 2007, 3:10am UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224 "2007-02-28T03:10:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [February 28, 2007, 3:10am UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224/1 "2007-02-28T03:10:21Z")

</div>

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.

```auto
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])
```

---

<div class="post-metadata">

**Author:** ![david\_mccutchen](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@david\_mccutchen](https://forum.inductiveautomation.com/u/david_mccutchen)\
**Post date:** [November 30, 2009, 2:28pm UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224/2 "2009-11-30T14:28:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [November 30, 2009, 2:53pm UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224/3 "2009-11-30T14:53:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david\_mccutchen](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@david\_mccutchen](https://forum.inductiveautomation.com/u/david_mccutchen)\
**Post date:** [November 30, 2009, 3:36pm UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224/4 "2009-11-30T15:36:31Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![MickeyBob](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@MickeyBob](https://forum.inductiveautomation.com/u/MickeyBob)\
**Post date:** [November 30, 2009, 4:49pm UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224/5 "2009-11-30T16:49:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david\_mccutchen](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@david\_mccutchen](https://forum.inductiveautomation.com/u/david_mccutchen)\
**Post date:** [November 30, 2009, 6:17pm UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224/6 "2009-11-30T18:17:31Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [November 30, 2009, 9:21pm UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224/7 "2009-11-30T21:21:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david\_mccutchen](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@david\_mccutchen](https://forum.inductiveautomation.com/u/david_mccutchen)\
**Post date:** [December 1, 2009, 11:03pm UTC](https://forum.inductiveautomation.com/t/playing-a-wav-file-from-the-database-on-fpmi-clients/224/8 "2009-12-01T23:03:51Z")

</div>

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
