24 lines
587 B
Python
24 lines
587 B
Python
|
import scipy.signal as signal
|
||
|
import pyaudio
|
||
|
from matplotlib import pyplot as plt
|
||
|
import numpy as np
|
||
|
from time import sleep
|
||
|
|
||
|
SAMPLE_SIZE = 1024
|
||
|
|
||
|
audio = pyaudio.PyAudio()
|
||
|
audioStream = audio.open(format=pyaudio.paInt16, channels=1, rate=1000, input=True, frames_per_buffer=SAMPLE_SIZE)
|
||
|
|
||
|
while True:
|
||
|
data = audioStream.read(SAMPLE_SIZE)
|
||
|
sample = np.frombuffer(data, dtype=np.int16)
|
||
|
|
||
|
# plot data
|
||
|
plt.plot(sample)
|
||
|
plt.show()
|
||
|
freqdom_signal = signal.stft(sample)
|
||
|
print(freqdom_signal)
|
||
|
# close stream
|
||
|
audioStream.stop_stream()
|
||
|
audioStream.close()
|
||
|
audio.terminate()
|