-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImgTxtSp.py
42 lines (38 loc) · 1023 Bytes
/
ImgTxtSp.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
31
32
33
34
35
36
37
38
39
40
41
42
import boto3
def ImgtoTxt (img,bkt,path):
client = boto3.client('s3')
client.upload_file(img,bkt,img)
client = boto3.client('rekognition')
response = client.detect_text(
Image={
'S3Object': {
'Bucket': bkt,
'Name': img,
}
}
)
out = ""
for i in response['TextDetections']:
out = out + i['DetectedText']+" "
print(out)
outf = open(path, 'w')
outf.write(out)
outf.close()
return out
x=ImgtoTxt('img.jpg', 'mayada', "C:/Users/asus/PycharmProjects/untitled1/file.txt")
def TxtToSp (format,txt,vid,outname):
client = boto3.client('polly')
response = client.synthesize_speech(
OutputFormat=format,
Text=txt,
VoiceId=vid
)
print('\n')
out = response['AudioStream']
out = out.read()
print(out)
outf = open(outname, "wb")
outf.write(out)
outf.close()
return
TxtToSp ('mp3',x,'Emma','ily.mp3')