Search Unity

Audio How to create a virtual microphone in Unity?

Discussion in 'Audio & Video' started by guodongrong, Sep 25, 2020.

  1. guodongrong

    guodongrong

    Joined:
    Dec 4, 2019
    Posts:
    13
    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!
     
    Rachan likes this.
  2. zacharyaghaizu

    zacharyaghaizu

    Joined:
    Aug 14, 2020
    Posts:
    65
    Hi did you find out how to solve the saving audio issue?