python - 使用 pyaudio 和 matplotlib 实时创建波形
问题描述
我正在寻找音频输入(麦克风)的实时图表,并使用 matplotlib 在波形图中显示此数据。如何显示 Y 轴上的数据和 X 轴上的时间(秒)?
我对音频处理一无所知,所以我从文档和示例中学到了很多东西,但我仍然不知道如何让图形实时反应。
from scipy.io import wavfile
from matplotlib import pyplot as plt
import numpy as np
# Load the data and calculate the time of each sample
samplerate, data = wavfile.read('audio.wav')
print(samplerate, data)
times = np.arange(len(data))/float(samplerate)
# Make the plot
# You can tweak the figsize (width, height) in inches
plt.figure(figsize=(30, 4))
print(data[:,0])
plt.fill_between(times, data[:,0], data[:,1], color='k')
plt.xlim(times[0], times[-1])
plt.xlabel('time (s)')
plt.ylabel('amplitude')
# You can set the format by changing the extension
# like .pdf, .svg, .eps
plt.savefig('plot.png', dpi=100)
plt.show()
我希望波形看起来像那样,但是使用我的麦克风而不是 wav 文件。我测试了其他东西,但没有那么结论......
解决方案
推荐阅读
- cookies - 是否可以使用 Set-Cookie 标头设置现有 cookie 的 Expires/Max-Age?
- mongodb - MongoDB 如果其他集合中存在字段/引用,则从聚合中排除文档
- django - django tables2 创建带有超链接的额外列
- wordpress - 我如何获得孩子页面木材/树枝 WordPress 的孩子
- javascript - 为什么我的 api 发布请求(Vue.js 客户端)从我的快递服务器收到未定义的响应?
- java - 是否有可能在项目反应堆中拥有一个为多个订阅者提供独立背压支持的热发布者?
- mysql - 没有在数据库中显示结果
- sql - SQL 删除 NULL 并重新组合
- javascript - 了解 Alexa Skill 中的 HTTP 函数——JavaScript
- php - Laravel 7.6 调用未定义的方法 Illuminate\Database\Eloquent\Builder::appends()