How to create a virtual microphone in Unity?

I am working on a simulator, where I put several AudioResources. What I want to do is to create a virtual microphone, which can be moved to different locations. In each frame, the virtual microphone will collect audio it “hears” and send it out via WebSocket (or save it in file).

I can use an AudioListener and move it to the position I want in each frame. According to Unity document, AudioListener will automatically handle all sound effects (e.g. reflection, diffraction, attenuation, Doppler effect, etc.), which is great for me. However, it seem only be able to play what it “hears” to the physical speaker. Although there are “AudioListener.GetOutputData” and “AudioListener.GetSpectrumData”, the document did not explain clearly the meaning of the results returned by these functions. So I do not know how to serialize the data (sending out or save) in the format I want (e.g. WAV).

Can anyone provide some example code of serializing the result of AudioListener to WAV format? Thanks a lot!

1 Like

Hi did you find out how to solve the saving audio issue?