I want to get save audio when vxml request sent for Ivr, I develop Ivr code like this..
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1">
<form>
<record name="myrecording" beep="true">
<prompt>
Please record a message after the beep.
</prompt>
<filled>
<prompt>
You just recorded the following message: <value expr="myrecording"/>
</prompt>
</filled>
</record>
</form>
</vxml>
I want get msg recode and after play. how to do this question? I want to answer in java.
You can save your recorded message by adding tag with your recording var and handle the submit request using some server side code like PHP/JSP/ASPX a PHP sample is included :
Edit: adding record.jsp which uses apache commons: http://commons.apache.org/proper/commons-fileupload/
also record.vxml is modified to submit the data to record.jsp , record.php is kept as a reference
"record.vxml"
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1">
<form>
<record name="myrecording" beep="true">
<prompt>
Please record a message after the beep.
</prompt>
<filled>
<prompt>
You just recorded the following message: <value expr="myrecording"/>
</prompt>
<submit expr="record.jsp" method="post" namelist="myrecording" enctype="multipart/form-data" />
</filled>
</record>
</form>
</vxml>
"record.php"
<?PHP
header('Cache-Control: no-cache');
error_reporting (0);
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo "<vxml version=\"2.0\">";
echo "<form id=\"main\">";
echo "<block>";
if ($HTTP_POST_FILES) {
foreach ($HTTP_POST_FILES as $key => $value) {
foreach ($value as $Filename) {
if (strpos($Filename, "WINNT")) { $ServerSide = $Filename; }
if (strpos($Filename, ".wav")) { $ClientSide = $Filename; }
} // for each statement
$ServerSide = str_replace("\\\\", "/", $ServerSide);
if (!copy($ServerSide, "c:/audio-storage/temp.wav")) {
echo "Could not save filename: " . $ServerSide;
} // if statement
else {
echo "Successfully saved filename: " . $ServerSide;
} // else statement
} // for each statement
} // if statement
echo "</block>";
echo "</form>";
echo "</vxml>";
?>
record.jsp
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.*"%>
<%@ page import="org.apache.commons.fileupload.disk.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.DateFormat"%>
<%@ page import="java.text.SimpleDateFormat"%>
<?xml version='1.0'?>
<vxml version="2.1">
<form>
<%
DateFormat dateFormat = new SimpleDateFormat("yyyy_MM-dd_HH:mm:ss");
Date date = new Date();
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List fileItems = null;
try {
fileItems = upload.parseRequest(request);
} catch (Exception e) {
e.printStackTrace();
}
try {
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
String newFileName = "Recording-" + dateFormat.format(date);
String inputFilePath = "c:/audio-storage/"+ newFileName + ".wav";
File file = new File(inputFilePath);
try {//Writing the wav file
item.write(file);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
%>
<block>
<prompt> Audio upload complete! </prompt>
</block>
</form>
</vxml>