Almas-123 commited on
Commit
97783ce
·
verified ·
1 Parent(s): 66a0396

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +18 -0
utils.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import pytesseract
3
+ import speech_recognition as sr
4
+
5
+ def extract_text_from_image(uploaded_file):
6
+ img = Image.open(uploaded_file)
7
+ return pytesseract.image_to_string(img)
8
+
9
+ def speech_to_text():
10
+ r = sr.Recognizer()
11
+ with sr.Microphone() as source:
12
+ audio = r.listen(source)
13
+ try:
14
+ return r.recognize_google(audio)
15
+ except sr.UnknownValueError:
16
+ return "Could not understand audio."
17
+ except sr.RequestError:
18
+ return "Speech recognition service error."