简体   繁体   English

如何获得 Python 中的声级?

[英]How do I get the sound level in Python?

For a project I am doing I need to get the live decibel level of my mic.对于我正在做的一个项目,我需要获得麦克风的实时分贝水平。

I have seen the plotters:我见过绘图仪:

# 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)

But i just need the volume as an integer, how do I do that?但我只需要 integer 的音量,我该怎么做?

Just print the number instead of bars:只需打印数字而不是条形:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM