From 47991cb7ab7eca8b07b14b3bcdbfdedb3120d044 Mon Sep 17 00:00:00 2001 From: Malar Kannan Date: Tue, 24 Oct 2017 11:54:15 +0530 Subject: [PATCH] added audio recording snippet --- record_mic_speech.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 record_mic_speech.py diff --git a/record_mic_speech.py b/record_mic_speech.py new file mode 100644 index 0000000..fb2b63e --- /dev/null +++ b/record_mic_speech.py @@ -0,0 +1,22 @@ +import pyaudio +import numpy as np +from matplotlib import pyplot as plt + +CHUNKSIZE = 1024 # fixed chunk size + +# initialize portaudio +p = pyaudio.PyAudio() +stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=CHUNKSIZE) + +# do this as long as you want fresh samples +data = stream.read(CHUNKSIZE) +numpydata = np.fromstring(data, dtype=np.int16) + +# plot data +plt.plot(numpydata) +plt.show() + +# close stream +stream.stop_stream() +stream.close() +p.terminate()