Version 3.4.0: Add a new library for JSX Speech Script

We’re happy to announce the new package @ask-utils/speech-script.
We can easy to write your Skill’s SSML like React.

Install

$ npm i -S @ask-utils/speech-script

Usage

/** @jsx ssml */
import {
    StandardSkillFactory
} from 'ask-sdk'
import {
    ssml,
    SpeechScriptJSX
} from '../dist/index'
import { LaunchRequest } from 'ask-sdk-model'

/**
 * SSML component like React
 **/
class LaunchRequestScript extends SpeechScriptJSX<LaunchRequest> {
    speech() {
        const { locale } = this.props.request
        if (/^ja/.test(locale)) {
            return (
                <speak>こんにちは!<break time="0.5s"/>お元気ですか?</speak>
            )
        }
        return (
            <speak>
                Hello! <break time="0.5s"/>How are you?
            </speak>
        )
    }
    reprompt() {
        const { locale } = this.props.request
        if (/^ja/.test(locale)) {
            return (
                <speak>
                    お元気ですか?<break time="0.5s"/>
                    <amazon-effect name="whispered">今日はいい日になるといいですね。</amazon-effect>
                </speak>
            )
        }
        return (
            <speak>
                How are you?<break time="0.5s"/>
                <amazon-effect name="whispered">I hope you to have a good day.</amazon-effect>
            </speak>
        )

    }
}

/**
 * Use the SSML component in your RequestHandler
 **/
export const handler = StandardSkillFactory.init()
.addRequestHandlers({
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'LaunchRequest'
    },
    handle(handlerInput) {
        const Speech = new LaunchRequestScript(handlerInput)
        const {
            speech,
            reprompt,
        } = Speech.create()
        return handlerInput.responseBuilder
            .speak(speech)
            .reprompt(reprompt)
            .getResponse()
    }
}).lambda()