Skip to content

Instantly share code, notes, and snippets.

@batok
Created May 21, 2010 13:56
Show Gist options
  • Save batok/408865 to your computer and use it in GitHub Desktop.
Save batok/408865 to your computer and use it in GitHub Desktop.
def RecordAudio(self, seconds):
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = seconds
WAVE_FILENAME = "output.wav"
p = pyaudio.PyAudio()
stream = p.open(format = FORMAT,
channels = CHANNELS,
rate = RATE,
input = True,
frames_per_buffer = chunk)
rec = []
dlg = wx.ProgressDialog("Recording Audio",
"Recording audio from sc2s3",
maximum = RECORD_SECONDS,
parent=self,
style = wx.PD_CAN_ABORT
| wx.PD_APP_MODAL
| wx.PD_ELAPSED_TIME
#| wx.PD_ESTIMATED_TIME
| wx.PD_REMAINING_TIME
)
for i in range(0, RATE / chunk * RECORD_SECONDS):
data = stream.read(chunk)
rec.append(data)
dlg.Destroy()
stream.close()
p.terminate()
sdata = ''.join(rec)
f = wave.open(WAVE_FILENAME, 'wb')
f.setnchannels(CHANNELS)
f.setsampwidth(p.get_sample_size(FORMAT))
f.setframerate(RATE)
f.writeframes(sdata)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment