Creates a new TTSEmbeddingElement instance.
The unique identifier of the custom speaker profile. This ID is generated when you create and train a custom speaker profile using Azure's Custom Neural Voice service. The profile contains the voice characteristics and training data that define how the text should be spoken. Format typically: alphanumeric string with hyphens (e.g., "profile-12345-abcd-efgh")
The text content to be synthesized using the custom speaker profile. Special XML characters (&, <, >, ", ') are automatically escaped to ensure valid XML output and prevent injection attacks. The text will be spoken with the voice characteristics defined in the referenced speaker profile.
// Corporate brand voice
const brandVoice = new TTSEmbeddingElement(
'company-brand-voice-001',
'Welcome to our company. We value your business.'
);
// Personal assistant voice
const assistant = new TTSEmbeddingElement(
'personal-assistant-profile',
'Good morning! Here is your schedule for today.'
);
// Character voice for gaming/entertainment
const characterVoice = new TTSEmbeddingElement(
'game-character-wizard',
'Greetings, brave adventurer! Your quest awaits.'
);
// Narrator voice for audiobooks
const narrator = new TTSEmbeddingElement(
'audiobook-narrator-001',
'Chapter 1: The Beginning of an Adventure'
);
// Custom voice for accessibility
const accessibilityVoice = new TTSEmbeddingElement(
'user-preferred-voice',
'Your document has been saved successfully.'
);
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">'
Renders the TTS embedding element as an SSML XML string.
Generates the Azure-specific <mstts:ttsembedding>
element with the speakerProfileId
attribute referencing the custom speaker profile. The text content is automatically
escaped to prevent XML injection and ensure valid output. The rendered element instructs
the speech synthesizer to use the specified custom voice profile for the enclosed text.
The XML string representation of the TTS embedding element in the format:
<mstts:ttsembedding speakerProfileId="id">text</mstts:ttsembedding>
// Simple text
const simple = new TTSEmbeddingElement('profile-001', 'Hello world');
console.log(simple.render());
// Output: <mstts:ttsembedding speakerProfileId="profile-001">Hello world</mstts:ttsembedding>
// With special characters (automatically escaped)
const special = new TTSEmbeddingElement(
'profile-002',
'Terms & "conditions" apply'
);
console.log(special.render());
// Output: <mstts:ttsembedding speakerProfileId="profile-002">Terms & "conditions" apply</mstts:ttsembedding>
// Long profile ID
const longId = new TTSEmbeddingElement(
'enterprise-voice-profile-abc123-def456-ghi789',
'Corporate announcement'
);
console.log(longId.render());
// Output: <mstts:ttsembedding speakerProfileId="enterprise-voice-profile-abc123-def456-ghi789">Corporate announcement</mstts:ttsembedding>
// Multi-line text
const multiline = new TTSEmbeddingElement(
'narrator-voice',
'First line.\nSecond line.'
);
console.log(multiline.render());
// Output: <mstts:ttsembedding speakerProfileId="narrator-voice">First line.\nSecond line.</mstts:ttsembedding>
SSML element for using custom speaker profiles in text-to-speech (Azure-specific).
The
<mstts:ttsembedding>
element enables the use of custom speaker profiles for speech synthesis. This Azure Speech Service specific feature allows you to create personalized voices by training a custom speaker model and then using that model to synthesize speech. The element references a pre-trained speaker profile ID that contains the voice characteristics to be applied to the text.This feature is particularly useful for creating consistent brand voices, personalizing virtual assistants, or maintaining voice consistency across different applications. The speaker profile must be created and trained using Azure's Custom Neural Voice service before it can be referenced in SSML documents.
Example
Remarks
See