Topic
  • 1 reply
  • Latest Post - ‏2005-05-09T14:51:40Z by SystemAdmin
SystemAdmin
SystemAdmin
835 Posts

Pinned topic How to submit a record audio over to web server?

‏2005-05-09T06:29:16Z |
Hi,

I'm trying to use <record> element to record user inputs and submit it to a jsp on a web server. The jsp just simply output a vxml hello world. I've tried to test this app with Bevocal Cafe and the debugger gave me a bad.fetch.timeout error. Here's the vxml:

<vxml version="1.0">
<form>
<record name="greeting" beep="true" maxtime="10s" finalsilence="4000ms" dtmfterm="true" type="audio/wav">
<prompt> please say your greeting. </prompt>
<noinput> I didn't hear anything, please try again. </noinput>
</record>
<field name="confirm" type="boolean">
<prompt> Your greeting is <value expr="greeting"/>.
</prompt>
<prompt> To keep it, say yes. To discard it, say no.
</prompt>
<filled>
<if cond="confirm">
<submit next="http://www.myjavaserver.com/~dzinh/test5vxml.jsp" method="post" namelist="greeting"/>
</if>
<clear/>
</filled>
</field>
</form>
</vxml>
test5vxml.jsp:

<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<form id="form">
<block>
<prompt>
Hello World Two!
</prompt>
</block>
</form>
</vxml>

What am I done wrong here? I was able to submit non-audio elements, so I'm sure it is not the problem of wrong URL. Any help is appreciated. Thanks.

Vinh
Updated on 2005-05-09T14:51:40Z at 2005-05-09T14:51:40Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    835 Posts

    Re: How to submit a record audio over to web server?

    ‏2005-05-09T14:51:40Z  
    Hi,

    With all the "&lt", and "&gt", it's hard to read the code that you have down
    here. However I can guess what the problem is, when you are submitting a raw
    recorded audio to a servlet, you need to specify the type of data as
    "multipart/form-data". Also, the way you access this data is different, see
    the following two files, and you will be able to understand.

    You need to have a jar file inorder for this servlet to work. I remember
    downloading it from a website, but cannot remember. I tried to attach it to
    this mail, but couldn't do that. Try googlit, and if you cannot find it, let
    me know your email address, I could email to you.

    Let me know if that helps,
    Regards,
    -Kris
    TestRecording.vxml

    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE vxml PUBLIC "-//W3C//DTD VOICEXML 2.0//EN" "vxml20-1115.dtd">

    <vxml version="2.0" xml:lang="en-US" xmlns="http://www.w3.org/2001/vxml">
    <meta name="GENERATOR" content="Voice Toolkit for WebSphere Studio" />

    <form id="Welcome">
    <block>
    Welcome to the recording demo application.
    <goto next="#GetMsg" />
    </block>
    </form>

    <form id="GetMsg">
    <record beep="true" dtmfterm="true" maxtime="300s" finalsilence="2500ms"
    name="msg" type="audio/x-wav">
    <prompt>Please record your message after the beep.</prompt>
    <noinput>I didn't hear anything, please try again.</noinput>
    </record>
    <block>
    Your message is
    <audio expr="msg" />
    <submit next="http://localhost:9080/VDT/servlet/SaveAudio" method="post"
    enctype="multipart/form-data" namelist="msg" />
    </block>

    <block>Thank you for calling.</block>
    </form>
    </vxml>

    SaveAudio.java

    import java.io.File;
    import java.io.IOException;
    import java.util.Enumeration;

    import javax.servlet.Servlet;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import com.oreilly.servlet.MultipartRequest;

    /**
    * @version 1.0
    * @author
    */
    public class SaveAudio extends HttpServlet implements Servlet {

    /* (non-Javadoc)
    * @see javax.servlet.GenericServlet#init()
    */
    public void init() throws ServletException {
    File file = new File("C:/dest/");
    file.mkdirs();
    }

    /* (non-Javadoc)
    * @see
    javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
    javax.servlet.http.HttpServletResponse)
    */
    protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
    throws ServletException, IOException {
    // Get output stream.
    ServletOutputStream out = arg1.getOutputStream();

    // establish directory in which to save recordings and 5 MB upload limit
    MultipartRequest multi = new MultipartRequest(arg0, "C:/", 5242880);

    File tempFile = null;

    Enumeration files = multi.getFileNames();
    String enumName, fileName;
    while (files.hasMoreElements()) {
    enumName = (String) files.nextElement();

    fileName = multi.getFilesystemName(enumName);

    tempFile = multi.getFile(enumName);
    tempFile.renameTo(new File("C:/dest/" + System.currentTimeMillis() +
    ".wav"));
    }

    // Send a response back to VXML client.
    arg1.setContentType("text/xml");
    out.println("<?xml version=\"1.0\"?>");
    out.println("<vxml version=\"2.0\"
    xmlns=\"http://www.w3.org/2001/vxml\"><form><block>");
    out.println("<prompt>Your greeting was
    saved.</prompt><exit/></block></form></vxml>");
    out.flush();
    out.close();
    }

    }

    <vnguyen@cs.uml.edu> wrote in message
    news:231900426.1115620187187.JavaMail.wassrvr@ltsgwas007.sby.ibm.com...
    > Hi,
    >
    > I'm trying to use <record> element to record user inputs and submit
    > it to a jsp on a web server. The jsp just simply output a vxml hello
    > world. I've tried to test this app with Bevocal Cafe and the debugger gave
    > me a bad.fetch.timeout error. Here's the vxml:
    >
    > <vxml version="1.0">
    > <form>
    > <record name="greeting" beep="true"
    > maxtime="10s" finalsilence="4000ms"
    > dtmfterm="true" type="audio/wav">
    > <prompt> please say your greeting. </prompt>
    > <noinput> I didn't hear anything, please try again.
    > </noinput>
    > </record>
    > <field name="confirm" type="boolean">
    > <prompt> Your greeting is <value expr="greeting"/>.
    > </prompt>
    > <prompt> To keep it, say yes. To discard it, say no.
    > </prompt>
    > <filled>
    > <if cond="confirm">
    > <submit
    > next="http://www.myjavaserver.com/~dzinh/test5vxml.jsp"
    > method="post" namelist="greeting"/>
    > </if>
    > <clear/>
    > </filled>
    > </field>
    > </form>
    > </vxml>
    >
    >
    > test5vxml.jsp:
    >
    > <vxml version="2.0"
    > xmlns="http://www.w3.org/2001/vxml">
    > <form id="form">
    > <block>
    > <prompt>
    > Hello World Two!
    > </prompt>
    > </block>
    > </form>
    > </vxml>
    >
    >
    >
    > What am I done wrong here? I was able to submit non-audio elements, so I'm
    > sure it is not the problem of wrong URL. Any help is appreciated. Thanks.
    >
    > Vinh