问题描述
我最终想要做的是从用户的麦克风录制,并在完成后将文件上传到服务器。到目前为止,我已经设法使用以下代码创建一个元素流:
What I ultimately want to do is record from the user's microphone, and upload the file to the server when they're done. So far, I've managed to make a stream to an element with the following code:
var audio = document.getElementById("audio_preview");
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.getUserMedia({video: false, audio: true}, function(stream) {
audio.src = window.URL.createObjectURL(stream);
}, onRecordFail);
var onRecordFail = function (e) {
console.log(e);
}
我该如何去记录文件?
推荐答案
这里有一个相当完整的录音演示:
There is a fairly complete recording demo available at: http://webaudiodemos.appspot.com/AudioRecorder/index.html
它允许您在浏览器中录制音频,然后给出您可以导出并下载您记录的内容。
It allows you to record audio in the browser, then gives you the option to export and download what you've recorded.
您可以查看该页面的来源以找到JavaScript的链接,但总而言之, code> Recorder 包含 exportWAV
方法的对象,以及 forceDownload
方法。
You can view the source of that page to find links to the javascript, but to summarize, there's a Recorder
object that contains an exportWAV
method, and a forceDownload
method.
这篇关于HTML5将音频录制到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!