I have a Float32Array with values from an audio file.I want to save it as a .wav file so I need to convert that values to a Uint8array.
To convert from uint8 to float I convert first to an int16 array and then to a Float32Array (Convert int16 array to float) How can I do that conversion in the other direction?
You can convert to an
ArrayBuffer
, copy the data into and then create a byte view of this buffer :This function can convert any TypedArray to any other kind of TypedArray :
Example :
Edit
As Ian pointed out in the comment section, you can access the
ArrayBuffer
withTypedArray.buffer
, so you can simply do :Note that doing this,
byteArray
andfloatArray
will share the same buffer, so modifyingbyteArray
will modifyfloatArray
and vice versa.