tksnack正在尝试创建波形

2024-09-27 22:09:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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。我该怎么做呢?我试着替代阅读(文件)用于记录()但那没用。在


Tags: 代码fromimport声音示例bintkinterusr
1条回答
网友
1楼 · 发布于 2024-09-27 22:09:36

您也可以使用snackogg包…tksnack在Linux中与libsnack alsa fine一起工作。我不知道吃零食。在

在这里的例子中,录制一首曲目-我把按钮放在你的源上。在

#! /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()

相关问题 更多 >

    热门问题