title: Python: Playing wav in memory using winsound - SND_MEMORY
body: <p>I'm trying to play a wav file from memory rather than a file. This is what I've tried but it doesn't work.</p>
  
  <pre><code>&gt;&gt;&gt; with open('my/file/dir/sound.wav','rb') as f:
  &gt;&gt;&gt;     data = f.read()
  &gt;&gt;&gt; data = base64.b64encode(data)
  &gt;&gt;&gt; data = data.decode('UTF-8')
  </code></pre>
  
  <p>So now data is a string object that represent bytes of an audio wav file.</p>
  
  <pre><code>&gt;&gt;&gt; winsound.PlaySound(data,winsound.SND_MEMORY)
  Traceback (most recent call last):
    File "&lt;string&gt;", line 301, in runcode
    File "&lt;interactive input&gt;", line 1, in &lt;module&gt;
  RuntimeError: Failed to play sound
  </code></pre>
  
  <p>Please help. Where am I going wrong?</p>
  
  <p><strong>Edit:</strong> Nevermind. <a href="https://www.reddit.com/r/learnpython/comments/3ggd9y/playing_a_wav_file_stored_in_memory_using_winsound/ctxywpr" rel="nofollow">It's a bug.</a></p>