0

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();
}
%>
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by peter_budo
0

Move that code to servlet, where it actually belong to, and in doing so you will enable yourself for better debugging.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.