Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
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."
|