admin管理员组

文章数量:1122832

I am trying to convert a recording captured with MediaRecorder from WebM to WAV.

const mediaRecorder = new MediaRecorder(stream); // stream passed from navigator.mediaDevices.getUserMedia
let chunks = [];

mediaRecorder.ondataavailable = function(event) {
  if (event.data.size > 0) {
    chunks.push(event.data);
  }
};

mediaRecorder.onstop = function() {
  const wavBlob = new Blob(chunks, { type: 'audio/wav' });
};

When the media recorder stops, the console outputs the following error:

Uncaught (in promise) TypeError: Failed to execute 'arrayBuffer' on 'Blob': Illegal invocation

window.Blob produces the same error.

I believe this is because Blob is being overwritten with the Blob class from wp-includes/js/plupload/moxie.js (Line 3421). This Blob does not work the same as the HTML5 Blob and I do not see a way to access the HTML5 Blob from it.

I tried saving a reference to the HTML5 Blob on page load like so:

<head>
  <script>const htmlBlob = Blob;</script>
</head>

However, new htmlBlob creates a plupload Blob and causes the same console error.

I assume moxie.js is required for WordPress to run properly, so unqueuing it does not seem like a good solution.

I also tried setting the mimeType to WAV when constructing the MediaRecorder:

const mediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/wav' });

This produces the following console error:

NotSupportedError: Failed to construct 'MediaRecorder': Failed to initialize native MediaRecorder the type provided (audio/wav) is not supported.

本文标签: pluploadHow can I access the native HTML5 Blob in WordPress