Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Converting raw WAV byte[] to mp3 byte[]?

Discussion in 'Audio & Video' started by murbas98, Dec 3, 2022.

  1. murbas98

    murbas98

    Joined:
    Dec 24, 2021
    Posts:
    2
    Hi everyone!

    A project I'm working on requires frequent sending of audio from device to a server. I'm currently sending a WAV byte[] but need to compress audio for efficiency. I've been reading into the math behind the WAV to mp3 compression but I imagine there is a better way than implementing this myself.

    Everything I've seen requires saving the audio on device as a .wav before converting it to mp3. I wanted to avoid this and have been working directly with the byte array stored in memory so far.

    Is there any tool that might allow me to directly convert this wav byte[] to an mp3 byte[]?

    Thanks in advance for any tips or advice!
     
  2. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,364
    Until a few years ago, the algorithms to convert WAV to MP3 were patented, so many systems including Unity did not include any code to make that conversion. Playing back those files was not as much of a problem.

    You will need a library that implements that conversion. Even with today's computers, MP3 is not an ideal real-time compression format. There are other formats out there, which can be run on lightweight computers like phones in real-time. None that I know of will be written in C#, you'll need to be able to write code that calls a native library.
     
  3. murbas98

    murbas98

    Joined:
    Dec 24, 2021
    Posts:
    2
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,954
    Last edited: Dec 5, 2022