old_contents: #!/usr/bin/python
  
  import pyaudio
  import wave
  import audioop
  
  FORMAT = pyaudio.paInt16
  CHANNELS = 2
  RATE = 44100
  CHUNK = 1024
  RECORD_SECONDS = 5
  WAVE_OUTPUT_FILENAME = "audio.wav"
  
  audio = pyaudio.PyAudio()
  
  # Start Recording
  stream = audio.open(format=FORMAT, channels=CHANNELS,
  		rate=RATE,
  		input=True,
  		frames_per_buffer=CHUNK)
  
  print "Recording..."
  
  frames = []
  threshold = 1000
  for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
  	data = stream.read(CHUNK)
  	rms = audioop.rms(data,2)
  	if rms > threshold:
  		print "I am hearing you now"
  		frames.append(data)
  
  print "Finished recording"
  
  # Stop Recording
  stream.stop_stream()
  stream.close()
  audio.terminate()
  
  waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
  waveFile.setnchannels(CHANNELS)
  waveFile.setsampwidth(audio.get_sample_size(FORMAT))
  waveFile.setframerate(RATE)
  waveFile.writeframes(b''.join(frames))
  waveFile.close()
  
new_contents: #!/usr/bin/python
  
  import pyaudio
  import wave
  import audioop
  
  FORMAT = pyaudio.paInt16
  CHANNELS = 2
  RATE = 44100
  CHUNK = 1024
  RECORD_SECONDS = 5
  WAVE_OUTPUT_FILENAME = "audio.wav"
  
  audio = pyaudio.PyAudio()
  
  # Start Recording
  stream = audio.open(format=FORMAT, channels=CHANNELS,
  		rate=RATE,
  		input=True,
  		frames_per_buffer=CHUNK)
  
  print "Recording..."
  
  frames = []
  threshold = 1000
  for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
  	data = stream.read(CHUNK)
  	rms = audioop.rms(data,2)
  	if rms > threshold:
  		print "I am hearing you now"
  		frames.append(data)
  
  print "Finished recording"
  
  # Stop Recording
  stream.stop_stream()
  stream.close()
  audio.terminate()
  
  waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
  waveFile.setnchannels(CHANNELS)
  waveFile.setsampwidth(audio.get_sample_size(FORMAT))
  waveFile.setframerate(RATE)
  waveFile.writeframes(b''.join(frames))
  waveFile.close()
  
  player = subprocess.Popen(["aplay", WAVE_OUTPUT_FILENAME])
  
subject: Create pyaudiorecordrms.py