Class: TextToSpeechUtils

TextToSpeechUtils

A collection of useful text-to-speech functions.

Methods

(static) addMarksToUnmarkedSentences(text, marks) → {string}

Returns a new string with a random SSML mark inserted at each sentence that
does not already contain an SSML mark.

Parameters:
Name Type Description
text string

Input string.

marks Array.<string>

Any array of random SSML marks to choose from
when modifying the text.

Returns:
Type
string

(static) autoGenerateSSMLMarks(text, map, randomMarksopt) → {string}

Returns a new string with SSML marks inserted based on
matches between the input string and the input map. The
word matches are case-insensitive. Words within existing
SSML tags will not be affected. Input text will be surrounded
by tags if needed.

Parameters:
Name Type Attributes Default Description
text string

Input string.

map object

Input object that maps mark keys
to arrays of words. Example:

{
'mark:sad' : ['sad', 'blue', 'down'],
'mark:happy' : ['joy', 'glad', 'great'],
'mark:no' : ['no', 'nah', 'nay', 'sure']
}

randomMarks Array.<string> <optional>
[]

If there are sentences that don't
match any words from the map object, marks from this array will be randomly
chosen and inserted.

Returns:
  • Updated input string.
Type
string

(static) validateText(text) → {string}

Generate a version of given text that is enclosed by Polly ssml speak tags.

Parameters:
Name Type Description
text string

The text to validate.

Returns:
  • Updated input string.
Type
string