LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

play sound file

 
HI
 
I need to play a sound file when I press a button and turn it off when i press the button to off......sounds simple enough but the only thing i found that generates the task id for functions like (sound output stop.vi) is play sound file.vi. 
 
However that would mean i would have to play the sound first before i begin my program, which i do not want to do.  Basically i guess i need to get a task id for a sound file somehow  without playing ths sound file first so i can then pass it on to the sound output stop.vi or the sound output start.vi
 
any suggestions or other methods
 
thanks
0 Kudos
Message 1 of 31
(19,977 Views)
Open the Example Finder (Help -> Find Examples), and search for "sound". Take a look at the example "Sound File to Sound Output". The stuff in the while loop is the part that's playing the sound which you can control from a Boolean.
0 Kudos
Message 2 of 31
(19,972 Views)

Thanks but that example did not work with my wave file for some reason ....(Hex 0x12C3) The sound driver or card does not support the desired operation.....i believe it doesn't work with uncompressed wave files...any solution?

 

 

0 Kudos
Message 3 of 31
(19,950 Views)
The sound file functions that come with LabVIEW don't work with MP3 files - I'm assuming you're referring to MP3 files when you say "compressed" sound files. You will need to use either ActiveX to call a media player (if on Windows), or an equivalent system call for other operating systems. You can do a search in this forum for posts related to playing MP3 file with LabVIEW - this has come up before. There was an old library that was done in LabVIEW. I've never used it, and I have no idea what became of it. The thread that talks about it is here.
0 Kudos
Message 4 of 31
(19,944 Views)
actually no, it is a wave file and it works with the play sound file.vi but not with the sound file read.vi or sound output configure. vi, that is why the example vi provided by labview didn't work for me.  And the reason I said compressed was that in the help menu for sound file read it says that the VI ".. retrieves only uncompressed wave files" so I thought MAYBE mine was compressed or something.
0 Kudos
Message 5 of 31
(19,941 Views)
Well, I've used that example before, and I know it works. With WAV files. I just tried it again. Perhaps you can upload your WAV file? Try to zip it if it's large.
0 Kudos
Message 6 of 31
(19,938 Views)
here it is....the file works in the Sound Player. vi example but not in the sound file to sound output.vi
 
 
Message 7 of 31
(19,926 Views)
reza_sed,

I believe this is happening because you are indeed using a compressed .WAV file.  If you look at its properties it is in MPEG 3 format.  The format you will want to use is PCM.  I have converted the file for you and attached it as harley2.zip.  I tried both and the PCM version worked fo rme.  Try this out and let me know if it works for you.  I can give you an easy way to convert compressed wav files back to PCM if you'd like.
Regards,

Jared Boothe
Staff Hardware Engineer
National Instruments
0 Kudos
Message 8 of 31
(19,922 Views)
The problem seems to be with the information in the WAV file. The Sound File Info VI reads 0 for bits per sample, which is clearly wrong. It also has these values for its other outputs:
total number of samples/ch: 0
sample rate (S/s): 22050
number of channels: 1
bits per sample: 0
That's why the example VI is generating the error. The Play Sound File Vi calls a different function in the sound DLL, and only NI knows what that's actually doing since they wrote the DLL.


EDIT: OK, looks like it is a compressed sound file.


Message Edited by smercurio_fc on 05-30-2008 10:57 AM
0 Kudos
Message 9 of 31
(19,921 Views)
Yeah thanks, the file works now and if you can tell me how to convert compressed wav files back to PCM that would be great too
 
 
0 Kudos
Message 10 of 31
(19,902 Views)