包含WAV文件和WAV文件的Blob:有什么区别以及如何相互转换?

时间:2021-08-07 19:43:39

Premise: I noticed there a other similar questions but looks like the interesting ones have no answers. e.g. Have a blob for a wav file on client side, how do I send it as a wav file to the server?

前提:我注意到还有其他类似的问题,但看起来有趣的问题没有答案。例如在客户端有一个blob用于wav文件,如何将其作为wav文件发送到服务器?

I'm using RecordRTC to get a WAV file on user voice input.

我正在使用RecordRTC来获取用户语音输入的WAV文件。

What I get is a Blob (binary file) printed (on console) as:

我得到的是一个Blob(二进制文件)打印(在控制台上):

Blob {}
  size: 131116
  type: "audio/wav"
  __proto__

I understand that the Blob contains a WAV audio stream but the WAV is contained by a Blob, rather than a WAV container (i.e. a WAV file). right?

我知道Blob包含WAV音频流,但WAV包含在Blob中,而不是WAV容器(即WAV文件)。对?

So, how do I extract the WAV stream, e.g. to send it to a server through an ajax/http call?

那么,我如何提取WAV流,例如通过ajax / http调用将其发送到服务器?

I don't mind using a HTTP or NodeJS script if it's needed.

如果需要,我不介意使用HTTP或NodeJS脚本。

EDIT I will try what's been proposed in one answer. Since I'm doing this in AngularJS (I'm still a beginner at it) I'd like to do something like...

编辑我将尝试在一个答案中提出的建议。因为我在AngularJS中这样做(我还是初学者)我想做点什么......

services.sendAudioMessage(recordedAudio)
    .then(function (data) {
}

where services is defined by a factory:

服务由工厂定义:

.factory('services', function($http,$q) {
    return {
        sendAudioMessage: function (audioMessage) {
            return $http.jsonp('http://.../api.php?callback=JSON_CALLBACK', {
                params: {
                    audio: audioMessage
                }
            })
                .then(function (response) { 
                    if (typeof response.data === 'object') {
                        return response.data;
                    } else { 
                        return $q.reject(response.data);
                    }
                }, function (response) { 
                    return $q.reject(response.data);
                });
        }
    };
});     

rather than using an Ajax call as proposed in: How can javascript upload a blob?

而不是使用如下建议的Ajax调用:javascript如何上传blob?

1 个解决方案

#1


A Blob is just a binary object in-memory. RecordRTC actually stores a full WAV file with the WAV headers in the Blob for you. It's not just PCM samples, it's a regular WAV file.

Blob只是内存中的二进制对象。 RecordRTC实际上为您存储了Blob中带有WAV标头的完整WAV文件。这不仅仅是PCM样本,而是常规的WAV文件。

You can do something with that data directly or upload to your server like any other blob. See also: https://*.com/a/13333478/362536

您可以直接对该数据执行某些操作,也可以像任何其他blob一样上传到您的服务器。另见:https://*.com/a/13333478/362536

#1


A Blob is just a binary object in-memory. RecordRTC actually stores a full WAV file with the WAV headers in the Blob for you. It's not just PCM samples, it's a regular WAV file.

Blob只是内存中的二进制对象。 RecordRTC实际上为您存储了Blob中带有WAV标头的完整WAV文件。这不仅仅是PCM样本,而是常规的WAV文件。

You can do something with that data directly or upload to your server like any other blob. See also: https://*.com/a/13333478/362536

您可以直接对该数据执行某些操作,也可以像任何其他blob一样上传到您的服务器。另见:https://*.com/a/13333478/362536