-
Notifications
You must be signed in to change notification settings - Fork 2
/
tts.py
43 lines (42 loc) · 1.07 KB
/
tts.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
from flask import send_file
import boto3
region_name = ''
polly_client = boto3.client(
'polly',
aws_access_key_id = '',
aws_secret_access_key = '',
region_name = region_name
)
korean = {
"0": " ",
"1": "하나",
"2": "둘",
"3": "셋",
"4": "넷",
"5": "다섯",
"6": "여섯",
"7": "일곱",
"8": "여덟",
"9": "아홉",
"10": "열"
}
class TTS:
precount = 0
def textToSpeech(self, count):
if count != 0:
num = (count-1)%10 + 1
text = " "
if TTS.precount != count:
text = korean[str(num)]
TTS.precount = count
# text = korean[str(num)]
print("TTS.precount: ", TTS.precount)
print("count: ", count, "num: ", num)
print("text: ", text)
response = polly_client.synthesize_speech(
Text="<speak>" + text + "</speak>",
VoiceId='Seoyeon',
OutputFormat='mp3',
TextType='ssml'
)
return send_file(response.get("AudioStream"), mimetype="audio/mp3", cache_timeout=0)