How to Read Realtime Microphone Audio Volume in Python and Ffmpeg or Similar

How to read realtime microphone audio volume in python and ffmpeg or similar

Thanks to @Matthias for the suggestion to use the sounddevice module. It's exactly what I need.

For posterity, here is a working example that prints real-time audio levels to the shell:

# Print out realtime audio volume as ascii bars

import sounddevice as sd
import numpy as np

def print_sound(indata, outdata, frames, time, status):
volume_norm = np.linalg.norm(indata)*10
print ("|" * int(volume_norm))

with sd.Stream(callback=print_sound):
sd.sleep(10000)

Sample Image

How to read realtime microphone audio volume in python and ffmpeg or similar

Thanks to @Matthias for the suggestion to use the sounddevice module. It's exactly what I need.

For posterity, here is a working example that prints real-time audio levels to the shell:

# Print out realtime audio volume as ascii bars

import sounddevice as sd
import numpy as np

def print_sound(indata, outdata, frames, time, status):
volume_norm = np.linalg.norm(indata)*10
print ("|" * int(volume_norm))

with sd.Stream(callback=print_sound):
sd.sleep(10000)

Sample Image

how to read from microphone using C

Read the developer documentation for your operating system. It is impossible to answer in general because the audio APIs are so different on each platform (DirectSound, ASIO, CoreAudio, ALSA, OSS, Jack, ...)



Related Topics



Leave a reply



Submit