-
Notifications
You must be signed in to change notification settings - Fork 0
/
English Speaking and Learning.py
373 lines (306 loc) · 16.1 KB
/
English Speaking and Learning.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import random
import threading
import time
import sqlite3
import speech_recognition as sr
import sys
import os
from pygame import mixer
from gtts import gTTS
from time import sleep
class English():
def __init__(self, Sleep, Score):
self.Sleep = Sleep
self.CON = sqlite3.connect("English.db")
self.CURSOR = self.CON.cursor()
self.History = sqlite3.connect("EnglishLocal.db")
self.HistoryCursor = self.History.cursor()
self.Türkçe = ""
self.İngilizce = ""
self.Microphone_TEXT = ""
self.EnginnerRandom = 0
self.EnginnerStop = Score
self.EnginnerScore = 0
self.CreateDatabase()
self.InsertDatabase()
self.RandomDatabase()
self.RandomSelect()
self.Thread = threading.Thread(target=self.Enginner(), daemon=True)
self.Thread.start()
def CreateDatabase(self):
Years = time.gmtime()[0]
Mounth = time.gmtime()[1]
Day = time.gmtime()[2]
Hours = time.gmtime()[3]
LocalTime = f"{Years}-{Mounth}-{Day}-{Hours}"
self.CURSOR.execute("CREATE TABLE IF NOT EXISTS Language(Türkçe TEXT, İngilizce TEXT, Puan TEXT, Zaman TEXT)")
self.CON.commit()
self.HistoryCursor.execute("CREATE TABLE IF NOT EXISTS LanguageLocal(Puan TEXT, Zaman TEXT)")
self.History.commit()
self.HistoryCursor.execute("INSERT INTO LanguageLocal(Puan,Zaman) VALUES(?,?)", (0, LocalTime))
self.History.commit()
def InsertDatabase(self):
islem = input("Veri Eklemek İster Misiniz : 'evet/hayır' : ")
if islem == "evet" or islem == "Evet":
sayı = int(input("Kaç Adet Veri Eklemek İstiyorsunuz ? : "))
while sayı:
sayı -= 1
Turkce = str(input("Türkçe Anlamı : "))
English = str(input("İngilizce Anlamı : "))
self.CURSOR.execute("INSERT INTO Language(Türkçe,İngilizce) VALUES(?,?)", (Turkce, English))
self.CON.commit()
elif islem == "hayır" or islem == "Hayır":
pass
else:
pass
def SelectDatabase(self):
self.CURSOR.execute("SELECT * FROM Language")
data = self.CURSOR.fetchall()
return data
def RandomDatabase(self):
self.CURSOR.execute("SELECT Türkçe,İngilizce FROM Language ORDER BY random() LIMIT 1")
data = self.CURSOR.fetchall()
for i in data:
if len(i) == 0:
print("Veritabanında Veri Yok.")
time.sleep(3)
sys.exit()
else:
self.Türkçe = i[0]
self.İngilizce = i[1]
# print("Türkçe Anlam : ", self.Türkçe)
# print("İngilizce Anlam : ",self.İngilizce)
def RandomSelect(self):
self.EnginnerRandom = random.randint(0, 1)
def Hatırlat(self, MOD):
if MOD == "Türkçe":
tts = gTTS(f"{self.İngilizce} Anlamı. {self.Türkçe}", lang="tr")
tts.save("Hatırlat.mp3")
print(f"\n{self.İngilizce} : {self.Türkçe}")
elif MOD == "İngilizce":
tts = gTTS(f"{self.Türkçe} Anlamı. {self.İngilizce}", lang="en")
tts.save("Hatırlat.mp3")
print(f"\n{self.Türkçe} : {self.İngilizce}")
TIME_OUT = str
TRACK = "Hatırlat.mp3"
mixer.init()
mixer.music.load(TRACK)
mixer.music.play()
while (mixer.music.get_busy()):
TIME_OUT = "\r" + str(mixer.music.get_pos())
TIME_OUT_MATH = int(TIME_OUT) / 1000
sleep(round(TIME_OUT_MATH, 1))
mixer.music.unload()
os.remove("Hatırlat.mp3")
def Microphone(self):
while True:
try:
# Türkçe
if self.EnginnerRandom == 0:
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source=source, phrase_time_limit=10, timeout=3)
self.Microphone_TEXT = r.recognize_google(audio, language="tr")
return False
# İngilizce
else:
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source=source, phrase_time_limit=10, timeout=3)
self.Microphone_TEXT = r.recognize_google(audio, language="en")
return False
except:
print("\nLütfen Konuşun.")
def Listening(self):
if self.EnginnerRandom == 0:
tts = gTTS(self.İngilizce, lang="en")
tts.save("Listening.mp3")
else:
tts = gTTS(self.Türkçe, lang="tr")
tts.save("Listening.mp3")
TIME_OUT = str
TRACK = "Listening.mp3"
mixer.init()
mixer.music.load(TRACK)
mixer.music.play()
while (mixer.music.get_busy()):
TIME_OUT = "\r" + str(mixer.music.get_pos())
TIME_OUT_MATH = int(TIME_OUT) / 1000
sleep(round(TIME_OUT_MATH, 1))
mixer.music.unload()
os.remove("Listening.mp3")
def Enginner(self):
while True:
# Finish Code
if self.EnginnerStop == self.EnginnerScore:
print("Başarıyla Bitirdiniz.")
return False
else:
time.sleep(int(self.Sleep))
self.RandomDatabase()
self.RandomSelect()
self.Listening()
# Türkçe Konuşmak
if self.EnginnerRandom == 0:
print("\nİngilizce Kelime : ", self.İngilizce.lower().strip())
self.Microphone()
print("Mikrofon Verisi : ", self.Microphone_TEXT.strip())
# Öğret
if self.Microphone_TEXT.strip() == "bilmiyorum":
self.Hatırlat("Türkçe")
elif self.Microphone_TEXT.strip() == "geçmiş":
self.HistoryCursor.execute("SELECT * FROM LanguageLocal")
DATA = self.HistoryCursor.fetchall()
for i in DATA:
print("----------------------------------------")
print(f"Puan : {i[0]}\t\t Tarih : {i[1]}")
print("----------------------------------------\n")
# Kelime Görüntüle
elif self.Microphone_TEXT.strip() == "veritabanı":
for i in self.SelectDatabase():
print("----------------------------------------")
print(f"Türkçe : {i[0]}\t\t İngilizce : {i[1]}")
print("----------------------------------------\n")
# Kelime Güncelle
elif self.Microphone_TEXT.strip() == "verilerimi güncelle" or self.Microphone_TEXT.strip() == "bilgilerimi güncelle":
Index = 0
for i in self.SelectDatabase():
Index += 1
print("----------------------------------------")
print(f"{Index}. SATIR -) Türkçe : {i[0]}\t\t İngilizce : {i[1]}")
print("----------------------------------------\n")
print("Toplam Satır : ", Index)
print("Toplam Sütun : ", 2)
SATIR = int(input("Kaçıncı Satırı Güncellemek İstiyorsunuz : "))
SUTUN = int(input("Kaçıncı Sütunu Güncellemek İstiyorsunuz : "))
NEW_DATA = input("Güncellemek İstediğiniz Yeni Kelime : ")
Index = 0
for i in self.SelectDatabase():
Index += 1
if Index == int(SATIR) and SUTUN == 1:
ARADIGIMIZ_KELIME = i[0]
self.CURSOR.execute("UPDATE Language SET Türkçe = ? WHERE Türkçe = ?",
(NEW_DATA, ARADIGIMIZ_KELIME))
self.CON.commit()
print("Güncelleme Başarılı")
elif Index == int(SATIR) and SUTUN == 2:
ARADIGIMIZ_KELIME = i[1]
self.CURSOR.execute("UPDATE Language SET Türkçe = ? WHERE Türkçe = ?",
(NEW_DATA, ARADIGIMIZ_KELIME))
self.CON.commit()
print("Güncelleme Başarılı")
# Doğru
elif self.Microphone_TEXT.strip() == self.Türkçe.lower().strip():
self.HistoryCursor.execute("SELECT * FROM LanguageLocal")
HistoryData = self.HistoryCursor.fetchall()
LEN = len(HistoryData)
OLD_SCORE = int(HistoryData[int(LEN) - 1][0])
SCORE = int(HistoryData[int(LEN) - 1][0]) + 1
print("\nDoğru")
print("--------------------------")
print("Eski Score : ", OLD_SCORE)
print("Yeni Skor : ", SCORE)
print("--------------------------\n")
self.EnginnerScore += 1
self.HistoryCursor.execute("UPDATE LanguageLocal SET Puan = ? WHERE Puan = ?",
(SCORE, OLD_SCORE))
self.History.commit()
# Yanlış
else:
self.HistoryCursor.execute("SELECT * FROM LanguageLocal")
HistoryData = self.HistoryCursor.fetchall()
LEN = len(HistoryData)
OLD_SCORE = int(HistoryData[int(LEN) - 1][0])
SCORE = int(HistoryData[int(LEN) - 1][0]) - 1
print("\nYanlış")
print("--------------------------")
print("Eski Score : ", OLD_SCORE)
print("Yeni Skor : ", SCORE)
print("--------------------------\n")
self.EnginnerScore -= 1
self.HistoryCursor.execute("UPDATE LanguageLocal SET Puan = ? WHERE Puan = ?",
(SCORE, OLD_SCORE))
self.History.commit()
# İngilizce Konuşmak
else:
print("\nTürkçe Kelime : ", self.Türkçe.strip().lower())
self.Microphone()
print("Mikrofon Data : ", self.Microphone_TEXT)
# Öğret
if self.Microphone_TEXT.strip() == "don't know":
self.Hatırlat("İngilizce")
elif self.Microphone_TEXT.strip() == "history":
self.HistoryCursor.execute("SELECT * FROM LanguageLocal")
DATA = self.HistoryCursor.fetchall()
for i in DATA:
print("----------------------------------------")
print(f"Puan : {i[0]}\t\t Tarih : {i[1]}")
print("----------------------------------------\n")
# Görüntüle
elif self.Microphone_TEXT.strip() == "database":
for i in self.SelectDatabase():
print("----------------------------------------")
print(f"Türkçe : {i[0]}\t\t İngilizce : {i[1]}")
print("----------------------------------------\n")
# Güncelle
elif self.Microphone_TEXT.strip() == "database update" or self.Microphone_TEXT.strip() == "profile update":
Index = 0
for i in self.SelectDatabase():
Index += 1
print("----------------------------------------")
print(f"{Index}. SATIR -) Türkçe : {i[0]}\t\t İngilizce : {i[1]}")
print("----------------------------------------\n")
print("Toplam Satır : ", Index)
print("Toplam Sütun : ", 2)
SATIR = int(input("Kaçıncı Satırı Güncellemek İstiyorsunuz : "))
SUTUN = int(input("Kaçıncı Sütunu Güncellemek İstiyorsunuz : "))
NEW_DATA = input("Güncellemek İstediğiniz Yeni Kelime : ")
Index = 0
for i in self.SelectDatabase():
Index += 1
if Index == int(SATIR) and SUTUN == 1:
ARADIGIMIZ_KELIME = i[0]
self.CURSOR.execute("UPDATE Language SET Türkçe = ? WHERE Türkçe = ?",
(NEW_DATA, ARADIGIMIZ_KELIME))
self.CON.commit()
print("Güncelleme Başarılı")
elif Index == int(SATIR) and SUTUN == 2:
ARADIGIMIZ_KELIME = i[1]
self.CURSOR.execute("UPDATE Language SET Türkçe = ? WHERE Türkçe = ?",
(NEW_DATA, ARADIGIMIZ_KELIME))
self.CON.commit()
print("Güncelleme Başarılı")
# Doğru
elif self.Microphone_TEXT.strip() == self.İngilizce.lower().strip():
self.HistoryCursor.execute("SELECT * FROM LanguageLocal")
HistoryData = self.HistoryCursor.fetchall()
LEN = len(HistoryData)
OLD_SCORE = int(HistoryData[int(LEN) - 1][0])
SCORE = int(HistoryData[int(LEN) - 1][0]) + 1
print("\nDoğru")
print("--------------------------")
print("Eski Score : ", OLD_SCORE)
print("Yeni Skor : ", SCORE)
print("--------------------------\n")
self.EnginnerScore += 1
self.HistoryCursor.execute("UPDATE LanguageLocal SET Puan = ? WHERE Puan = ?",
(SCORE, OLD_SCORE))
self.History.commit()
# Yanlış
else:
self.HistoryCursor.execute("SELECT * FROM LanguageLocal")
HistoryData = self.HistoryCursor.fetchall()
LEN = len(HistoryData)
OLD_SCORE = int(HistoryData[int(LEN) - 1][0])
SCORE = int(HistoryData[int(LEN) - 1][0]) - 1
print("\nYanlış")
print("--------------------------")
print("Eski Score : ", OLD_SCORE)
print("Yeni Skor : ", SCORE)
print("--------------------------\n")
self.EnginnerScore -= 1
self.HistoryCursor.execute("UPDATE LanguageLocal SET Puan = ? WHERE Puan = ?",
(SCORE, OLD_SCORE))
self.History.commit()
# Sleep = Soru'nun Zaman Aralığı / Score Hedef Skor.
English(Sleep=1, Score=2)