-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtext_recog.py
More file actions
28 lines (17 loc) · 793 Bytes
/
text_recog.py
File metadata and controls
28 lines (17 loc) · 793 Bytes
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
from google_trans_new import google_translator
translator = google_translator()
##Created by Lex Whalen 2/19/21
class TextRecognizer():
###for text only
def __init__(self):
self.TRANSLATOR = google_translator()
def translate_text(self,text,src_lang,out_lang):
translate_text = self.TRANSLATOR.translate(text,lang_src=src_lang,lang_tgt=out_lang)
return translate_text
def detect_lang(self, text):
##returns the detected language
detect_res = self.TRANSLATOR.detect(text)
return detect_res
###THIS IS BONUS CONTENT. Try to apply it to the regular sub generator to convert English!
#translate_text = translator.translate('Hello!',lang_src='en', lang_tgt='ja')
#rint(translate_text)