Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Record clip of unknown length with Microphone.Start

Discussion in 'Audio & Video' started by jgp80, Dec 4, 2014.

  1. jgp80

    jgp80

    Joined:
    Aug 24, 2012
    Posts:
    23
    Hi,

    I want to be able to record to an AudioClip all the audio generated between the Start and End function calls. This audio clip is later saved to a file in disk. However, Start forces me to specify the length in seconds of the audio clip I want to record. Since this is an unknown information, I can fall short or it may be too long.

    There is a way to record an AudioClip of the exact length?

    If not, what would be the best approach to solve my problem?

    Cheers and thanks in avance.
     
    CloudyVR likes this.
  2. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Check out my framework G-Audio, it handles this problem efficiently by only allocating a tiny clip in Micriphone.Start and piping the data to a memory buffer or to disk ( as a wav file ). It can all be done with minimal coding, through I/O modules that you can drag and drop on AudioSources to route their audio data.

    If you want to do it yourself, you'll have to grab audio data from the mic's AudioSource in OnAudioFilterRead, format it in int16s, and write it to disk as a wav file ( with proper header ), preferably on a separate thread so as not to burden the audio thread with file I/O.

    Cheers,

    Gregzo
     
  3. jgp80

    jgp80

    Joined:
    Aug 24, 2012
    Posts:
    23
    Hi gregzo, your framework sounds interesting. Is there any demo/trial to evaluate it before buying?

    Thanks for your feedback.

    Cheers.
     
  4. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi,

    There's no trial version at the moment, sorry.

    If all you need is to record mic input to disk, then G-Audio is overkill. There are other assets in the store which are cheaper and more focused on your use case, you should check them out.

    Cheers,

    Gregzo
     
  5. jgp80

    jgp80

    Joined:
    Aug 24, 2012
    Posts:
    23
    Hi thanks for being so honest. I just need to record input and save it to a file, so I think I should check other assets.

    I checked some but I'm not sure if they allow me to record unlimited time, would you recommend me anyone?

    Cheers.
     
    CloudyVR likes this.
  6. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Hi @SelfishGenome,

    What is it about? You can make a new thread and tag me, or pm me, or if you're a G-Audio user use the G-Audio forums. And please, hide that e-mail of yours fast!

    Cheers,

    Gregzo