小编Net*_*min的帖子

Python-获取mp3的波形/幅度

我希望我能找到一种方法从 python 中的 mp3 获取幅度数据。与 audacity 类似,但我不需要视觉效果,一个简单的值数组就可以了。我希望我的代码在声音变大时在某些点对声音做出反应。我正在使用 pygame 播放音频并尝试将其转换为 sndarray 但它只给了我前 0.00018 秒。无论如何,我可以得到整个mp3吗?它不一定是实时的,因为无论如何我都希望能够提前做出反应,并且会使用 pygame 跟踪我的位置。

我正在使用树莓派来构建这个云,而不是其他功能。我已经完成了照明工作,需要它对闪电做出反应,遗憾的是 lightshowpi 不是一个选择。任何帮助将不胜感激

编辑:这就是我到目前为止所拥有的,感谢 coder-don。它有效,但我挂在 while 循环上。我不知道为什么。我使用的 mp3 相当长,这可能是问题所在吗?

import os, sys
from gi.repository import Gst, GObject
Gst.init()
GObject.threads_init()

def get_peaks(filename):
global do_run

pipeline_txt = (
    'filesrc location="%s" ! decodebin ! audioconvert ! '
    'audio/x-raw,channels=1,rate=22050,endianness=1234,'
    'width=32,depth=32,signed=(bool)TRUE !'
    'level name=level interval=1000000000 !'
    'fakesink' % filename)
pipeline = Gst.parse_launch(pipeline_txt)

level = pipeline.get_by_name('level')
bus = pipeline.get_bus()
bus.add_signal_watch()

peaks = []
do_run = True

def show_peak(bus, message): …
Run Code Online (Sandbox Code Playgroud)

python audio mp3

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

audio ×1

mp3 ×1

python ×1