I need to fetch an audio file using Ajax and receive it in the form an array of bytes. My backend is on PHP.
Currently I am using
<?php
echo file_get_contents("./mainFile.mp3");
?>
This lets me return the audio file in the form an array of bytes. But how can I receive it in Javascript as a byte array. I referred this link on SO
But this does not seem to be the proper way. Can anyone please suggest something ???
You need to
overrideMimeType()to"text/plain; charset=x-user-defined"like so:Note that this is extremely futile, bit operations in javascript are extremely fast on strings+charCodeAt only. Even faster than on typed arrays, as I shockingly discovered in an application of mine.
The text/plain isn’t important, but the charset is.