title: Record Video with Audio in Raspberry Pi using USB Cam
body: <p>How to record video with audio in Raspberry Pi using USB Cam that has built-in microphone.
  I was able to do it separately, but I need to do them together.<br>
  I need a python code. This the code that I use it to record the video only:</p>
  
  <pre><code>def video_capture():
      global RS
      print 'try recording'
      global end_time
      fourcc = cv2.cv.CV_FOURCC(*'XVID')
  
      if end_time is None:
                      end_time = time.time()
      while True:
          while RS == 1:
              while time.time() - end_time &gt;= 1:
                  end_rec = time.time() + 20
                  print 'writing video'
                  t_start = time.time()
                  while t_start &lt; end_rec:
                      date_string = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
                      out = cv2.VideoWriter(str(date_string)+'.avi',fourcc, 13, (640,480))
                      while (camera.isOpened()) &amp; (time.time() &lt; end_rec):
                          ret, frame3 = camera.read()
                          if ret==True:
                              out.write(frame3)
                      end_time = time.time()
                      break
                  print 'The End'
  </code></pre>