-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
30 lines (24 loc) · 830 Bytes
/
main.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
'''
Project Name: Text to Speech
Author: Thisitha Wickramarachchi
Description: This program uses pytesseract library for Optical Character Recognition and Google Text To Speech (gTTS) python library to convert text into speech.
To run this program you need to be connected to the internet.
'''
# sudo apt install tesseract-ocr
# pip install gTTS playsound
from PIL import Image
import pytesseract
import numpy as np
import gtts
from playsound import playsound
# convert image to text
imgFile = 'image_01.jpg'
img1 = np.array(Image.open(imgFile))
text = pytesseract.image_to_string(img1)
#convert text into speech
def textToSpeech(text) :
tts = gtts.gTTS(text=text, lang='en')
speechFile = "speech.mp3" # save the synthesized speech to a mp3 file
tts.save(speechFile)
playsound(speechFile)
textToSpeech(text)