title: How to write pyaudio output into audio file?
body: <p>I currently have the following code, which produces a sine wave of varying frequencies using the <code>pyaudio</code> module:</p>
  
  <pre><code>import pyaudio
  import numpy as np
  
  p = pyaudio.PyAudio()
  
  volume = 0.5
  fs = 44100
  duration = 1
  
  f = 440
  
  samples = (np.sin(2 * np.pi * np.arange(fs * duration) * f / 
  fs)).astype(np.float32).tobytes()
  
  stream = p.open(format = pyaudio.paFloat32,
                  channels = 1,
                  rate = fs,
                  output = True)
  
  stream.write(samples)
  </code></pre>
  
  <p>However, instead of playing the sound, is there any way to make it so that the sound is written into an audio file?</p>