Recently in the video recording of things to see the next audio recording and output. The main reference is the official framecapturer:
Https://github.com/unity3d-jp/FrameCapturer
Because the demand is not very complex, only recorded and simple WAV output.
WAV file structure is relatively simple, divided into two parts of the file header and data, the file header format on the Internet, the data can be directly using uncompressed data.
One thing to note here is that C # does not populate all bytes when writing with StreamWriter.
For example, the int data occupies 4 bytes, and the write will only fill in the corresponding data size byte, so here use Bitconverter to do byte write
Mfilestream.write (bitconverter.getbytes (04);
Get audio This piece can be provided by unity itself with events:
void Onaudiofilterread (floatint channels) { ...}
Audio write order is mono channel-right channel, left channel-right channel ... Cycle. Since unity is in this order by default, the second parameter is not available.
Corresponding to the different bits of the WAV file, the corresponding numeric conversion operation can be done when the byte is written.
Project file Address:
Https://gitee.com/Hont/WavAudioRecorder
Recording and outputting wav files in Unity3d