I need to use SSML to play an audio file with the tag in my Alexa Skill (as per Amazon's instructions).
Problem is, I don't know how to use SSML with Python. I know I can use it with Java but I want to build my skills with Python. I've looked all over, but haven't found any working examples of SSML in a Python script/program - does anyone know?
This was asked two years ago but maybe someone will benefit from the below.
I've just checked and if you use Alexa Skills Kit SDK for Python you can simply add SSML to your response, for example:
@sb.request_handler(can_handle_func=is_request_type("LaunchRequest"))
def launch_request_handler(handler_input):
speech_text = "Wait for it 3 seconds<break time="3s"/> Buuuu!"
return handler_input.response_builder.speak(speech_text).response
Hope this helps.
SSML audio resides in the response.outputSpeech.ssml
attribute. Here is an
example obj with other required parameters removed:
{
"response": {
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>
Welcome to Car-Fu.
<audio src="https://carfu.com/audio/carfu-welcome.mp3" />
You can order a ride, or request a fare estimate. Which will it be?
</speak>"
}
}
Further reference:
Install ssml-builder "pip install ssml-builder", and use it:
from ssml_builder.core import Speech
speech = Speech()
speech.add_text('sample text')
ssml = speech.speak()
print(ssml)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With