python-telemetrix-ambilight/beat_detection.py

24 lines
587 B
Python
Raw Normal View History

2022-03-29 18:34:26 +00:00
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()