-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinal.py
246 lines (198 loc) · 8.48 KB
/
final.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import wx
import threading
import pytesseract
import pyttsx3
import pyautogui
import time
import sys
# Initialize text-to-speech engine
engine = pyttsx3.init()
voices = engine.getProperty("voices")
volume = 0.5 # Default volume
rate = 200 # Default speech rate (words per minute)
current_voice = voices[0] # Default voice
current_language = "eng" # Default language (English)
# Store the previous cursor position
previous_cursor_position = pyautogui.position()
# Variable to control the main loop
running = False
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(1300, 1000))
# Set the favicon (replace 'Logo.png' with the actual path)
icon = wx.Icon("Logo.png", wx.BITMAP_TYPE_PNG)
self.SetIcon(icon)
# Create a notebook for tabs
notebook = wx.Notebook(self)
self.panel1 = wx.Panel(notebook)
self.panel2 = wx.Panel(notebook)
notebook.AddPage(self.panel2, "Settings")
notebook.AddPage(self.panel1, "Instructions")
# Instructions tab
instructions_text = (
"Welcome to EchoEYES!\n\n"
"Instructions:\n\n"
"1. Select the desired language from the dropdown (English or Hindi).\n"
"2. Adjust the volume and speech rate using the sliders.\n"
"3. Choose a voice from the available options.\n"
"4. Click 'Launch' to start the text-to-speech application.\n"
"5. Click 'Quit' to exit the application.\n"
"6. Move your cursor to different text on the screen to hear it spoken.\n"
)
self.instructions_label = wx.StaticText(self.panel1, label=instructions_text)
# Logo image on the Instructions tab
self.logo_bitmap_instructions = wx.Bitmap("Logo.png", wx.BITMAP_TYPE_PNG)
self.logo_staticbitmap_instructions = wx.StaticBitmap(
self.panel1,
wx.ID_ANY,
self.logo_bitmap_instructions,
wx.DefaultPosition,
wx.DefaultSize,
)
# Add logo and instructions label to a sizer
instructions_sizer = wx.BoxSizer(wx.VERTICAL)
instructions_sizer.Add(
self.logo_staticbitmap_instructions,
flag=wx.ALIGN_CENTER | wx.ALL,
border=10,
)
instructions_sizer.Add(
self.instructions_label, flag=wx.ALIGN_CENTER | wx.ALL, border=10
)
# Set the sizer for the Instructions tab
self.panel1.SetSizer(instructions_sizer)
# Settings tab
panel = self.panel2
vbox = wx.BoxSizer(wx.VERTICAL)
# Load the logo image
self.logo_bitmap = wx.Bitmap("Logo.png", wx.BITMAP_TYPE_PNG)
# Create a StaticBitmap widget to display the logo
self.logo_staticbitmap = wx.StaticBitmap(
panel, wx.ID_ANY, self.logo_bitmap, wx.DefaultPosition, wx.DefaultSize
)
vbox.Add(self.logo_staticbitmap, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
# Language selection
language_label = wx.StaticText(panel, label="Select Language:")
self.language_dropdown = wx.Choice(panel, choices=["English", "Hindi"])
self.Bind(wx.EVT_CHOICE, self.on_language_select, self.language_dropdown)
vbox.Add(language_label, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
vbox.Add(self.language_dropdown, flag=wx.EXPAND | wx.ALL, border=10)
# Increase the size of the buttons
button_size = wx.Size(200, 60)
launch_button = wx.Button(panel, label="Launch", size=button_size)
quit_button = wx.Button(panel, label="Quit", size=button_size)
vbox.Add(launch_button, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
vbox.Add(quit_button, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
self.Bind(wx.EVT_BUTTON, self.on_launch, launch_button)
self.Bind(wx.EVT_BUTTON, self.on_quit, quit_button)
# Volume slider
volume_label = wx.StaticText(panel, label="Volume:")
self.volume_slider = wx.Slider(
panel,
value=int(volume * 100),
minValue=0,
maxValue=100,
style=wx.SL_HORIZONTAL,
)
self.Bind(wx.EVT_SLIDER, self.on_volume_change, self.volume_slider)
vbox.Add(volume_label, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
vbox.Add(self.volume_slider, flag=wx.EXPAND | wx.ALL, border=10)
# Rate slider
rate_label = wx.StaticText(panel, label="Speech Rate:")
self.rate_slider = wx.Slider(
panel, value=rate, minValue=100, maxValue=400, style=wx.SL_HORIZONTAL
)
self.Bind(wx.EVT_SLIDER, self.on_rate_change, self.rate_slider)
vbox.Add(rate_label, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
vbox.Add(self.rate_slider, flag=wx.EXPAND | wx.ALL, border=10)
# Voice selection
voice_label = wx.StaticText(panel, label="Select Voice:")
voice_choices = [voice.name for voice in voices]
self.voice_dropdown = wx.ComboBox(
panel, choices=voice_choices, style=wx.CB_READONLY
)
self.Bind(wx.EVT_COMBOBOX, self.on_voice_select, self.voice_dropdown)
vbox.Add(voice_label, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
vbox.Add(self.voice_dropdown, flag=wx.EXPAND | wx.ALL, border=10)
panel.SetSizer(vbox)
def on_launch(self, event):
start_main_loop()
self.Iconize(True)
def on_quit(self, event):
stop_main_loop()
wx.CallAfter(self.Close)
def on_volume_change(self, event):
global volume
volume = self.volume_slider.GetValue() / 100
def on_rate_change(self, event):
global rate
rate = self.rate_slider.GetValue()
def on_voice_select(self, event):
global current_voice
selected_voice_name = self.voice_dropdown.GetValue()
for voice in voices:
if voice.name == selected_voice_name:
current_voice = voice
break
def on_language_select(self, event):
global current_language
selected_language = self.language_dropdown.GetStringSelection()
if selected_language == "English":
current_language = "eng"
elif selected_language == "Hindi":
current_language = "hin"
def take_screenshot():
# Capture a screenshot of the entire screen
screenshot = pyautogui.screenshot()
cursor_position = pyautogui.position()
# Determine the region of interest around the cursor position
x, y = cursor_position
region = (x, y - 20, x + 250, y + 20)
region_image = screenshot.crop(region)
region_image_gray = region_image.convert("L")
region_image_gray = region_image.convert("L")
extracted_text = pytesseract.image_to_string(region_image_gray, lang="eng+hin")
sys.stdout.reconfigure(encoding="utf-8")
return extracted_text
def detect_screen_change(previous_text):
global previous_cursor_position
current_cursor_position = pyautogui.position()
# Check if the cursor has moved from its previous position
if current_cursor_position != previous_cursor_position:
# Capture a new screenshot and perform OCR
new_text = take_screenshot()
# Compare the text extracted from the current and previous screenshots
if new_text != previous_text:
# If the text has changed, alert the user
# If the text has changed, alert the user
engine.stop()
print(new_text)
speak_text(new_text)
previous_cursor_position = current_cursor_position
return new_text
else:
return previous_text
def speak_text(text):
engine.setProperty("volume", volume)
engine.setProperty("rate", rate)
engine.setProperty("voice", current_voice.id)
engine.say(text)
engine.runAndWait()
def main_loop():
global running
initial_text = take_screenshot()
while running:
# Check for cursor movement and screen change
initial_text = detect_screen_change(initial_text)
time.sleep(0.5)
def start_main_loop():
global running
running = True
threading.Thread(target=main_loop).start()
def stop_main_loop():
global running
running = False
app = wx.App()
frame = MyFrame(None, -1, "EchoEYES")
frame.Show()
app.MainLoop()