2014-01-08 76 views
1

我正在尝试使用tksnack创建一个实时移动到正在播放的声音的波形。我发现了一些或多或少做我想要的示例代码。tksnack-试图创建波形

#! /usr/bin/env python 

from Tkinter import * 
from tkSnack import * 

root = Tkinter.Tk() 
initializeSnack(root) 
snd = Sound() 
def start(): 
    snd.record() 

c = SnackCanvas(height=500, width=1920, bg='white') 
c.pack() 
c.create_waveform(1,1,sound=snd,width=1920,height=500,pixelspersec=500) 

start() 
root.mainloop() 

但是这个例子需要从麦克风的音频,但我想给它一个MP3。我会如何去做这件事?我尝试使用snd.read(file)替代snd.record(),但没有奏效。

回答

2

您也可以使用包snackogg ... tksnack在Linux中使用libsnack-alsa罚款。我不知道用snackogg。

这里在记录一个轨道的例子 - 我把按钮给你的来源。

#! /usr/bin/env python 

    from Tkinter import * 
    from tkSnack import * 

    root = Tkinter.Tk() 
    root.geometry("650x560+100+80") 
    initializeSnack(root) 
    snd = Sound() 

    def start(): 
     snd.record() 

    def stop(): 
     snd.stop() 

    def play(): 
     snd.play() 

    def save(): 
     file = root.tk.call('eval', 'snack::getSaveFile') 
     snd.write(file) 


    c = SnackCanvas(height=500, width=820, bg='white') 
    c.pack() 

    c.create_waveform(1,1,sound=snd,width=1920,height=500,pixelspersec=500) 

    record=Button(root,width=50,height=50,fg='red', bitmap='snackRecord',command=start).place(x=5,y=501) 
    stop=Button(root,width=50,height=50,fg='black', bitmap='snackStop',command=stop).place(x=60,y=501) 
    play=Button(root,width=50,height=50,fg='black', bitmap='snackPlay', command=play).place(x=115,y=501) 
    save=Button(root,width=5,height=3,fg='black', text='Save', command=save).place(x=170,y=501) 
    root.mainloop()