-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadAloud.py
More file actions
34 lines (25 loc) · 1 KB
/
readAloud.py
File metadata and controls
34 lines (25 loc) · 1 KB
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
from PIL import Image
import pyttsx3
import pytesseract
def to_audio(text_to_read, audio_output):
"""This function convert textual data into audio
Args:
text_to_read (str): The textual data to be converted into audio
audio_output (str): The name of the audio output file
"""
speaker = pyttsx3.init()
# read aloud voice the texteual data
speaker.say(text_to_read)
# save it in a audio file
speaker.save_to_file(text_to_read, f'{audio_output}.mp3')
speaker.runAndWait()
# path to executable binary of tesseract
pytesseract.pytesseract.tesseract_cmd = "C:\\Users\Administrator\\AppData\\Local\\Tesseract-OCR\\tesseract.exe"
# The path of the image to recognize text on
image_path = input("The image path > ")
img = Image.open(image_path)
# convert recognized text from the image to txt
image_to_txt = pytesseract.image_to_string(img)
# prompt for the audio output
audio_output = input('output file without extension 🔉> ')
to_audio(image_to_txt, audio_output)