I'm trying to send AudioClips through UnityWebRequest (not important for now) and the way I've found to do that is converting AudioClips to byte[] and sending it as a raw audio file. But this audio file doesn't seem to be working correctly. When I try saving the raw audio directly to my computer and play it in Audacity, it sounds very noisy and corrupt. When I speak into the mic, my voice can barely be made out in the static when I play it in Audacity.
This is what I am currently doing to get my AudioClip to a file:
float[] samples = new float[audioClip.samples * audioClip.channels];
audioClip.GetData(samples, 0);
byte[] byteArray = new byte[samples.Length * 4];
Buffer.BlockCopy(samples, 0, byteArray, 0, byteArray.Length);
File.WriteAllBytes("myAudio/audio.raw", byteArray);
Playing it within Unity works fine (whether playing the original AudioClip or converting it back from bytes). How can I get the file to play correctly. Is there a specific way to decode it in Audacity? Do the bytes not correspond to a raw audio file and must they somehow be converted?