Hi,
I have the following jsp file which receives an audio file from the form. I am receiving the form data as Multipart and saving the uploaded file as temp.wav. The uploaded file is in uLaw audio format. I want to convert it to PCM format and save it as 1j.wav. I have the following code below. It doesnt give any error but it doesnt generate the file 1.j either.
Any help will be much appreciated.
<%@page import="java.util.*" %>
<%@page import="java.io.*" %>
<%@page import="com.oreilly.servlet.multipart.*" %>
<%@page import="javax.sound.sampled.*"%>
<%
try {
MultipartParser mr = new MultipartParser(request, 5 * 1024 * 1024);
Part p;
p = mr.readNextPart();
FilePart pt = (FilePart) p;
File temp = new File("C:/temp.wav");
File fileout = new File("C:/1java.wav");
FileOutputStream fout = new FileOutputStream(temp);
pt.writeTo(fout);
AudioInputStream sourceaudio = AudioSystem.getAudioInputStream(pt.getInputStream());
AudioFormat targetformat = new AudioFormat(new AudioFormat.Encoding("PCM_SIGNED"),8000,8,2,8,8000,true);
AudioFileFormat.Type targettype = AudioFileFormat.Type.WAVE;
AudioInputStream targetaudiostream = AudioSystem.getAudioInputStream(targetformat,sourceaudio);
AudioSystem.write(targetaudiostream, targettype, fileout);
out.println("<saveStatus>SUCCESS</saveStatus>");
} catch (Exception e) {
out.println("<saveStatus>FAIL</saveStatus>");
e.printStackTrace();
}
%>