-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImgTxtSp_lambda
52 lines (46 loc) · 1.27 KB
/
ImgTxtSp_lambda
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
43
44
45
46
47
48
49
50
51
52
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', "/home/xrexeon/Downloads/ant/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 out
def lambda_handler(event, context):
# TODO implement
# client = boto3.client('s3')
# client.upload_file('dody1.jpg', 'ai5', 'dody1.jpg')
# rekog = boto3.client('rekognition')
# return ImgtoTxt('text1.jpg', 'mayada')
return TxtToSp ('mp3',x,'Emma','ily.mp3')
# Input = input("image searching for ")
#return 'Hello from Lambda'