-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlay_Tone_GUI.py
More file actions
executable file
·122 lines (102 loc) · 3.08 KB
/
Play_Tone_GUI.py
File metadata and controls
executable file
·122 lines (102 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import math
import pyaudio
import sys
from Tkinter import *
PyAudio = pyaudio.PyAudio
rate = 128000 # 16 kbps
def gen_tone(freq):
data = ''.join([chr(int(math.sin(x/((rate/freq)/math.pi))*127+128)) for x in xrange(rate)])
p = PyAudio()
stream = p.open(format =
p.get_format_from_width(1),
channels = 1,
rate = rate,
output = True)
for DISCARD in xrange(1):
stream.write(data)
stream.stop_stream()
stream.close()
p.terminate()
class App:
def __init__(self,parent):
frame = Frame(parent)
frame.pack()
self.button = Button(
frame, text="QUIT", fg="blue",bg="red", command=frame.quit
)
self.button.pack(side=LEFT)
self.tone1 = Button(
frame, text="Play A", command=self.gentone1
)
self.tone1.pack(side=LEFT)
self.tone2 = Button(
frame, text="Play Bb", command=self.gentone2
)
self.tone2.pack(side=LEFT)
self.tone3 = Button(
frame, text="Play B", command=self.gentone3
)
self.tone3.pack(side=LEFT)
self.tone4 = Button(
frame, text="Play C", command=self.gentone4
)
self.tone4.pack(side=LEFT)
self.tone5 = Button(
frame, text="Play Db", command=self.gentone5
)
self.tone5.pack(side=LEFT)
self.tone6 = Button(
frame, text="Play D", command=self.gentone6
)
self.tone6.pack(side=LEFT)
self.tone7 = Button(
frame, text="Play Eb", command=self.gentone7
)
self.tone7.pack(side=LEFT)
self.tone8 = Button(
frame, text="Play E", command=self.gentone8
)
self.tone8.pack(side=LEFT)
self.tone9 = Button(
frame, text="Play F", command=self.gentone9
)
self.tone9.pack(side=LEFT)
self.tone10 = Button(
frame, text="Play Gb", command=self.gentone10
)
self.tone10.pack(side=LEFT)
self.tone11 = Button(
frame, text="Play G", command=self.gentone11
)
self.tone11.pack(side=LEFT)
self.tone12 = Button(
frame, text="Play Ab", command=self.gentone12
)
self.tone12.pack(side=LEFT)
def gentone1(self):
gen_tone(440)
def gentone2(self):
gen_tone(466.16)
def gentone3(self):
gen_tone(493.88)
def gentone4(self):
gen_tone(523.25)
def gentone5(self):
gen_tone(554.37)
def gentone6(self):
gen_tone(587.33)
def gentone7(self):
gen_tone(622.25)
def gentone8(self):
gen_tone(659.26)
def gentone9(self):
gen_tone(698.46)
def gentone10(self):
gen_tone(739.99)
def gentone11(self):
gen_tone(783.99)
def gentone12(self):
gen_tone(830.61)
root = Tk()
app = App(root)
root.mainloop()