如何使用Python的条形图进行实时声音净空?
我正在尝试使用条形图和Pyaudio进行简单的声音空间。经过几次尝试后,我意识到问题与While循环有关。这让我想到..如何从循环中获取价值?主要问题是条形图重叠,使代码通过时间较慢。有可能这样做吗?
并且想要类似的东西:
主要思想是将此图表带入级别。
这是代码:
import numpy as np
import pyaudio as pa
import struct
import matplotlib.pyplot as plt
fps = 516
CHUNK = fps * 2
FORMAT = pa.paInt16
CHANNELS = 1
RATE = 44100
p = pa.PyAudio()
stream = p.open(
format = FORMAT,
channels = CHANNELS,
rate = RATE,
input=True,
output=True,
frames_per_buffer=CHUNK
)
fig, ax = plt.subplots(1)
ax.set_ylim(-80,40)
fig.show()
while True:
data = stream.read(CHUNK)
dataInt = np.array(struct.unpack(str(CHUNK) + 'h', data))
datadBFs = 20*np.log10(np.abs(np.sum(dataInt)/len(dataInt))/32768)
ax.bar("bar1", datadBFs, align='center', alpha=0.5)
fig.canvas.draw()
fig.canvas.flush_events()
有什么想法吗? 非常感谢,我希望有人可以帮助我!
I am trying to do a simple sound headroom using a bar chart and Pyaudio. After several attemps I realize that the problem is related with the while loop. This makes me think.. how to get a value from the loop? The main problem is that the bar chart overlaps making the code slower throuh the time. Is it possible to do it like this?
This is the image of the chart now:
and want something similar to this:
The principal idea is to have this chart in movement with the levels.
And this is the code:
import numpy as np
import pyaudio as pa
import struct
import matplotlib.pyplot as plt
fps = 516
CHUNK = fps * 2
FORMAT = pa.paInt16
CHANNELS = 1
RATE = 44100
p = pa.PyAudio()
stream = p.open(
format = FORMAT,
channels = CHANNELS,
rate = RATE,
input=True,
output=True,
frames_per_buffer=CHUNK
)
fig, ax = plt.subplots(1)
ax.set_ylim(-80,40)
fig.show()
while True:
data = stream.read(CHUNK)
dataInt = np.array(struct.unpack(str(CHUNK) + 'h', data))
datadBFs = 20*np.log10(np.abs(np.sum(dataInt)/len(dataInt))/32768)
ax.bar("bar1", datadBFs, align='center', alpha=0.5)
fig.canvas.draw()
fig.canvas.flush_events()
Any Idea?
Thanks a lot and I hope someone could help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论