The ssml package for python exists.
you can install like below by pip
$ pip install pyssml
or
$ pip3 install pyssml
so example is link below
http://blog.naver.com/chandong83/221145083125
sorry. it is korean.
# -*- coding: utf-8 -*-
# for amazon
import re
import os
import sys
import time
from boto3 import client
from botocore.exceptions import BotoCoreError, ClientError
import vlc
from pyssml.PySSML import PySSML
# amazon service fuction
# if isSSML is True, SSML format
# else Text format
def aws_polly(text, isSSML = False):
voiceid = 'Joanna'
try:
polly = client("polly", region_name="ap-northeast-2")
if isSSML:
textType = 'ssml'
else:
textType = 'text'
response = polly.synthesize_speech(
TextType=textType,
Text=text,
OutputFormat="mp3",
VoiceId=voiceid)
# get Audio Stream (mp3 format)
stream = response.get("AudioStream")
# save the audio Stream File
with open('aws_test_tts.mp3', 'wb') as f:
data = stream.read()
f.write(data)
# VLC play audio
# non block
p = vlc.MediaPlayer('./aws_test_tts.mp3')
p.play()
except ( BotoCoreError, ClientError) as err:
print(str(err))
if __name__ == '__main__':
# normal pyssml
#s = PySSML()
# amazon speech ssml
s = AmazonSpeech()
# normal
s.say('i am normal')
# speed is very slow
s.prosody({'rate':"x-slow"}, 'i am very slow')
# volume is very loud
s.prosody({'volume':'x-loud'}, 'my voice is very loud')
# take a one sec
s.pause('1s')
# pitch is very high
s.prosody({'pitch':'x-high'}, 'my tone is very high')
# amazone
s.whisper('i am whispering')
# print to convert to ssml format
print(s.ssml())
# request aws polly and play
aws_polly(s.ssml(), True)
# Wait while playback.
time.sleep(50)
type
param of theoutputSpeech
JSON object toSSML
and usessml
instead iftext
, you can use SSML tags (as documented in the Speech Synthesis Markup Language (SSML) Reference). – Gapes