title: Fast way to compress audio data?
body: <p>I'm trying to build (Inspirated by teamspeak) a voip program that comunicate via UDP.</p>
  
  <p>Here is my source (Server):</p>
  
  <pre><code>import pyaudio
  import socket
  
  CHUNK = 1024
  FORMAT = pyaudio.paInt16
  CHANNELS = 1
  RATE = 44100
  
  p = pyaudio.PyAudio()
  
  stream = p.open(format=FORMAT,
                  channels = CHANNELS,
                  rate = RATE,
                  output = True,
                  frames_per_buffer = CHUNK,
                  )
  
  udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  udp.bind(("0.0.0.0", 4444))
  
  while True:
      soundData, addr = udp.recvfrom(CHUNK * CHANNELS * 2)
      stream.write(soundData, CHUNK)
      print len(soundData)
  
  udp.close()
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>import pyaudio
  import socket
  
  
  CHUNK = 1024
  FORMAT = pyaudio.paInt16
  CHANNELS = 1
  RATE = 44100
  
  p = pyaudio.PyAudio()
  
  stream = p.open(format = FORMAT,
                  channels = CHANNELS,
                  rate = RATE,
                  input = True,
                  frames_per_buffer = CHUNK,
                  )
  
  udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  
  while True:
      udp.sendto(stream.read(CHUNK), ("127.0.0.1", 4444))
  
  udp.close()
  </code></pre>
  
  <p>It works great on LAN, but in WAN the audio is very bad.</p>
  
  <p>I assumed that raw audio is not good for voip, and I'm looking for a way to compress the audio using a lossy algorithm or an encoder (mp3, AAC, ogg)</p>
  
  <p>I tried LZMA, but I don't need lossless compression, lossy is better in my case.</p>
  
  <p>I have two rules to follow:</p>
  
  <ol>
  <li><p>The program must be cross platform, so I need a way to compress/decompress in a "cross platform" way (Inside python)</p></li>
  <li><p>Audio quality should be good (not below 50% of original)</p></li>
  </ol>