How to use RECORD with
Voicent Gateway
Voicent Gateway follows the VoiceXML standard implementation
for RECORD tag. The example here illustrates the standard vxml
file with <RECORD> tag, and a post processing JSP file for
handling the recorded file.
The vxml file with <RECORD>
- <?xml
version="1.0"?>
<vxml version="1.0">
<form id="userecord">
<record name="msg">
<prompt>
<audio src="audio/please_record_msg.wav"/>
</prompt>
<filled>
<var name="forwardpage" expr="'/next.jsp'"/>
<submit next="processwave.jsp"
method="post"
namelist="forwardpage
msg"/>
</filled>
</record>
</form>
</vxml>
Once the recording is done, the current VoiceXML interpreter is
forwarded to a post processing page "processwave.jsp".
Post processing JSP file
The following code utilizes HTTPClient package.
- ...
// process the form submission from the vxml page
-
ByteArrayOutputStream bout = new ByteArrayOutputStream();
InputStream ins = request.getInputStream();
byte[] chunk = new byte [256];
int len;
while ((len = ins.read(chunk)) != -1)
bout.write(chunk, 0, len);
byte[] body = bout.toByteArray();
String dir = application.getRealPath("./audio");
NVPair[] opts = Codecs.mpFormDataDecode(bout.toByteArray(),
request.getContentType(),
dir);
String forwardpage = null;
String filename = null;
for (int i = 0; i < opts.length; i++) {
if (opts[i].getName().equals("forwardpage"))
forwardpage = opts[i].getValue();
else
filename = opts[i].getValue();
}
- //
recordFile is the temporary file used by the gateway
File recordFile = new File(dir, filename);
// save to the real recording file
String saveFilename = "myrecording.wav";
// copy file
FileInputStream inf = new FileInputStream(recordFile);
FileOutputStream outf = new FileOutputStream(saveFilename);
byte[] buf = new byte[256];
int ll;
while ((ll = inf.read(buf)) != -1)
outf.write(buf, 0, ll);
inf.close();
outf.close();
if (forwardpage != null) {
response.sendRedirect(forwardpage);
return;
}
- ...
|