ssml-gib
Helper library for generating SSML for use in Alexa Skills.
ask-gib for authoring Alexa Skills in TypeScript.
See alsoSsml
class- Factory functions
<phoneme>
<emphasis>
<prosody>
<amazon-effect>
<audio>
<break>
(pause)<sub>
<w>
<sayAs>
<p>
<s>
- (Hmmm, still up-to-date?) Full support for SpeechCons in English (US), English (UK), and German
- Leverage TypeScript auto-complete for each SpeechCon.
- Helper functions
- Wrap/Unwrap
<speak>
- Useful to be able to unwrap as well.
stripSsml(text: string)
- Wrap/Unwrap
- Factory functions
All of the following levels and settings are checked at compile time with TypeScript pseudo-enums (discriminated
unions of string literals), so e.g., you can't typo "low" when you actually meant "slow" when defining a rate.
So instead of trying to remember all the intricacies of the <prosody>
tag in all its
glory, you can just hit ctrl+space and see the options available. This stems from
TypeScript and vscode auto-complete goodness.
Installation
Install with npm:
npm install --save ssml-gib
Import ES6 style:
// for Ssml helper only; // for SpeechCons;
Usage
Each function returns a string that contains the SSML, which is especially useful when combined with JavaScript's templated strings.
Phoneme
Ssml.phoneme"functacular", "fʌŋktækjulɝ"; // "ipa" is the defaultSsml.phoneme"functacular", "fʌŋktækjulɝ", "ipa"; // or to be explicit...Ssml.phoneme"functacular", "fVNkt{kjul@`", "x-sampa"; // x-sampa also supported ;// The word of the day is <phoneme alphabet="ipa" ph="${funkIPA}">functacular</phoneme>.
Emphasis
Ssml.emphasis"emphasize me"; // defaults to moderateSsml.emphasis"emphasize me", "strong"; // explicit strong ;// This is <emphasis level="moderate">very</emphasis> important.
Prosody
Ssml.prosody"say me slowly", ; Ssml.prosody"say me like a chipmunk", ; // preset pitchSsml.prosody"say me like a chipmunk", ; // increase pitch by %50Ssml.prosody"say me like thunder", ; // decrease pitch by %30 Ssml.prosody"shout me!", ; // preset increaseSsml.prosody"shout me!", ; // specify in decibelsSsml.prosody"shout me!", ; // min decibels // combine them;// Well, <prosody rate="slow" pitch="low" volume="soft">hello there...</prosody>
SpeechCons
Ssml.speechCon.arrivederci;Ssml.speechCon.bada_bing_bada_boom;Ssml.speechConUK.blimey; // ConUK for English (UK)Ssml.speechConDE.achtung; // ConDE for German (Deutsch) ;// To open the door, say <say-as interpret-as="interjection">abracadabra</say-as>!
Amazon Effect
// change the import to include the `Effect` object.; Ssml.amazonEffect.whispered, "Be vewy, vewy quiet..."; ;// My secret is this: <amazon:effect name="whispered">I have no secrets.</amazon:effect>
Audio
Ssml.audio"https123://x.y.z/audio.mp3"; ;// Welcome! <audio src="httpsss://x.y.z/welcome_jingle.mp3" />
Break (Pause)
Ssml.break;Ssml.break; ;// You have three seconds to think about it...<break time="3s"/>
Sub
Ssml.sub"Mg", "Magnesium"; ;// Bronze is made with <sub alias="copper">Cu</sub> and <sub alias="tin">Sn</sub>.
W (Part of Speech)
Ssml.w"read", PartOfSpeech.past_participle;Ssml.w"bass", PartOfSpeech.sense1; ;// Use the 'w' tag to disambiguate how to pronounce words like '<w role="amazon:NN">lead</w>'.
say-as
Ssml.sayAs;Ssml.sayAs;Ssml.sayAs;Ssml.sayAs;Ssml.sayAs; ;// <say-as interpret-as="expletive">frack</say-as>
Thanks
- Amazon for creating such good documentation and a good product.
- Up.