我有以下代码创建音频文件的波形:
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数组任何想法???