Created
October 11, 2023 09:27
-
-
Save kylemcdonald/bf27d7b231748c2a478561560154715d to your computer and use it in GitHub Desktop.
Show microphone level in realtime using pyaudio.
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 audioop | |
p = pyaudio.PyAudio() | |
stream = p.open(format=pyaudio.paInt16, | |
channels=1, | |
rate=44100, | |
input=True, | |
frames_per_buffer=1024) | |
try: | |
while True: | |
data = stream.read(1024) | |
rms = audioop.rms(data, 2) | |
max_n = 100 | |
n = min(int(rms//2), max_n) | |
blank = max_n - n | |
print(f"RMS: {n *'█'}{blank*' '}", end='\r') | |
except KeyboardInterrupt: | |
stream.stop_stream() | |
stream.close() | |
p.terminate() | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment