0

我需要在 IE10 中捕获麦克风音频。到目前为止,我有两个半工作解决方案:

  • getUserMedia 来自微软的实验性 WebRTC 插件: http ://www.html5labs.com/prototypes/media-capture-api-(2nd-updated)/media-capture-api-(2nd-update)/info 这个问题是虽然我可以在浏览器中捕获和重播音频,但我无法将音频发送到服务器。特别是,不清楚如何从“blob”对象中提取音频数据:

    function msStopRecordCallback(blob) {
          console.log(blob) // outputs {}
          console.dir(blob) // outputs {}
    
          playMediaObject.Play(blob); // This works!
    
    }
    
  • jRecorder: http: //www.sajithmr.me/jrecorder-jquery这个问题是它依赖 Flash 来捕获音频,这是我想避免的。

还有其他方法可以在 IE10 中捕获音频吗?

4

1 回答 1

0

我意识到我的回答有点晚了,但是......您可以将 blob 上传到服务器,如下所示(Javascript):

function saveBlob(blob)
{
   var uploader = new CustomXMLHttpRequest();
   uploader.onpartreceived = function (response)
   {
     // TODO: handle the server response here
   };

   var base = window.location.toString();
   var uploadService = base.substr(0, base.lastIndexOf("/")) + "/api/upload";

   uploader.open("POST", uploadService, true);

   uploader.responseType = "text";

   var form = new FormData();
   form.append("fname", blob, "audio.wav");

   uploader.send(form);
}

在服务器端,您可以将此 blob 视为文件附件,例如 (C#):

public class UploadController : ApiController
{
   public async Task<HttpResponseMessage> PostFile()
   {
      // Check if the request contains multipart/form-data.
      if (!Request.Content.IsMimeMultipartContent())
      {
        throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
      }

      var root = HttpContext.Current.Server.MapPath("~/App_Data");
      var provider = new MultipartFormDataStreamProvider(root);

      try
      {
        // Read the form data and return an async task.
        await Request.Content.ReadAsMultipartAsync(provider);

        var fileName = "";

        // get the uploaded files.
        foreach (var data in provider.FileData)
        {
          var file = new FileInfo(data.LocalFileName);

          // TODO: handle received file here
        }

        if (string.IsNullOrEmpty(fileName))
        {
          return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
        }

        return Request.CreateResponse(HttpStatusCode.OK);
      }
      catch (System.Exception e)
      {
        return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
      }
  }
}

希望这会有所帮助。

于 2014-08-18T08:42:18.440 回答