Last active
September 15, 2023 14:56
-
-
Save damp11113/f68d2f889b4c0affe9abcea7b04f89ad to your computer and use it in GitHub Desktop.
python audio vu meter L R
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 numpy as np | |
import time | |
CHUNK = 2**11 | |
p = pyaudio.PyAudio() | |
stream = p.open(format=pyaudio.paInt16, channels=2, rate=44100, input=True, input_device_index=5, frames_per_buffer=CHUNK) | |
while True: | |
data = np.fromstring(stream.read(CHUNK), dtype=np.int16) | |
L = np.average(np.abs(data[0::2])) * 5 | |
R = np.average(np.abs(data[1::2])) * 5 | |
LB = "|" * int(50 * L / 2 ** 16) | |
RB = "|" * int(50 * R / 2 ** 16) | |
print(f'L {LB}') | |
print(f'R {RB}') | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment