-
Notifications
You must be signed in to change notification settings - Fork 0
/
phoneme_audio.py
172 lines (155 loc) · 5.09 KB
/
phoneme_audio.py
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import os
import ui
import sound
# Define the button click event handler functions
def phoneme_tapped(sender):
sound.stop_all_effects() # Stop all currently playing sound effects
sound_name = os.path.join("audio", sender.name + "_isolation.mp3")
sound.play_effect(sound_name)
def word_tapped(sender):
sound.stop_all_effects() # Stop all currently playing sound effects
sound_name = os.path.join("audio", sender.name + "_words.mp3")
sound.play_effect(sound_name)
# Create the main view
scroll_view = ui.ScrollView()
scroll_view.background_color = "white"
scroll_view.flex = "WH"
scroll_view.content_size = (
ui.get_screen_size().width,
900,
) # Assuming content height is 900, adjust as needed
content_view = ui.View(
frame=(0, 0, scroll_view.content_size[0], scroll_view.content_size[1])
)
scroll_view.add_subview(content_view)
# Add the title label
title_label = ui.Label(frame=(0, 0, content_view.width, 40))
title_label.text = "Sounds"
title_label.font = ("<system-bold>", 24)
title_label.alignment = ui.ALIGN_CENTER
content_view.add_subview(title_label)
subtitle_label = ui.Label(frame=(0, 40, content_view.width, 30))
subtitle_label.text = "British English"
subtitle_label.font = ("<system>", 18)
subtitle_label.alignment = ui.ALIGN_CENTER
content_view.add_subview(subtitle_label)
instruction_label = ui.Label(frame=(0, 70, content_view.width, 30))
instruction_label.text = "Choose a sound to practise"
instruction_label.font = ("<system>", 16)
instruction_label.alignment = ui.ALIGN_CENTER
content_view.add_subview(instruction_label)
# Define the button content
sections = [
(
"Consonants",
[
("p", "pen"),
("b", "bag"),
("t", "tie"),
("d", "dog"),
("k", "key"),
("g", "girl"),
("m", "man"),
("n", "nose"),
("ŋ", "singer"),
("f", "fall"),
("v", "van"),
("θ", "thin"),
("ð", "this"),
("s", "see"),
("z", "zoo"),
("ʃ", "shoe"),
("ʒ", "genre"),
("tʃ", "chain"),
("dʒ", "jazz"),
("l", "leg"),
("r", "red"),
("h", "house"),
("x", "Hanukkah"),
("j", "yes"),
("w", "wet"),
],
),
(
"Vowels",
[
("iː", "eat"),
("i", "anyway"),
("ɪ", "if"),
("e", "egg"),
("æ", "add"),
("ə", "about"),
("ɜː", "earth"),
("ʌ", "up"),
("uː", "ooze"),
("u", "actual"),
("ʊ", "oops"),
("ɔː", "order"),
("ɒ", "on"),
("ɑː", "arm"),
],
),
(
"Diphthongs",
[
("eɪ", "eight"),
("əʊ", "open"),
("aɪ", "ice"),
("aʊ", "out"),
("ɔɪ", "oil"),
("ɪə", "ear"),
("eə", "airport"),
("ʊə", "tourist"),
],
),
]
# Add the buttons
y_offset = 110
for section_title, buttons in sections:
section_label = ui.Label(frame=(0, y_offset, content_view.width, 30))
section_label.text = section_title
section_label.font = ("<system-bold>", 20)
section_label.alignment = ui.ALIGN_CENTER
content_view.add_subview(section_label)
y_offset += 40
for i, (symbol, word) in enumerate(buttons):
# Create a container view for the phoneme and word buttons
container_view = ui.View(
frame=(10 + (i % 6) * 60, y_offset + (i // 6) * 60, 50, 50)
)
container_view.border_width = 1
container_view.corner_radius = 10
# Create the phoneme button
phoneme_button = ui.Button(name=symbol)
phoneme_button.frame = (0, 0, container_view.width, container_view.height / 2)
phoneme_button.background_color = "white"
phoneme_button.tint_color = "black"
phoneme_button.border_color = "white"
phoneme_button.border_width = 1
phoneme_button.corner_radius = 5
phoneme_button.title = symbol
phoneme_button.font = ("<system-bold>", 16) # 设置音标按钮的字体为粗体
phoneme_button.action = (
phoneme_tapped # Bind the phoneme event handler function
)
container_view.add_subview(phoneme_button)
# Create the word button
word_button = ui.Button(name=symbol)
word_button.frame = (
0,
container_view.height / 2,
container_view.width,
container_view.height / 2,
)
word_button.background_color = "white"
word_button.tint_color = "black"
word_button.border_color = "white"
word_button.border_width = 1
word_button.corner_radius = 5
word_button.title = word
word_button.action = word_tapped # Bind the word event handler function
container_view.add_subview(word_button)
content_view.add_subview(container_view)
y_offset += (len(buttons) // 6 + 1) * 60
# Show the view
scroll_view.present("fullscreen")