如何在Python中获得音频的声压级(dB)?

时间:2017-04-21 17:24:26

标签: python pyaudio

我想知道如何在Python中获得以dB为单位的声压级?输入应该是来自PC麦克风的信号(实时音频信号)。输出是输入信号的实时声压级。我写了一个需要开发的简单代码。非常感谢。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 21 17:22:10 2017

@author: YuanGao
"""

import pyaudio
import numpy as np
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100

pa = pyaudio.PyAudio()
stream = pa.open(format=FORMAT,
                         channels=CHANNELS,
                         rate=RATE,
                         input=True,
                         frames_per_buffer=CHUNK)

buffer = []
while True:
    string_audio_data = stream.read(CHUNK) 
    audio_data = np.fromstring(string_audio_data, dtype=np.short)

    print(audio_data)

0 个答案:

没有答案