Play a wav file once
how do I play a wav file just once using the play sound
file.vi. i keep getting it to repeat over and over
thanks
First may I recommend some reading here. This is not meant to be cocky just to help you.
Getting Started with NI LabVIEW Student Training
LabVIEW101
Second I have included sort of template. Notice the wire that ends in the while loop. This will ensure that the wav is played before the loop starts.
Good luck with your Labview labwork
Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Attachments:
play wav file[2].vi 9 KB
Similar Messages
-
Playing a wav file (byte array) using JMF
Hi,
I want to play a wav file in form of a byte array using JMF. I have 2 classes, MyDataSource and MyPullBufferStream. MyDataSource class is inherited from PullStreamDataSource, and MyPullBufferStream is derived from PullBufferStream. When I run the following piece of code, I got an error saying "EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c9108b2, pid=3800, tid=1111". Any idea what might be the problem? Thanks.
File file = new File(filename);
byte[] data = FileUtils.readFileToByteArray(file);
MyDataSource ds = new MyDataSource(data);
ds.connect();
try
player = Manager.createPlayer(ds);
catch (NoPlayerException e)
e.printStackTrace();
if (player != null)
this.filename = filename;
JMFrame jmframe = new JMFrame(player, filename);
desktop.add(jmframe);
import java.io.IOException;
import javax.media.Time;
import javax.media.protocol.PullBufferDataSource;
import javax.media.protocol.PullBufferStream;
public class MyDataSource extends PullBufferDataSource
protected Object[] controls = new Object[0];
protected boolean started = false;
protected String contentType = "raw";
protected boolean connected = false;
protected Time duration = DURATION_UNKNOWN;
protected PullBufferStream[] streams = null;
protected PullBufferStream stream = null;
protected final byte[] data;
public MyDataSource(final byte[] data)
this.data = data;
public String getContentType()
if (!connected)
System.err.println("Error: DataSource not connected");
return null;
return contentType;
public void connect() throws IOException
if (connected)
return;
stream = new MyPullBufferStream(data);
streams = new MyPullBufferStream[1];
streams[0] = this.stream;
connected = true;
public void disconnect()
try
if (started)
stop();
catch (IOException e)
connected = false;
public void start() throws IOException
// we need to throw error if connect() has not been called
if (!connected)
throw new java.lang.Error(
"DataSource must be connected before it can be started");
if (started)
return;
started = true;
public void stop() throws IOException
if (!connected || !started)
return;
started = false;
public Object[] getControls()
return controls;
public Object getControl(String controlType)
try
Class cls = Class.forName(controlType);
Object cs[] = getControls();
for (int i = 0; i < cs.length; i++)
if (cls.isInstance(cs))
return cs[i];
return null;
catch (Exception e)
// no such controlType or such control
return null;
public Time getDuration()
return duration;
public PullBufferStream[] getStreams()
if (streams == null)
streams = new MyPullBufferStream[1];
stream = streams[0] = new MyPullBufferStream(data);
return streams;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.media.Buffer;
import javax.media.Control;
import javax.media.Format;
import javax.media.format.AudioFormat;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.PullBufferStream;
public class MyPullBufferStream implements PullBufferStream
private static final int BLOCK_SIZE = 500;
protected final ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW);
protected AudioFormat audioFormat = new AudioFormat(AudioFormat.GSM_MS, 8000.0, 8, 1,
Format.NOT_SPECIFIED, AudioFormat.SIGNED, 8, Format.NOT_SPECIFIED,
Format.byteArray);
private int seqNo = 0;
private final byte[] data;
private final ByteArrayInputStream bais;
protected Control[] controls = new Control[0];
public MyPullBufferStream(final byte[] data)
this.data = data;
bais = new ByteArrayInputStream(data);
public Format getFormat()
return audioFormat;
public void read(Buffer buffer) throws IOException
synchronized (this)
Object outdata = buffer.getData();
if (outdata == null || !(outdata.getClass() == Format.byteArray)
|| ((byte[]) outdata).length < BLOCK_SIZE)
outdata = new byte[BLOCK_SIZE];
buffer.setData(outdata);
byte[] data = (byte[])buffer.getData();
int bytes = bais.read(data);
buffer.setData(data);
buffer.setFormat(audioFormat);
buffer.setTimeStamp(System.currentTimeMillis());
buffer.setSequenceNumber(seqNo);
buffer.setLength(BLOCK_SIZE);
buffer.setFlags(0);
buffer.setHeader(null);
seqNo++;
public boolean willReadBlock()
return bais.available() > 0;
public boolean endOfStream()
return willReadBlock();
public ContentDescriptor getContentDescriptor()
return cd;
public long getContentLength()
return (long)data.length;
public Object getControl(String controlType)
try
Class cls = Class.forName(controlType);
Object cs[] = getControls();
for (int i = 0; i < cs.length; i++)
if (cls.isInstance(cs[i]))
return cs[i];
return null;
catch (Exception e)
// no such controlType or such control
return null;
public Object[] getControls()
return controls;Here's some additional information. After making the following changes to MyPullBufferStream class, I can play a wav file with gsm-ms encoding with one issue: the wav file is played many times faster.
protected AudioFormat audioFormat = new AudioFormat(AudioFormat.GSM, 8000.0, 8, 1,
Format.NOT_SPECIFIED, AudioFormat.SIGNED, 8, Format.NOT_SPECIFIED,
Format.byteArray);
// put the entire byte array into the buffer in one shot instead of
// giving a portion of it multiple times
public void read(Buffer buffer) throws IOException
synchronized (this)
Object outdata = buffer.getData();
if (outdata == null || !(outdata.getClass() == Format.byteArray)
|| ((byte[]) outdata).length < BLOCK_SIZE)
outdata = new byte[BLOCK_SIZE];
buffer.setData(outdata);
buffer.setLength(this.data.length);
buffer.setOffset(0);
buffer.setFormat(audioFormat);
buffer.setData(this.data);
seqNo++;
} -
Playing a .wav file from email attachment
I am trying to play a .wav file that is attached to an email, and i get "The document conversion failed". Am I missing something? What do I need to do to be able to play .wav files that are sent to me via email?
I have the same request.
We have a new Panasonic phone system that sends out .wav voicemail files.
Our company's Curve's play the wav fine.
Our company's BOLDs ... DO NOT. -
How to play a wave file through the DAQ board?
Hi there,
we want to play a wave file that is saved on the harddrive via the DAQ board. Means we want to connect a amp to the analog output of the DAQ to amplify the sound and play it through a speaker.
We couldn't find any VI that does that. Can anybody tell us how to play a wave file, or perhaps even send us a VI that can do that?
Thanks a lot for your help
Martin - Physical Optics CorporationHi Martin,
The only example that I could find on how to do this was using our
older Traditional DAQ drivers version 6.9.3. If you're using Traditional
DAQ drivers, the vi can be found here.
The example reads a 8-bit mono .wav file (an example .wav file is included in the .zip file) and writes it to the analog out of your DAQ card. I've updated the
example to work with our newer DAQmx drivers and attached it here.
I hope this helps,
Paul C.
Message Edited by Paul C. on 08-14-2007 05:47 PM
Attachments:
daqmx_wav_file_to_ao_output.zip 27 KB -
Why cant I play embeded wave files in firefox but I can in explorer?
I just embedded a wave file (Godsmack Voodoo) for my website & saved it but when I goto run teh intro no sound, But explorer plays it no problems? What is wrong with Firefox 9.01 & playing the embedded sounds?
Can you post a link to a public page?
Which code are you using to play that WAV file? -
Playing a WAVE file after making a phone call.
Hi everyone..
I'm trying to play a wav file after making a phone call. I was able to make the call. But I get an exception when i try to paly a wav file..
Can any one tell me where I've gone wrong..
This is the code which plays the audio file..(I downloaded it by the way.. and it's working fine when used as a seperate program)
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
public class PlayWave extends Thread {
private String filename;
private Position curPosition;
//30000000(7324.21 kb)
private final int EXTERNAL_BUFFER_SIZE = 524288; // 128Kb
enum Position {
LEFT, RIGHT, NORMAL
public PlayWave(String wavfile) {
filename = wavfile;
curPosition = Position.NORMAL;
public PlayWave(String wavfile, Position p) {
filename = wavfile;
curPosition = p;
public void run() {
File soundFile = new File(filename);
if (!soundFile.exists()) {
System.err.println("Wave file not found: " + filename);
return;
AudioInputStream audioInputStream = null;
try {
audioInputStream = AudioSystem.getAudioInputStream(soundFile);
} catch (UnsupportedAudioFileException e1) {
e1.printStackTrace();
return;
} catch (IOException e1) {
e1.printStackTrace();
return;
AudioFormat format = audioInputStream.getFormat();
SourceDataLine auline = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
try {
auline = (SourceDataLine) AudioSystem.getLine(info);
auline.open(format);
} catch (LineUnavailableException e) {
e.printStackTrace();
return;
} catch (Exception e) {
e.printStackTrace();
return;
if (auline.isControlSupported(FloatControl.Type.PAN)) {
FloatControl pan = (FloatControl) auline.getControl(FloatControl.Type.PAN);
if (curPosition == Position.RIGHT)
pan.setValue(1.0f);
else if (curPosition == Position.LEFT)
pan.setValue(-1.0f);
auline.start();
int nBytesRead = 0;
byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
try {
while (nBytesRead != -1) {
nBytesRead = audioInputStream.read(abData, 0, abData.length);
if (nBytesRead >= 0)
auline.write(abData, 0, nBytesRead);
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
auline.drain();
auline.close();
}I inserted
new PlayWave("greeting.wav").start();In to a method an called this method in the program where i send commands to the modem.
These are my modem commands
send("ATZ");
expect("OK");
//Enable voice mode
send("AT+FCLASS=8");
expect("OK");
//Dial the number
send("ATDT"+number);
expect("OK");
//Choose encoding method //This is the default
send("AT+VSM=140,8000,0,0");
expect("OK");
// start sending audio data
send("AT+VTX");
expect("OK");
PlayAudio();
send("ATH");The size of my audio file is 100 kb.I'm using a 56 K intel externel voice modem connected to a serial port.I wonder if it's because the buffer is too big. If anyone tried this and succeded please correct me.
Thankyou in advance
goodnewsHi goodnews!
Did I understand well? Can You record the speech? This is what I want!
Can you help me and send me sample code?
This would be a big help for me!
Thank You!
rflair -
Subsequent play of WAV files from HTTP
Hi,
I have to subsequently play many WAV files from HTTP in a nokia series 60 emulator.
Everything is ok for the first two files, but at the third I catch an exception:
"java.io.IOException: exceeded the configured maximum number of connections"
I tried two ways to load the files from HTTP:
Manager.CreatePlayer(InputStream...)
Manager.CreatePlayer("http:\\...")
Below there is the code of the two methods I use. Please note that I try in every way to close the connection before open a new one!!!
public void Method_1(String src, String type){
int iLen=0;
is = null;
httpCon = null;
byte[] bBuf;
try {
if (p != null) {
if (p.getState() == Player.STARTED) {
p.stop();
p.removePlayerListener(this);
p.deallocate();
p.close();
p=null;
if (is!=null){
is.close();
is=null;
if (httpCon!=null){
httpCon.close();
httpCon=null;
httpCon = (HttpConnection) Connector.open(src);
if (httpCon.getResponseCode() != HttpConnection.HTTP_OK) {
System.out.println("Bad response code");
return;
System.out.println("Connection OK! (audio)");
iLen = (int) httpCon.getLength();
System.out.println("audio file length : " + iLen);
is = httpCon.openInputStream();
p = Manager.createPlayer(is, type);
p.addPlayerListener(this);
p.setLoopCount(1);
p.prefetch();
p.start();
vc = (VolumeControl)p.getControl("VolumeControl");
catch (MediaException ex) {
ex.printStackTrace();
catch (IOException ex) {
ex.printStackTrace();
public void Method_2(String src){
try {
if (p!=null){
if (p.getState() == Player.STARTED)
p.stop();
p.deallocate();
p.close();
p=null;
p = Manager.createPlayer(src);
p.addPlayerListener(this);
p.setLoopCount(1);
p.start();
vc = (VolumeControl)p.getControl("VolumeControl");
catch (java.io.IOException e) {
e.printStackTrace();
catch (MediaException e) {
e.printStackTrace();My question is:
how can I load (from a HTTP server) and play more than two WAV files without crashing?
Do I have to close the connection in a better way in order to re-open it without problems (and more than two times)?
It is simply an emulator bug?
Thanks. -
How do I play the .wav file google mail sends me on my Iphone 5?
I have cable phone service that sends out a .wav file of any voicemails I recieve to my e-mail account. I use google mail on my Iphone, and cannot play the .wav file that is attached to that e-mail. When I click on the "audio message box", it brings up a circle containing a south-west facing arrow which has a slash through it.
I have the latest software (6.1.4) and I can play the attachment if I go through "Mail" instead of "GMail". I am still not certain why I have a widget called "Mail".
Inside the "Mail" app, there are it's own Inbox, VIP, Flagged, etc which are all in color. Further down the list is my GMail boxes and sub-boxes. They are all grayed out, but still funtional.
Do I have something set up wrong causing me to be unable to play the .wav files that come to me through gmail? -
How to play a wav file to LINE_OUT with javax.sound.sampled
Hello all,
I need to play a wav file to LINE_OUT port, but not to the SPEAKER. I am trying to do this under window NT. For some reason I get false for isLineSupported(Port.Info.LINE_OUT). I am new to javax.sound so I might be doing something wrong. Here is the code that I am using to iterate through all availible mixers and check if LINE_OUT is supported by any of them:
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
for(int i = 0; i < mixers.length; i++){
Mixer mixer = AudioSystem.getMixer(mixers);
if (mixer.isLineSupported(Port.Info.LINE_OUT)) {
System.out.println("the port is supported");
try {
Port line = (Port) AudioSystem.getLine(
Port.Info.LINE_OUT);
catch(Exception ex){
ex.printStackTrace();
else{
System.out.println("the port is not supported");
Please helpThe new bugID of the request to implement Ports is: 4558938.
(If you voted for the old bug id: 4504642, be sure to change your votes to this new bug report since the old one was closed as a duplicate of the new one.) -
Play a .wav file fractional
hi,
i´m looking for a solution to play a .wav file.
the special what i need is, that i want to jump to concrete points on the timeline.
or can i seperate the timeline of a .wav file?
martinHi Martin
this could help you starting. For the case you can't open LV 8.2- VIs, i attach the BD- picture.
greets, Dave
Message Edited by daveTW on 06-14-2007 10:26 AM
Greets, Dave
Attachments:
play sound part_FP.png 10 KB
play sound part.vi 50 KB -
Need Help playing a wav file on PDA
Does anyone have a SIMPLE example of playing a wav file on a PDA using LabView PDA. The only working example I can find from NI "Advance Sound Example for LabVIEW PDA for Pocket PC" is a jumbled of confusing functionality. I'm mainly looking for a simple "play" example, but a simple "record" example would be helpful also.
Thanks - BruceHello,
Well, I looked through the example code I tried to break it down to the point where you could create a simple Play VI. Unfortunately, I don't have the PDA target, so I'm uncertain if the little example that I have attached will run or not. If not, I also took a screen shot so you can see what VIs I used. I'm pretty sure I only used VI's that I found on the example itself.
Good luck.
Attachments:
Play_Wav_PDA.vi 55 KB
Play_Wav_PDA.bmp 1029 KB -
Streaming wav files once edited won't work in flash
I need some help with streaming wav files in flash. I can load a wav file and stream it ok using actionscript 3 into my fla file. However if I go to edit the wav and make it shorter the saved wav file will not play. I have used a trial version of soundbooth to see if I could somehow change the settings for the wav but I still cannot make it work. It will stream as an mp3 but I want the file to loop and need the file to be wav. I have attached the file. I have no problem when I upload the file into the fla file but that is not what I want to do.
Can anyone help me.
Cheers.Thanks for the input however I had already tried a variety of combinations. But I did go through it again.
The Flash Player supports 8-bit or 16-bit audio at sample rates of 5.512, 11.025, 22.05, or 44.1 kHz. I have tried all permutations of wav from 8 bit to 16bit and the all sampling rates from 11.025. The original file is attached at it was at 32000hz. Nothing I can do will make these play in flash once edited. I am using soundbooth howeve I have used audacity and wavepad. I have removed the metadata tags as that was suggested in one of the forums. I have attached the original files and the shortened file that I cannot get to work. I went into Soundbooth and went through all the preferences and checked the box where it asked for FLash compaticble at 16bit 44 hz etc. This is really frustrating. I know wav can be streamed. -
I am having big problems to create a music background for my project. I am newbie using labview and maybe my questions is not so dificult to solve (I hope so)
I was using play sound file vi but the problem is that I dont want the music file start automatically. I wanna control the start time using a button. I tried include a sound output stop but when the app start and I add more wav files in my vi, the sound file start, then stop abruptally because the stop vi and the everything is normal. I would like to eliminate that error.
Someone have any idea, maybe using open file or another way.
Thanks in advance
I add a screenshot of my vi and also the vi in this post
Attachments:
test sound.vi 11 KBI leave an example that can provide, use it in your program
Atom
Certified LabVIEW Associate Developer
Attachments:
playsound.zip 58 KB -
Playing a .wav file loaded from filesystem
I am trying to play a local file and getting:
Have not been able to load: MediaError: media unsupported:com.sun.media.jmc.MediaUnsupportedException: Unsupported media: file:///product-name/lib/buzzer.wav
I get a different exception if the file does not exist, so the message seems to be saying it has a problem with .wav files, or this .wav file in particular??
I am using 1.3, but this page is for 1.2:
http://download.oracle.com/javafx/1.2/tutorials/media/format.html
There doesn't seem to be an equivalent page for 1.3. If 1.2 rules still applied then for Audio on Vista the resolution under 'Supported Media Codecs' is "All the audio formats supported by Windows Media Player". And [this file|http://www.strandz.org/javafxstreaming/buzzer.wav] certainly works on Windows Media Player.
package def alarmSoundPlayer = MediaPlayer
media: makeFilesystemMedia( "file:///product-name/lib/buzzer.wav");
autoPlay: false;
repeatCount: 1;
public function makeFilesystemMedia( fileName: String): Media
var music = Media
source: fileName
onError: function( mediaError: MediaError)
println( "Have not been able to load: {mediaError}");
return music;
}It might not be the issue, but the file:///product-name/lib/buzzer.wav is strange. Aren't you missing a drive specification? (might not be necessary if on the same disk, but still unusual). Is the "product-name" at the root of the disk? When in doubt of URL syntax, you can still use a path to initialize a File object, then get toURI().toURL() to have a normalized URL.
HTH. -
Reading, filtering and playing large WAV files
Hi!
I want to build an application that reads LARGE wavefiles, filters them and plays them via the soundcard.
I tried to build something with the standard blocks available in Labview 7.0, but I keep running out of memory. The files I want to filter and play are simply too large The filesize is typ. 650Mb = 1 hour of stereo CD quality audio. The files I am using just won't play even on a WIN XP machine with 1Gb of memory.
Next step was to build a function that loads the WAV files in blocks of ~16kB. This works fine, but now the filtering does not work anymore; after each block, the 'FIR Filter' block seems to reset its states. The result is a very bad repeating artifact in the sound. The repetition-rate is related to the buffer size.
Does anyone have experience with this type of application? Help and examples are -very- welcome (as I am new to Labview... .
Many thanks,
Dr.dBI have created a VI that will do the continuous FIR filtering you need. I assume you want to filter a 'stereo' signal so the VI takes an array of waveforms as input. In this version the FIR filter coefficients (kernel) is common to all channels. If this is not what you need you can correct the VI accordingly.
The control 'algorithm' specifies whether the FIR convolution is internally performed in the time or frequency domain. Changing the 'algorithm' does not affect your result but affects your performances. Select time domain (direct) if your kernel size (number of FIR coefficients) is, say less than 100, otherwise select 'frequency domain'.
Try the attached example and let me know if you have any problems.
Attachments:
continuous FIR filtering on multiple channels.llb 79 KB
Maybe you are looking for
-
Recently, FF has started opening my last tabs when I start a fresh session. I have already checked to make sure that none of the applicable settings are enabled, such as under Options->General: When FF starts "SHOW MY HOMEPAGE" is selected. But for s
-
Where did my brightness slider bar go????
Hi all, I have a macbook 13.3 thats having issues with the brightness. It seems to just be too bright and the blacks just don't look right. My friend showed me on his Macbook Pro how to change the brightness using the slider bar in the display prefer
-
How to set Password for Xellerate user in OIM
I am using recon API's and creating Xellerate user, unfortunately the recon is not accepting USR_PASSWORD which is the field name defined in OIM Can somebody please let me know how to set this password for Xellerate user?? Thank you in advance for yo
-
Weird box on desk top from ICal Info Window when using Expose
Whenever I use the info Window in iCal to enter some text in the Notes area, if I don't remember to click on the main window, or pretty much any other place in iCal afterward then when I use Expose to go to the desk top I end up with this wierd recta
-
Information Engineering Notation
Hello Why only sql developer data modeler extension has Information Engineering Notation in Logical Model Diagram? Regards Nelson