Menu

Get data from Unity Microphone: float-Int16 conversion

Help
2016-07-29
2016-07-29
  • Andrea Lisi

    Andrea Lisi - 2016-07-29

    Hi!

    I was wondering one thing:

    I am using Pocketsphinx inside an Unity Application.
    To get the audio I call Microphone.GetPosition(), I get the current sample and then I call clip.GetData(audioBuffer, previousSample) where audioBuffer is the array where I store the data.

    This data is a float number in range [-1...1].
    Because PocketSphinx process_raw() gets an Int16 buffer, I convert each float element el into a short element multipling el * Int16.MaxValue.
    And then I pass the new array of Int16 to the PocketSphinx engine and process_raw() function.

    Finally, previousSample = current .

    Is it this conversion process correct?

    Thank you!

     

    Last edit: Andrea Lisi 2016-07-29
    • Nickolay V. Shmyrev

      The conversion process is correct.

      You need to be careful about position though, it might be that you have extra samples when you do not retrieve full buffer in GetData.

      To debug this thing you can enable raw data logging with -rawlogdir parameter from pocketsphinx and check result files.

       

      Last edit: Nickolay V. Shmyrev 2016-07-29

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.