public String playVoiceFile() throws Exception {
String filePath = "D:/Voice/aa.wav";
if (!filePath.equals("")) {
//Get audio input stream
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(filePath));
//Get audio coding object
AudioFormat audioFormat = audioInputStream.getFormat();
//Set data entry
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat,
AudioSystem.NOT_SPECIFIED);
SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
//Read from the data sent to the mixer input stream
int count;
byte tempBuffer[] = new byte[1024];
while ((count = audioInputStream.read(tempBuffer, 0, tempBuffer.length)) != -1) {
if (count > 0) {
sourceDataLine.write(tempBuffer, 0, count);
}
}
//Empty the data buffer, and close the input
sourceDataLine.drain();
sourceDataLine.close();
}
return null;
}