Audio Blob not working on iOS / Safari

I record audio by sending it as a blob to a nodejs server. The nodejs server then sends it to all connected users who are not currently writing.

Sending blob:

mediaRecorder.onstop = function(e) {
  var blob = new Blob(this.chunks, { 'type' : 'audio/ogg; codecs=opus' });
  socket.emit('radio', blob);
};

Server receiving blob:

socket.on('radio', function(blob) {
  socket.broadcast.emit('voice', blob);
});

Listener receiving blob:

socket.on('voice', function(arrayBuffer) {
  var blob = new Blob([arrayBuffer], { 'type' : 'audio/ogg; codecs=opus' });
  var audio = document.getElementById('audio');
  audio.src = window.URL.createObjectURL(blob);
  audio.play();
});

This works in all browsers / devices except safari and any ios device. Taking this further with the safari inspector, I found this:

1st blob returned 2nd blob returned 3rd blob returned

Does safari need anything else in its headers to correctly interpret blob objects? I studied the accepted types of audio, tried aac / mp3 / ogg without any success. When reading further, I heard links to the fact that in safari and IOS there is an error with streaming audio / video blob data, although I do not understand the details too clearly.

Guidance in the direction of the rite will be very helpful!

EDIT: , audio.src = window.URL.createObjectURL(blob); - , blob ( i)

2: , , blob, base64. , , IOS Safari. , - , IOS / ...

+4
1

-, Web Audio Api, , : https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API

    var audioContext = new (window.AudioContext || window.webkitAudioContext);
    socket.on('voice', function(arrayBuffer) {
      audioContext.decodeAudioData(arrayBuffer, audioData => {
        var source = audioContext.createBufferSource();
        source.buffer = audioData;
        source.connect(audioContext.destination);
        source.start()
    });

iOS, / .

0

Source: https://habr.com/ru/post/1675655/


All Articles