如何将重新编码文件另存为.wave文件

时间:2015-09-23 11:30:27

标签: java ivr vxml

我希望在为Ivr发送vxml请求时保存音频,我开发像这样的Ivr代码..

<?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>

我希望得到msg recode并且在游戏之后。怎么做这个问题?我想用java回答。

1 个答案:

答案 0 :(得分:2)

您可以通过在记录var中添加标记来保存录制的消息,并使用PHP / JSP / ASPX等服务器端代码处理提交请求,其中包含PHP示例:
编辑:添加使用apache commons的record.jsp:http://commons.apache.org/proper/commons-fileupload/
还修改record.vxml以将数据提交到record.jsp,将record.php作为参考保存

&#34; record.vxml&#34;

<?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>

&#34; record.php&#34;

<?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>