-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
44 lines (36 loc) · 1.24 KB
/
code.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
43
44
# GUI for T2S converter
import tkinter as tk
import boto3
import os
import sys
from tempfile import gettempdir
from contextlib import closing
root=tk.Tk()
root.geometry("400x240")
root.title("T2S-conversion Amazon Polly")
textExample=tk.Text(root,height=10)
textExample.pack()
def getText():
aws_mag_con=boto3.session.Session(profile_name='demo_user')
client=aws_mag_con.client(service_name='polly',region_name='us-east-1')
result=textExample.get("1.0","end")
print(result)
response=client.synthesize_speech(VoiceId='Kajal*',OutputFormat='mp3',Text=result,Engine='neural')
print(response)
if "AudioStream" in response:
with closing(response['AudioStream']) as stream:
output=os.path.join(gettempdir(),"speech.mp3")
try:
with open(output,"wb") as file:
file.write(stream.read())
except IOError as error:
print(error)
sys.exit(-1)
else:
print("Cloud not find the stream")
sys.exit(-1)
if sys.platform=='win32':
os.startfile(output)
btnRead=tk.Button(root,height=1,width=10,text="READ",command=getText)
btnRead.pack()
root.mainloop()