【发布时间】:2017-05-08 01:41:47
【问题描述】:
我有以下代码可以创建音频文件的波形:
times = np.arange(len(data))/float(samplerate)
fig = plot.figure(figsize = (8,4), frameon = False)
axes = fig.gca()
if(channels == 1): #mono file
axes.fill_between(times, data, color = 'k')
else: #stereo file
axes.fill_between(times, data[:,0], data[:,1], color = 'k')
plot.savefig(savefile, dpi = 'figure', transparent = True)
我尝试了多种方法来从该图中提取 RGBA 数组,但都没有成功。我当前的代码如下:
canvas.draw() # draw the canvas, cache the renderer
width, height = fig.get_size_inches() * fig.get_dpi()
waveformRGBA= np.fromstring(canvas.tostring_rgb(),dtype='uint8').reshape(height, width, 3)
print waveformRGBA
此方法生成 [255,255,255] 的空白 RGBA 数组
有什么想法吗???
【问题讨论】:
-
您的“当前代码”未显示
canvas的创建方式。了解这可能会有所帮助。 -
我看到您使用的命令几乎(但不完全)与上面链接的问题的答案相同。该答案中的示例对您也不起作用吗?否则尝试修复差异。
标签: python numpy matplotlib plot waveform