-
Notifications
You must be signed in to change notification settings - Fork 2
/
matplotlib_example2.py
executable file
·61 lines (47 loc) · 1.48 KB
/
matplotlib_example2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from matplotlib_example import *
from scipy.fftpack import fft
#Record a sound and plots the amplitude and spectrogram
SOUND=None
def play_audio(**kwargs):
if SOUND:
SOUND.play()
return
def record_audio(view1,view2,*args,**kwargs):
global SOUND
snd_array=record_array(2.)
SOUND=pg.sndarray.make_sound(snd_array)
fig1 = pylab.figure(figsize=[4, 2], # Inches
dpi=100, # 100 dots per inch, so the resulting buffer is 400x400 pixels
)
ax = fig1.gca()
ax.plot(snd_array)
make_fig(fig1,view1)
fig2 = pylab.figure(figsize=[4, 2], # Inches
dpi=100, # 100 dots per inch, so the resulting buffer is 400x400 pixels
)
spectrogram(fig2,snd_array[:,0])
make_fig(fig2,view2)
def uinit(screen):
ui=UI(screen)
#Display element for the plot
view1= ui.add('view',pos=(200,0),size=(400,200))
view2= ui.add('view',pos=(200,200),size=(400,200))
#Play button
playbutton=ui.add('button',pos=(10,10),text='Play')
playbutton.bind(play_audio)
#Record button
recordbutton=ui.add('button',pos=(60,10),text='Record')
recordbutton.bind(record_audio,view1,view2)
return ui
def main():
pg.init()
screen = pg.display.set_mode((600, 400), pg.DOUBLEBUF)
ui=uinit(screen)
alive=True
while alive:
draw(ui)
alive=logic(ui)
pg.display.quit()
pg.quit()
if __name__ in '__main__':
main()