2

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?

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

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

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?

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

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

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...

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?

Community
  • 1
  • 1
dragonmnl
  • 14,578
  • 33
  • 84
  • 129

1 Answers1

2

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.

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

Community
  • 1
  • 1
Brad
  • 159,648
  • 54
  • 349
  • 530
  • thank you very much Brad. I'll try it a while (and then I'll definitely accept the answer). Any way you could explain how to make it by using AngularJS' premises? (I will updated my question right now) – dragonmnl May 03 '15 at 15:16
  • Sorry, I'm not an Angular guy but you don't really need Angular for this part of your project. – Brad May 03 '15 at 15:43
  • Unfortunately the WS to which I'm supposed to send the file is not working properly. But I think it will work so I will accept your answer to thank you for the effort :) – dragonmnl May 03 '15 at 16:55