added audio recording snippet

master
Malar Kannan 2017-10-24 11:54:15 +05:30
parent 8be8fa2595
commit 47991cb7ab
1 changed files with 22 additions and 0 deletions

22
record_mic_speech.py Normal file
View File

@ -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()