【问题标题】:tksnack- Trying to create waveformtksnack-尝试创建波形
【发布时间】:2014-01-08 07:53:32
【问题描述】:

我正在尝试使用 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() 但这没有用。

【问题讨论】:

    标签: python audio tkinter waveform


    【解决方案1】:

    您还可以使用包snagogg...tksnack 在Linux 中与libsnack-alsa 一起工作。我不知道snagogg。

    此处以录制曲目为例 - 我将按钮放在您的来源。

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

    【讨论】:

      猜你喜欢
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多