Adds an SSML element as a child of this paragraph.
This method allows adding any valid SSML element that can be contained within a paragraph, enabling complex structured content with various speech modifications and effects.
An SSML element to add to the paragraph. Must be a valid child element for paragraphs.
This ParagraphElement instance for method chaining
const paragraph = new ParagraphElement();
const sentence = new SentenceElement();
sentence.text('This is a sentence.');
paragraph.addElement(sentence);
// Add multiple elements
const emphasis = new EmphasisElement('important', 'strong');
paragraph
.text('This is ')
.addElement(emphasis)
.text(' information.');
Adds an audio file to the paragraph.
The audio element allows insertion of pre-recorded audio files within the paragraph content, with optional fallback text.
URL of the audio file (must be HTTPS)
Optional
fallbackText: stringOptional text to speak if audio is unavailable
This ParagraphElement instance for method chaining
Adds a pause or break within the paragraph.
Breaks provide control over pauses between words or sentences, useful for improving comprehension or creating dramatic effect.
Optional
options: string | BreakOptionsBreak configuration or duration string. Can be a duration (e.g., '500ms') or an object with strength/time.
This ParagraphElement instance for method chaining
Adds emphasized text to the paragraph.
Emphasis changes the speaking style to highlight important words or phrases through changes in pitch, timing, and vocal stress.
The text to emphasize
Optional
level: EmphasisLevelOptional emphasis level: 'strong', 'moderate' (default), or 'reduced'
This ParagraphElement instance for method chaining
Protected
escapeProtected
Escapes special XML characters in text content to ensure valid XML output.
This method replaces XML special characters with their corresponding entity references to prevent XML parsing errors and potential security issues (XML injection). It should be used whenever inserting user-provided or dynamic text content into XML elements.
The following characters are escaped:
&
becomes &
(must be escaped first to avoid double-escaping)<
becomes <
(prevents opening of unintended tags)>
becomes >
(prevents closing of unintended tags)"
becomes "
(prevents breaking out of attribute values)'
becomes '
(prevents breaking out of attribute values)This method is marked as protected
so it's only accessible to classes that extend
SSMLElement, ensuring proper encapsulation while allowing all element implementations
to use this essential functionality.
The text content to escape
The text with all special XML characters properly escaped
// In a render method implementation
class TextElement extends SSMLElement {
private text: string = 'Hello & "world" <script>';
render(): string {
// Escapes to: Hello & "world" <script>
return `<text>${this.escapeXml(this.text)}</text>`;
}
}
// Edge cases handled correctly
this.escapeXml('5 < 10 & 10 > 5');
// Returns: '5 < 10 & 10 > 5'
this.escapeXml('She said "Hello"');
// Returns: 'She said "Hello"'
this.escapeXml("It's a test");
// Returns: 'It's a test'
// Prevents XML injection
this.escapeXml('</voice><voice name="evil">');
// Returns: '</voice><voice name="evil">'
Adds phonetic pronunciation for specific text.
The phoneme element provides exact pronunciation using phonetic alphabets, essential for proper names or technical terms that might be mispronounced.
The text to pronounce
Phoneme configuration
Configuration options for phoneme elements.
Provides exact phonetic pronunciation using standard phonetic alphabets. Essential for proper names, technical terms, or words with ambiguous pronunciation.
Phonetic alphabet used for transcription. (Required)
Available alphabets:
ipa
: International Phonetic Alphabet (universal standard)sapi
: Microsoft SAPI phonemes (English-focused)ups
: Universal Phone Set (Microsoft's unified system)Phonetic transcription of the word. (Required)
The exact phonetic representation in the specified alphabet. Must be valid according to the chosen alphabet's rules.
This ParagraphElement instance for method chaining
Adds text with modified prosody (pitch, rate, volume).
Prosody modifications affect how text is spoken, allowing for expressive variations in speech characteristics.
The text to modify
Prosody configuration
Configuration options for prosody (speech characteristics).
Controls various aspects of speech delivery including pitch, speaking rate, volume, and intonation contours. Multiple properties can be combined for complex speech modifications.
Optional
contour?: stringPitch contour changes over time.
Defines how pitch changes during speech using time-position pairs. Format: "(time1,pitch1) (time2,pitch2) ..." Time as percentage, pitch as Hz or percentage change.
Optional
pitch?: stringPitch adjustment for the speech.
Can be specified as:
Optional
range?: stringPitch range variation.
Controls the variability of pitch (monotone vs expressive). Can be relative change or named value.
Optional
rate?: stringSpeaking rate/speed.
Can be specified as:
Optional
volume?: stringVolume level of the speech.
Can be specified as:
This ParagraphElement instance for method chaining
Renders the paragraph element as an SSML XML string.
Generates the <p>
element containing all child content. Text content
is automatically escaped to prevent XML injection, while child elements
are rendered recursively to build the complete paragraph structure.
The XML string representation of the paragraph element
Adds a say-as element to control pronunciation of formatted text.
The say-as element ensures proper pronunciation of dates, numbers, currency, and other specialized text formats within the paragraph.
The text to be interpreted
Configuration for text interpretation
Configuration options for say-as elements.
Controls interpretation and pronunciation of formatted text like dates, numbers, currency, and other specialized content.
Optional
detail?: stringAdditional detail for interpretation.
Provides extra context for certain interpretAs types:
Optional
format?: stringFormat hint for interpretation.
Provides additional formatting information. Available formats depend on interpretAs value:
For dates:
For time:
How to interpret the text content. (Required)
Determines the pronunciation rules applied to the text. Each type has specific formatting requirements.
This ParagraphElement instance for method chaining
Adds a substitution element for custom pronunciation.
The sub element allows you to specify an alias that should be spoken instead of the written text, useful for acronyms or abbreviations.
The text as written
How the text should be pronounced
This ParagraphElement instance for method chaining
Adds plain text content to the paragraph.
The text will be spoken as part of the paragraph with appropriate pauses and intonation for paragraph context. Special XML characters are automatically escaped to ensure valid XML output and prevent injection attacks.
The text content to add to the paragraph. Will be spoken with paragraph-appropriate prosody. Multiple calls append text sequentially.
This ParagraphElement instance for method chaining
const paragraph = new ParagraphElement();
paragraph.text('This is the first sentence. ');
paragraph.text('This is the second sentence.');
// Result: <p>This is the first sentence. This is the second sentence.</p>
// With special characters (automatically escaped)
paragraph.text('Terms & conditions apply.');
SSML element for structuring content into paragraphs.
The
<p>
element denotes a paragraph in synthesized speech, providing logical structure to the content and ensuring appropriate pauses between blocks of text. The speech synthesizer uses paragraph boundaries to apply natural intonation patterns and timing, creating more comprehensible and natural-sounding speech output. This element is particularly useful for longer texts where clear separation of ideas improves listener comprehension.Paragraphs can contain various inline elements including text, sentences, breaks, emphasis, prosody, and other speech modification elements. The paragraph element helps the synthesizer understand document structure even when sentence elements aren't explicitly marked.
Example
Remarks
See