Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to incorporate SSML into Python

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?

like image 482
SamYoungNY Avatar asked Apr 14 '16 20:04

SamYoungNY


3 Answers

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.

like image 90
wmatt Avatar answered Oct 17 '22 21:10

wmatt


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:

  • JSON Interface Reference for Custom Skills
  • Speech Synthesis Markup Language (SSML) Reference
like image 42
BMW Avatar answered Oct 17 '22 23:10

BMW


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)
like image 3
Victor Vrabii Avatar answered Oct 17 '22 21:10

Victor Vrabii