如何将录音文件另存为.wav 文件

How to get recode file save as .wave file

我想在为 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>

我想在播放后获取消息重新编码。这道题怎么做?我想在 java 中回答。

您可以通过在录音 var 中添加标签来保存录制的消息,并使用一些服务器端代码处理提交请求,例如 PHP/JSP/ASPX 包含 PHP 示例:
编辑:添加使用 apache commons 的 record.jsp:http://commons.apache.org/proper/commons-fileupload/
也修改 record.vxml 以将数据提交到 record.jsp,record.php 保留为一个参考[​​=14=]

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