title: How to write Javascript audio blob to Python wave?
body: <p>I'm trying to create a Flask endpoint that accepts an audio blob every n seconds and write it to a wave file:</p>
  <p><strong>Flask:</strong></p>
  <pre><code>@app.route('/api/v01/post/audio-blob/', methods=['POST'])
  def api_post_audio_blob():
      blob = request.data
      with open('file.wav', 'ab') as f:
          f.write(blob)
      return Response(status=200)
  </code></pre>
  <p><strong>Javascript:</strong></p>
  <pre><code>const startButton = document.getElementById(&quot;start&quot;);
  startButton.addEventListener(&quot;click&quot;, function() {
  
      /* Get client-side audio stream */
      var constraints = { audio: true }
      var chunks = []
      navigator.mediaDevices.getUserMedia(constraints)
      .then(function(stream) {
          const recorder = new MediaRecorder(stream);
          recorder.ondataavailable = event =&gt; {
              chunks.push(event.data);
              var blob = new Blob(chunks, {
                  type: &quot;audio/wav&quot;
              });
              var xmlhttp = new XMLHttpRequest();
              var url = &quot;http://127.0.0.1:5000/api/v01/post/audio-blob/&quot;;
              xmlhttp.open(&quot;POST&quot;, url, true);
              xmlhttp.setRequestHeader(&quot;Content-type&quot;, &quot;audio/wav&quot;);
              xmlhttp.send(blob);
          };
          recorder.start(10000);
      })
      .catch(function(err) {
          /* handle the error */
      });
  </code></pre>
  <p>It seems like binary is written to file.wav, but it doesn't play any sound. Anyone knows how to resolve this? Help would be much appreciated!</p>