问题描述
我已经看到了这个在这里和其他地方的许多部分答案,但我非常新手codeR,我希望能进行一次彻底的解决方案。我已经能够建立记录从一台笔记本电脑麦克风音频输入Chrome Canary版和可以使用recorder.js,相对轻松地设置录制.wav文件并保存在本地的,一拉(五29.x):
I've seen many partial answers to this here and elsewhere, but I am very much a novice coder and am hoping for a thorough solution. I have been able to set up recording audio from a laptop mic in Chrome Canary (v. 29.x) and can, using recorder.js, relatively easily set up recording a .wav file and saving that locally, a la:
http://webaudiodemos.appspot.com/AudioRecorder/index.html
不过,我需要能够将文件保存到我已经运行的Linux服务器。这是实际的BLOB记录的数据发送到服务器,并保存它作为一个.wav文件,该文件赶上我。我没有必要的PHP和/或AJAX的知识,有关如何将BLOB保存到一个URL和处理,因为我一直在考虑要明白,有使保存该.wav文件挑战确实在Linux二进制文件。我会非常欢迎任何指针朝着正确的方向。
But I need to be able to save the file onto a Linux server I have running. It's the actual sending of the blob recorded data to the server and saving it out as a .wav file that's catching me up. I don't have the requisite PHP and/or AJAX knowledge about how to save the blob to a URL and to deal, as I have been given to understand, with binaries on Linux that make saving that .wav file challenging indeed. I'd greatly welcome any pointers in the right direction.
推荐答案
客户端JavaScript函数上传WAV BLOB:
Client side JavaScript function to upload the WAV blob:
function upload(blob) {
var xhr=new XMLHttpRequest();
xhr.onload=function(e) {
if(this.readyState === 4) {
console.log("Server returned: ",e.target.responseText);
}
};
var fd=new FormData();
fd.append("that_random_filename.wav",blob);
xhr.open("POST","<url>",true);
xhr.send(fd);
}
PHP文件 upload_wav.php
:
<?php
// get the temporary name that PHP gave to the uploaded file
$tmp_filename=$_FILES["that_random_filename.wav"]["tmp_name"];
// rename the temporary file (because PHP deletes the file as soon as it's done with it)
rename($tmp_filename,"/tmp/uploaded_audio.wav");
?>
之后就可以播放的文件 /tmp/uploaded_audio.wav
。
但要记住! /tmp/uploaded_audio.wav
由用户 WWW的数据
,及(由PHP默认)创建不可读由用户。要自动添加相应的权限,追加行
But remember! /tmp/uploaded_audio.wav
was created by the user www-data
, and (by PHP default) is not readable by the user. To automate adding the appropriate permissions, append the line
chmod("/tmp/uploaded_audio.wav",0755);
到PHP的端(PHP结束标记之前&GT;
)。
希望这有助于。
这篇关于记录在Chrome浏览器到服务器保存WAV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!