简体   繁体   English

使用HTML5 / Flash录制和上传(到服务器)音频

[英]Record and upload (to server) audio with HTML5/Flash

I know that getUserMedia() wont be supported in a few browsers so I have to use more or less a flash based audio recorder. 我知道在几个浏览器中不支持getUserMedia(),因此我必须使用或多或少的基于闪存的录音机。 Its very important for me to upload the captured audio to a server via POST even if I could get access to the clientside captured audio would be pretty awesome. 通过POST将捕获的音频上传到服务器非常重要,即使我可以访问客户端捕获的音频也非常棒。 So do you guys know a libary/plugin/extension to do this? 所以你们知道一个libary / plugin / extension来做到这一点吗?

I found some scripts as well like: 我发现了一些脚本,如:
https://github.com/mattdiamond/Recorderjs https://github.com/mattdiamond/Recorderjs
https://github.com/jwagener/recorder.js/ https://github.com/jwagener/recorder.js/

But the upload doesnt work. 但上传不起作用。 I dont know how I could continue. 我不知道如何继续。

You can save the recorded data as a blob and then use a FileReader to upload the data via POST with AJAX. 您可以将记录的数据保存为blob,然后使用FileReader通过POST使用AJAX上传数据。

Something similar along these lines: 这些方面类似的东西:

function uploadAudio(mp3Data){
    var reader = new FileReader();
    reader.onload = function(event){
        var fd = new FormData();
        var mp3Name = encodeURIComponent('audio_recording_' + new Date().getTime() + '.mp3');
        console.log("mp3name = " + mp3Name);
        fd.append('fname', mp3Name);
        fd.append('data', event.target.result);
        $.ajax({
            type: 'POST',
            url: 'upload.php',
            data: fd,
            processData: false,
            contentType: false
        }).done(function(data) {
            //console.log(data);
            log.innerHTML += "\n" + data;
        });
    };      
    reader.readAsDataURL(mp3Data);
}

This code is taken directly from the gitHub project Recordmp3js available here: https://github.com/nusofthq/Recordmp3js 此代码直接来自gitHub项目Recordmp3js: https//github.com/nusofthq/Recordmp3js

It records audio and saves it MP3 format using just HTML5 and JS and then uploads the data on the webserver. 它只使用HTML5和JS记录音频并保存MP3格式,然后在网络服务器上传数据。

It only works on Chrome and Firefox though. 它仅适用于Chrome和Firefox。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM