package s1;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;

public class SoundSample1 {

	public static void main(String[] args) throws Exception {

		AudioInputStream audioStream = AudioSystem
				.getAudioInputStream(SoundSample1.class
						.getResourceAsStream("voice.wav"));

		AudioFormat format = audioStream.getFormat();
		byte[] buffer = new byte[8000];	

		DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

		SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
		line.open(format, buffer.length);

		line.start();

		int numBytesRead = 0;
		while ( numBytesRead != -1) {
			numBytesRead = audioStream.read(buffer, 0, buffer.length);
			if (numBytesRead != -1) {
				line.write(buffer, 0, numBytesRead);
			}
		}
		
		line.drain();
		line.close();
		System.exit(0);
	}
}
