本文介绍了了解AudioBuffer到ArrayBuffer的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AudioBuffer客户端,我想AJAX到快递服务器.

I have an AudioBuffer client-side that I'd like to AJAX to a express server.

此链接显示了XMLHttpRequest如何发送/接收二进制数据-ArrayBuffer.

This link shows how a XMLHttpRequest can send/receive binary data - ArrayBuffer.

ArrayBuffer与AudioBuffer(或者我相信)不同,因为我首先解码了ArrayBuffer来制作AudioBuffer.使用 decodeAudioData()完成此操作网络音频API.

An ArrayBuffer is different to an AudioBuffer (or so I believe) as I decoded an ArrayBuffer to make the AudioBuffer in the first place. This was done using decodeAudioData() as part of the Web Audio API.

所以我的问题是,我可以将AudioBuffer转换回ArrayBuffer吗?

So my question is, can I convert an AudioBuffer back to an ArrayBuffer?

如果可能的话,我想将ArrayBuffer发送到我的快递服务器,然后将其转发到S3存储桶,如此示例.

If this is possible, I'd like to then send the ArrayBuffer to my express server and then forward it on to a S3 bucket as shown in this example.

在该示例中,代码在通过fs.readFileSync()创建的S3存储桶中放置了一个Buffer.我认为Buffer和ArrayBuffer之间的区别不会是S3的问题:S

In that example, the code PUTs a Buffer in a S3 bucket created via a fs.readFileSync(). I assume the difference between a Buffer and ArrayBuffer wont be an issue with S3 :S

推荐答案

使用 copyFromChannel 方法,然后将 Float32Array 转换为 ArrayBuffer .

Use the copyFromChannel method, then convert the Float32Array to an ArrayBuffer.

var myArrayBuffer = audioCtx.createBuffer(2, frameCount, audioCtx.sampleRate);  
var anotherArray = new Float32Array();
myArrayBuffer.copyFromChannel(anotherArray,1,0);

这篇关于了解AudioBuffer到ArrayBuffer的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 07:37