"lexicon" Element

Description

Sets the location of the user-defined pronunciation dictionary.

A lexicon file is an XML file following the PLS specification (http://www.w3.org/TR/pronunciation-lexicon/).

Syntax

<lexicon
  uri = "URI"
  type = "application/pls+xml"
  xml:lang = "locale"
  xml:id = "reference_id"
/>

Attributes

AttributeDescription
uriURI of the dictionary. Mandatory field.
typeMedia type of the dictionary. Optional field.
xml:langLocale. Optional field.
xml:idMay be used to give the lexicon reference an identifier that is unique to the document, allowing the element to be specified via the <lookup> ref attribute as shown in the examples below. This is an SSML 1.1 extension.

Parent

<speak>

Children

None.

Limitations/Restrictions

The lexicon element is not supported when using TTS2 voices.

Lexicons of types other than application/pls+xml are not supported. The lexicon element must have a uri attribute specifying a URI that identifies the location of the pronunciation lexicon document. This location may utilize the optional xml:base attribute specified in the speak element (see examples below).

PLS lexicon files are loaded separately for each synthesized SSML document. The only lexicons loaded are the ones declared by a <lexicon> element.

The Text-To-Speech engine supports PLS 1.0 lexicons referenced from SSML documents, as defined by Pronunciation Lexicon Specification (PLS) Version 1.0, W3C Recommendation 14 October 2008, http://www.w3.org/TR/2008/REC-pronunciation-lexicon-20081014/.

The platform supports both SSML 1.0 and an extension to the SSML 1.1 standard for lexicon references as shown in the examples below. The corresponding SSML 1.1 <lookup> element is also supported (with corresponding ref attribute), also as shown below.

Example: SSML 1.0 style, local file reference to lexicon

<?xml version="1.0"?>

<speak version="1.0">
    <!-- references the file "/opt/lexicons/general.pls" -->
    <lexicon uri="file:///opt/lexicons/general.pls" />
    <voice name="Amanda" xml:lang="en-US">
        <s>Capacity has been recognized as a leading innovator of speech
        technology since <say-as interpret-as="date"
        format="year">2001</say-as>.</s>
    </voice>
</speak>

Example: SSML 1.1 style, local file reference to lexicon, using lookup element

<?xml version="1.0"?>

<speak version="1.1">
    <!-- references the file "/opt/lexicons/general.pls" -->
    <lexicon uri="file:///opt/lexicons/general.pls" xml:id="general"/>
    <lookup ref="general">
    <voice name="Amanda" xml:lang="en-US">
        <s>Capacity has been recognized as a leading innovator of speech
        technology since <say-as interpret-as="date"
        format="year">2001</say-as>.</s>
    </voice>
    </lookup>
</speak>

Example: SSML 1.1 style, xml:base specifying lexicon folder

<?xml version="1.0"?>

<speak version="1.1" xml:base="file:///opt/lexicons/">
    <!-- references the file "general.pls" in folder "/opt/lexicons/" -->
    <lexicon uri="general.pls" xml:id="general"/>
    <lookup ref="general">
    <voice name="Amanda" xml:lang="en-US">
        <s>Capacity has been recognized as a leading innovator of speech
        technology since <say-as interpret-as="date"
        format="year">2001</say-as>.</s>
    </voice>
    </lookup>
</speak>

Example: SSML 1.1 style, xml:base specifying lexicon folder on web server

<?xml version="1.0"?>

<speak version="1.1" xml:base="https://media.example.com/lexicons/">
    <!-- references the file "general.pls" on the web server -->
    <lexicon uri="general.pls" xml:id="general"/>
    <lookup ref="general">
    <voice name="Amanda" xml:lang="en-US">
        <s>Capacity has been recognized as a leading innovator of speech
        technology since <say-as interpret-as="date"
        format="year">2001</say-as>.</s>
    </voice>
    </lookup>
</speak>

Example: SSML 1.0 style, lexicon URI referencing web server (with xml:base)

<?xml version="1.0"?>

<speak version="1.0" xml:base="https://media.example.com/lexicons/">
    <!-- references the file "general.pls" on the web server -->
    <lexicon uri="general.pls" />
    <voice name="Amanda" xml:lang="en-US">
        <s>Capacity has been recognized as a leading innovator of speech
        technology since <say-as interpret-as="date"
        format="year">2001</say-as>.</s>
    </voice>
</speak>

Example: SSML 1.0 style, lexicon URI referencing web server (without xml:base)

<?xml version="1.0"?>

<speak version="1.0">
    <!-- references the file "general.pls" on the web server -->
    <lexicon uri="https://media.example.com/lexicons/general.pls" />
    <voice name="Amanda" xml:lang="en-US">
        <s>Capacity has been recognized as a leading innovator of speech
        technology since <say-as interpret-as="date"
        format="year">2001</say-as>.</s>
    </voice>
</speak>

Example Lexicon

<?xml version="1.0" encoding="UTF-8" ?>
<lexicon version="1.0"
  xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
    http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
  alphabet="x-sampa" xml:lang="en-US">

<lexeme>
 <grapheme>Capacity</grapheme>
 <phoneme>
 k@p"{sIti
 </phoneme>
</lexeme>

<lexeme>
 <grapheme>Cool Guys</grapheme>
 <alias>
 Capacity
 </alias>
</lexeme>

</lexicon>

You can copy this example lexicon as a starting point, but you will need to add your own lexemes to it. For more information on building <phoneme> elements, see the documentation on phonetic alphabets.


Multiple Lexicons in SSML 1.0

To work with multiple different lexicons in a single SSML 1.0 file, separately group the portions of the file according to which lexicon should be used. For example:

<?xml version="1.0"?>
<speak version="1.0">

<!-- first lexicon used in following 'voice' section -->
<lexicon uri="https://media.example.com/lexicons/first_lexicon.pls" />
<voice name="Amanda" xml:lang="en-US">
  <s>Some phrase using words in first lexicon.</s>
</voice>

<!-- second lexicon used in following 'voice' section -->
<lexicon uri="https://media.example.com/lexicons/second_lexicon.pls" />
<voice name="Amanda" xml:lang="en-US">
  <s>Some phrase using words in second lexicon.</s>
</voice>

<!-- third lexicon used in following 'voice' section -->
<lexicon uri="https://media.example.com/lexicons/third_lexicon.pls" />
<voice name="Amanda" xml:lang="en-US">
  <s>Some phrase using words in third lexicon.</s>
</voice>

</speak>

As shown in this example, sections of the file to be synthesized are contained in <voice> tags, each preceded by their corresponding lexicon references.

The most recent lexicon reference is used for each <voice> section. Note that <lexicon> tags must be children of <speak> elements (not within <voice> elements), and <voice> elements should follow after any lexicon definition they use.



Was this article helpful?