title: Playing sounds from buffer in pygame
body: <p>I am trying to play sound from buffer in pygame. I am using Python 3. 
  I got uncompressed wav file, sound.wav. </p>
  
  <p>I can play it like this and it works fine:</p>
  
  <pre><code>sound = pygame.mixer.Sound(file='/path/to/file/sound.wav')
  sound.play()
  </code></pre>
  
  <p>According to <a href="https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound" rel="nofollow">pygame documentation</a> buffer can be Python 3 bytes object, but if I try:</p>
  
  <pre><code>f = open('/path/to/file/sound.wav', 'rb')
  data = f.read()
  sound = pygame.mixer.Sound(buffer=data)
  sound.play()
  </code></pre>
  
  <p>This code can be run, but sound is deformed.</p>
  
  <p>So, how to use buffer? Documentation is really spare and I couldn't find any examples. I can't play sounds from hard disk because I have many raw audio chunks, which I convert to wav, but saving them on hard disk (and then reading them) is way to slow and inefficient (since I already have them in memory). Thank you for your help.</p>
  
  <p>EDIT:
  I forgot to mention that I also tried to play raw audio without header. Fortunately thanks to <a href="https://stackoverflow.com/users/501814/andris">@Andris</a> comment I figure out what pygame means by buffer. I init mixer with <code>pygame.mixer.init(frequency=22050, size=8, channels=1)</code> so I thought that buffer should be in this format. I dumped on disk what was returned by <code>pygame.mixer.Sound(file='/path/to/file/sound.wav').get_raw()</code> and after examination I can say it's raw audio, but with frequency=44100, size=-16.</p>