File tree Expand file tree Collapse file tree 4 files changed +33
-39
lines changed Expand file tree Collapse file tree 4 files changed +33
-39
lines changed Original file line number Diff line number Diff line change 4
4
5
5
## Image To Speech Functionalities : 🚀
6
6
7
- - There are two parts :
8
- 1 ) The first script image_to_text.py. In this the user gives the input of the image path
9
- and the script converts the image to text file.
10
- 2 ) The second script text_to_speech.py. This script directly converts the text file of the first
11
- script to speech file or mp3 file.
12
-
13
- - The scripts run depending on the user requirement
7
+ - The script converts an image to text and speech files
8
+ - At the end the script asks whether to save or delete files
14
9
15
10
## Image To Speech Instructions: 👨🏻💻
16
11
24
19
25
20
### Step 3:
26
21
27
- Run the command: python image_to_text.py/python3 image_to_text.py 🧐
28
- To convert image to text
29
-
30
- Run the command: python text_to_speech.py/python3 text_to_speech.py 🧐
31
- If you want to convert above obtained text file to speech
22
+ Run the command: python image_to_speech.py/python3 image_to_speech.py 🧐
32
23
33
24
### Step 4:
34
25
Original file line number Diff line number Diff line change
1
+ import pytesseract
2
+ from PIL import Image
3
+ from gtts import gTTS
4
+ import os
5
+
6
+
7
+ pytesseract .pytesseract .tesseract_cmd = input (r'Enter the path: ' )
8
+
9
+ img = input (r"Enter image: " )
10
+ target = Image .open (img )
11
+ text = pytesseract .image_to_string (target , config = '' )
12
+
13
+ with open (f"./Imagetospeech/Text/text.txt" ,'w' ) as f :
14
+ f .write (text )
15
+
16
+ file = open (r'./Imagetospeech/Text/text.txt' )
17
+ mytext = file .read ().replace ("\n " ," " )
18
+ language = 'en'
19
+ output = gTTS (text = mytext , lang = language , slow = False )
20
+ output .save ('./Imagetospeech/sound/imagetospeech.mp3' )
21
+ file .close ()
22
+ os .system ("start ./Imagetospeech/sound/imagetospeech.mp3" )
23
+
24
+ question = input ("Do you want to delete the files (Y/N): " )
25
+ if question == 'Y' or question == 'y' :
26
+ os .remove ('./Imagetospeech/Text/text.txt' )
27
+ os .remove ('./Imagetospeech/sound/imagetospeech.mp3' )
28
+
29
+ elif question == 'N' or question == 'n' :
30
+ print ("Files saved" )
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments