The default GUI kit that comes with Python, Let's draw the wav waveform by force using tkInter's canvas.
There are no additional plugins required. All you have to do is prepare Python and the sound source you want to play.
python
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
import Tkinter
import wave
import numpy as np
window_width = 600
window_height = 500
root = Tkinter.Tk()
root.title(u"Software Title")
root.geometry(str(window_width) + "x" + str(window_height))
#Read wav data
wav = wave.open("./test.wav")
#Move to the beginning of the audio part
wav.rewind()
#Binary reading
wavdata = wav.readframes(wav.getnframes())
#Convert to int
wavdata = np.frombuffer(wavdata,'int16')
#
#Canvas area
#
canvas = Tkinter.Canvas(root, width = window_width, height = window_height)
#Number of X-axis steps
step = float(window_width)/float(wav.getnframes())
x = 0 #X axis
b_i = 0 #Previous value
for c,i in enumerate(wavdata):
#Keep the previous coordinates
if (c%2 == 0):
b_i = i
x = x + step
continue
#Create a waveform graph using the previous coordinates and the current coordinates
canvas.create_line(int(x), (b_i/window_height)+(window_height/2), int(x+step), (i/window_height)+(window_height/2), fill = "blue")
#Advance the X coordinate by step
x = x + step
print "(x,y) = ("+ str(x) +","+ str(i) +")"
#center lane
canvas.create_line(0, window_height/2, window_width, window_height/2, fill = "black")
#
#Canvas bind
#
canvas.place(x=0,y=0)
#
#close wav
#
wav.close()
root.mainloop()
Although it is rough, it is output like this.
Recommended Posts