Created
January 25, 2016 13:28
-
-
Save tbbooher/579095ac89fa2fff58db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyaudio | |
import wave | |
CHUNK = 1024 | |
FORMAT = pyaudio.paInt16 | |
CHANNELS = 1 | |
RATE = 44100 | |
p = pyaudio.PyAudio() | |
def record(file_name): | |
stream = p.open(format = FORMAT, | |
channels = CHANNELS, | |
rate = RATE, | |
input = True, | |
frames_per_buffer = CHUNK) | |
frames = [] | |
print "starting recording " + file_name + "." | |
for i in range(0, int(RATE / CHUNK * 2)): | |
data = stream.read(CHUNK) | |
frames.append(data) | |
print "finished recording" | |
stream.stop_stream() | |
stream.close() | |
p.terminate() | |
wf = wave.open(file_name, 'wb') | |
wf.setnchannels(CHANNELS) | |
wf.setsampwidth(p.get_sample_size(FORMAT)) | |
wf.setframerate(RATE) | |
wf.writeframes(b''.join(frames)) | |
wf.close() | |
record('first.wav') | |
'''and again''' | |
record('second') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment