audio.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:zignal 作者: ronnyandersson 项目源码 文件源码
def rms(self):
        """Calculate the RMS (Root Mean Square) value of the audio
        data. Returns the RMS value for each individual channel
        """
        if not (self.samples == 0).all():
            if np.issubdtype(self.samples.dtype, float):
                rms = np.sqrt(np.mean(np.power(self.samples, 2), axis=0))
            else:
                # use a bigger datatype for ints since we most likely will
                # overflow when calculating to the power of 2
                bigger  = np.asarray(self.samples, dtype=np.int64)
                rms     = np.sqrt(np.mean(np.power(bigger, 2), axis=0))

        elif len(self.samples) == 0:
            # no samples are set but channels are configured
            rms = np.zeros(self.ch)
            rms[:] = float('nan')
        else:
            rms = np.zeros(self.ch)
        return rms
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号