gpt4 book ai didi

ajax - RecorderJS 通过 AJAX 上传记录的 blob

转载 作者:搜寻专家 更新时间:2023-10-31 08:04:01 25 4
gpt4 key购买 nike

我正在使用 Matt Diamond 的 recorder.js 来浏览 HTML5 音频 API,感觉这个问题可能有明显的答案,但我找不到任何具体的文档。

问题:录制了一个wav文件后,如何通过ajax将这个wav发送到服务器?有什么建议吗???

最佳答案

如果您有 blob,则需要将其转换为 url 并通过 ajax 调用运行该 url。

// might be nice to set up a boolean somewhere if you have a handler object
object = new Object();
object.sendToServer = true;

// You can create a callback and set it in the config object.
var config = {
callback : myCallback
}

// in the callback, send the blob to the server if you set the property to true
function myCallback(blob){
if( object.sendToServer ){

// create an object url
// Matt actually uses this line when he creates Recorder.forceDownload()
var url = (window.URL || window.webkitURL).createObjectURL(blob);

// create a new request and send it via the objectUrl
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "blob";
request.onload = function(){
// send the blob somewhere else or handle it here
// use request.response
}
request.send();
}
}

// very important! run the following exportWAV method to trigger the callback
rec.exportWAV();

让我知道这是否有效.. 尚未测试但它应该有效。干杯!

关于ajax - RecorderJS 通过 AJAX 上传记录的 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15014638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com