1#! /usr/bin/env python 2 3from Tkinter import * 4from tkSnack import * 5 6root = Tkinter.Tk() 7 8initializeSnack(root) 9 10s1 = Sound(load='ex1.wav') 11s2 = Sound() 12 13Frame(root).pack(pady=5) 14Label(root, text='Snack Sound Toolkit Demonstration', 15 font='Helvetica 14 bold').pack() 16 17def load(): 18 file = root.tk.call('eval', 'snack::getOpenFile') 19 s2.read(file) 20 21def save(): 22 file = root.tk.call('eval', 'snack::getSaveFile') 23 s2.write(file) 24 25def play(): 26 s2.play() 27 28def pause(): 29 s2.pause() 30 31def stop(): 32 s2.stop() 33 root.after_cancel(id) 34 35def timer(): 36 len = s2.length(units='seconds') 37 timelab.configure(text=len) 38 root.after(100,timer) 39 40def record(): 41 s2.record() 42 id=root.after(100,timer) 43 44f0 = Frame(root) 45f0.pack(pady=5) 46Label(f0, text='Basic sound handling:').pack(anchor='w') 47timelab = Label(f0, text='0.00 sec',width=10) 48timelab.pack(side='left') 49Button(f0, bitmap='snackPlay', command=play).pack(side='left') 50Button(f0, bitmap='snackPause', command=pause).pack(side='left') 51Button(f0, bitmap='snackStop', command=stop).pack(side='left') 52Button(f0, bitmap='snackRecord', fg='red', command=record).pack(side='left') 53Button(f0, image='snackOpen', command=load).pack(side='left') 54Button(f0, image='snackSave', command=save).pack(side='left') 55 56colors = '#000 #006 #00B #00F #03F #07F #0BF #0FF #0FB #0F7\ 57 #0F0 #3F0 #7F0 #BF0 #FF0 #FB0 #F70 #F30 #F00' 58 59 60c = SnackCanvas(width=680, height=140, highlightthickness=0) 61c.pack(pady=5) 62 63c.create_text(0, 0, text='Waveform canvas item type:',anchor='nw') 64c.create_waveform(0, 20, sound=s1, height=120, width=250 ,frame='yes') 65c.create_text(250, 0, text='Spectrogram canvas item type:',anchor='nw') 66c.create_spectrogram(250, 20, sound=s1, height=120, width=250, colormap=colors) 67c.create_text(480, 0, text='Spectrum section canvas item type:',anchor='nw') 68c.create_section(500, 20, sound=s1, height=120, width=180 ,frame='yes', 69 start=8000, end=10000, minval=-100) 70 71root.mainloop() 72