Specification for Spoken Presentation in HTML

W3C Editor's Draft

More details about this document
This version:
https://w3c.github.io/pronunciation/technical-approach
Latest published version:
https://www.w3.org/TR/spoken-html/
Latest editor's draft:
https://w3c.github.io/pronunciation/technical-approach
History:
https://www.w3.org/standards/history/spoken-html
Commit history
Editors:
(Educational Testing Service)
(Educational Testing Service)
(Invited Expert)
(W3C)
Feedback:
GitHub w3c/pronunciation (pull requests, new issue, open issues)

Abstract

Accurate pronunciation by text-to-speech (TTS) synthesis is very important in many contexts, and critical in education, publishing, communication, entertainment, among other domains. TTS has become an important technology for providing access to digital content on the web. Yet there is no way to markup content today that will correctly present TTS generated output across commonly used TTS engines and operating environments.

We identify two markup approaches in this publication to give content authors reliable pronunciation of HTML content regardless of the operating environment (or assistive technology) users might choose to use. Each approach has been demonstrated to yield consistent results. We seek feedback from authors and implementors to help determine which approach should be advanced to normative recommendation status by W3C.

We base each candidate approach on a subset of Speech Synthesis Markup Language (SSML). Our selected subset is carefully chosen to bring consistency and predictability to spoken presentation across a full range of assistive technologies and operating environments. Both technical approaches described in this publication carefully avoid the impasse that has prevented SSML from becoming a native HTML technology and should, therefore, be generally applicable. Either approach described here satisfies our requirements for assistive technologies and will be useful to voice assistants which consume and present HTML content in spoken form. We seek feedback on which approach would prove most implementable across all applications of spoken presentation of web content.

Status of This Document

This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.

This document was published by the Accessible Platform Architectures Working Group as an Editor's Draft.

Publication as an Editor's Draft does not imply endorsement by W3C and its Members.

This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 2 November 2021 W3C Process Document.

1. Introduction

This section is non-normative.

In this First Public Working Draft (FPWD) publication we define two independent approaches for achieving accurate, consistent, and reliable pronunciation by Text-to-Speech (TTS) engines across all operating environments, regardless of any assistive technology also utilized. We are publishing two approaches now in order to obtain feedback from the wider community on which of these two approaches is deemed to be preferable—and why.

Text-to-speech is necessary for people with disabilities and useful for all. Accurate pronunciation is essential in many situations such as in education and educational assessment (testing students). Many computers and mobile devices today have built-in TTS functionality that is also commonly used by people without disabilities in different situations, such as when driving or interacting with personal data assistants.

The W3C's Web Content Accessibility Guidelines (WCAG) emphasize the importance of correct pronunciation.

For example, in the English language heteronyms are words that are spelled the same but have different pronunciations and meanings, such as the words desert (abandon) and desert (arid region). … Additionally, in some languages certain characters can be pronounced in different ways. In Japanese, for example, there are characters like Han characters(Kanji) that have multiple pronunciations. … When read incorrectly, the content will not make sense to users. Understanding Success Criterion 3.1.6: Pronunciation
While WCAG provides numerous workarounds for indicating correct pronunciation, it is nevertheless forced to categorize Success Criterion 3.1.6 as AAA because it cannot point to a reliable technological solution.

The W3C has two mature pronunciation related specifications:

These have long provided technical methods to allow authors to embed pronunciation (and related spoken presentation) markup in their HTML document, but SSML's approach has not been adopted for several technical reasons. Additionally, feedback from various browser and assistive technology vendors has indicated that this is not a likely or viable approach. In our specification therefore, we do not attempt to reinvent this wheel, but rather to bridge the long-standing technical barriers that have prevented use of SSML in HTML. Our approaches rely directly on both specifications, wrapping them as attributes which will be accepted by HTML validation.

As noted we have identified two candidate approaches:

The task force encourages implementors and authors to provide feedback about these approaches. Once analyzed, the feedback will help determine which approach will become the final normative W3C recommendation.

The following sections include example code for each approach. Please refer to the sample content examples, complete with audio files, for comparison with existing TTS technology.

Editor's note
Using the data- prefix to name attributes is not the editors' recommendation or preference. Rather, it is the canonical approach for developing enhancements to HTML as defined in the HTML 5.x specification. This standards-based development approach enables experimental implementations which, in turn, will inform the further development of this specification.

For a more in-depth introduction to pronunciation issues and related W3C documents, please refer to Pronunciation Overview.

2. Internationalization Considerations

A web specification that will contain language specific information must consider internationalization (i18n). HTML specifies the lang attribute which sets the language used for any given content. A speech engine can use this to select an appropriate voice for audible presentation. An example of this might include text like "1". Do we say "one" or "uno?" That would depend on the lang attribute. Text-to-speech (TTS) technology presents the declared language. User preference provides an implicit language when not declared.

This specification augments existing language support giving authors the ability to clarify intent. Authors can declare pronunciation within the expressive capabilities of the TTS engine. Including how TTS engines should pronounce abbreviations, proper nouns, and other ambiguities. For example, "Versailles" has two possible pronunciations. It depends on whether the city in question is in Indiana or France. Regardless of the language context.

Explicit pronunciations can override the presentation of an entire element. Authors should exercise caution when the visual content and aural presentation differ. Consider:

  1. This can cause confusion for TTS users who attempt to separate the parts from the whole.
  2. Searching a document for heard words or phrases may not match content. It would be incumbent of the user agent to allow for this use case.

3. Multi-attribute Approach for Including SSML in HTML

By converting SSML tags and attributes to HTML attributes, authors can embed pronunciation (and related spoken presentation) in their HTML document. Authors can combine most supported tags with each other to apply multiple speech effects.

Most of the markup included in SSML is suitable for use by the majority of content developers; however, some features such as, phoneme and prosody may require specialized knowledge. Publishers in Japan use a similar technique from EPUB 3 for the SSML phoneme element.

Edgar Allen Poe's The Raven:

EXAMPLE 1
<p data-ssml-prosody-rate="slow" data-ssml-prosody-pitch="low">
    Once upon a midnight 
    <span data-ssml-phoneme-alphabet="ipa" data-ssml-phoneme-ph="ˈdrɪəri">dreary</span>
    <span data-ssml-break-time="500ms"></span>,
    while I pondered, weak
    <span data-ssml-break-time="150ms"></span> and weary,<br data-ssml-break-time="500ms" />
    Over many a quaint and curious volume of forgotten
    <span data-ssml-prosody-rate="x-slow" data-ssml-prosody-pitch="low"> lore—</span><br />
    While I nodded, nearly napping, suddenly there came a tapping,
    <br data-ssml-audio-src="/soundlibrary/wood/hits/hits_11" />
    As of some one gently rapping,
    <span data-ssml-audio-src="/soundlibrary/wood/hits/hits_11"></span>
    rapping at my chamber door.
    <span data-ssml-audio-src="/soundlibrary/wood/hits/hits_11"></span>
    <br data-ssml-audio-src="/soundlibrary/wood/hits/hits_11" />
    <span data-ssml-prosody-volume="x-soft" data-ssml-prosody-rate="medium">
      "'Tis some visitor,"
    </span>
    I muttered, <span data-ssml-prosody-volume="x-soft" data-ssml-prosody-rate="x-slow">
    <span data-ssml-phoneme-alphabet="ipa" data-ssem-phoneme-ph="tæpɪŋ">"tapping</span>
    at my chamber door—</span><br data-ssml-break-time="750ms" />
    Only this <span data-ssml-break-strength="weak"></span> and nothing
    <span data-ssml-break-strength="none"></span>
    <span data-ssml-prosody-volume="soft" data-ssml-prosody-rate="75%"> more."</span>
</p>

3.1 The data-ssml-* Multi-Attribute Set

These attributes provide functional equivalence to the SSML counterparts. These attributes are valid on the following HTML elements:

3.1.1 data-ssml-say-as(-*)

Allows the author to classify the element's text content. The attributes are derived from the SSML say-as element and associated properties.

Editor's note
interpret-as seems superfluous, and should be implied

data-ssml-say-as

Values: date | time | telephone | characters | cardinal | ordinal

data-ssml-say-as-format (optional)

Value: time/date format as defined in W3C Note, SSML say-as attribute values. SSML 1.0 say-as attribute

data-ssml-say-as-detail (optional)

Value: detail as defined in W3C Note, SSML say-as attribute values. SSML 1.0 say-as attribute

Editor's note
The data-ssml-say-as-detail attribute allows authors to target implementation-specific TTS engine features or behavior.
EXAMPLE 2
According the 2010 US Census, the population of <span data-ssml-say-as='characters'>90274</span>
increased to 25209 from 24976 over the past 10 years.

3.1.2 data-ssml-phoneme-*

Defines two required attributes for phonemic/phonetic pronunciation. The element with the phoneme attributes can only contain text (no elements). The attributes are derived from the SSML phoneme element and associated properties.

data-ssml-phoneme-ph

Value: The phoneme string.

data-ssml-phoneme-alphabet

Values: The phonetic alphabet in use. ipa | x-sampa

EXAMPLE 3
Once upon a midnight <span data-ssml-alphabet="ipa" data-ssml-phoneme-ph="ˈdrɪəri">dreary</span>

3.1.3 data-ssml-sub-alias

A string value that replaces the text content for pronunciation. While similar to aria-label, alias does not alter spelling (i.e., a Braille display). Additionally, the alias attribute can be used by TTS technologies that do not access the accessibility tree. The processor should apply text normalization to the alias value. The attribute is derived from the SSML sub element and associated properties.

Value: text string to be substituted and delivered to the TTS for presentation.

EXAMPLE 4
<span data-ssml-sub-alias="Sodium Chloride">NaCL</span>

3.1.4 data-ssml-voice-*

A set of attributes defining production values that requests a change in speaking voice. There are two kinds of attributes for the voice element: those that indicate desired features of a voice and those that control behavior. The attributes are derived from the SSML voice element and associated properties.

data-ssml-voice-gender (optional)

Values: female | male | neutral

data-ssml-voice-age (optional)

Value: integer corresponding to age in years

data-ssml-voice-variant (optional)

Value: integer indicating a numeric voice variant

data-ssml-voice-name (optional)

Values: specific voice name requested from the current TTS engine (e.g., "David").

data-ssml-voice-languages (optional)

Value: string a space delimited list of one or more languages to be spoken by this voice.

Editor's note
The data-ssml-voice-languages attribute only assists the TTS engine with selecting the appropriate voice. It does not indicate the language of content. To specify language, use the HTML lang attribute.
EXAMPLE 5
She said, "<span data-ssml-voice-gender="female">My name is Marie</span>".

3.1.5 data-ssml-emphasis-level

Requests that the text content be spoken with emphasis (also referred to as prominence or stress). This is a single attribute and is derived from the SSML emphasis element and associated properties.

Values: strong | moderate | none | reduced

EXAMPLE 6
Please use <span data-ssml-emphasis-level="strong">extreme caution.</span>

3.1.6 data-ssml-break-*

Describes the timing associated with an empty element to control the pausing or other prosodic boundaries between tokens. The use of the break attribute between any pair of tokens is optional. If the element is not present between tokens, the synthesis processor is expected to automatically determine a break based on the linguistic context. The attributes are derived from the SSML break element and associated properties.

data-ssml-break-strength

Values: none | x-weak | weak | medium (default) | strong | x-strong

data-ssml-break-time

Value: string containing a time duration expressed in numeric form as "250ms", "1s", etc.

EXAMPLE 7
Take a deep breath,<span data-ssml-break-time="1s"></span> and exhale.

3.1.7 data-ssml-prosody-*

Permits control of the pitch, speaking rate and volume of the speech output. The attributes are derived from the SSML prosody element and associated properties.

data-ssml-prosody-pitch (optional)

Values: frequency-value"Hz" | +/- change value | "x-low" | "low" | "medium" | "high" | "x-high" | "default"

data-ssml-prosody-contour (optional)

Value: string of contour change parameters as defined in the SSML 1.1 recommendation.

data-ssml-prosody-range (optional)

Value: string range value as defined in the SSML 1.1 recommendation.

data-ssml-prosody-rate (optional)

Values: non-negative-percentage% | "x-slow" | "slow" | "medium" | "fast"| "x-fast" | "default"

data-ssml-prosody-duration (optional)

Value: string containing a time duration (e.g., "250ms", "1s", etc.).

data-ssml-prosody-volume (optional)

Values: +/- soundlevel>"dB" | "silent" | "x-soft" | "soft" | "medium" | "loud" | "x-loud" | "default"

EXAMPLE 8
The tortoise, said (slowly) "<span data-ssml-prosody-rate="x-slow">
I am almost at the finish line</span>."

3.1.8 data-ssml-audio-*

Supports the insertion of recorded audio files in conjunction with synthesized speech output. The element may be empty. If the element is not empty, then the contents should be spoken if the audio document is not available. The attributes are derived from the SSML audio element and associated properties.

data-ssml-audio-src

Value: The URI of a document with an appropriate media file.

data-ssml-audio-fetchtimeout (optional)

Value: string containing a time duration (e.g., "250ms", "1s", etc.).

data-ssml-audio-fetchint (optional)

Values: safe | prefetch

data-ssml-audio-maxage (optional)

Value: string

data-ssml-audio-maxstale (optional)

Value: string

data-ssml-audio-clipBegin (optional)

Value: string containing a time duration (e.g., "250ms", "1s", etc.).

data-ssml-audio-clipEnd (optional)

Value: string containing a time duration (e.g., "250ms", "1s", etc.).

data-ssml-audio-repeatCount (optional)

Value: integer indicating the number of times to repeat the audio clip.

data-ssml-audio-repeatDur (optional)

Value: string containing a time duration (e.g., "250ms", "1s", etc.).

EXAMPLE 9
You will hear a brief chime <span data-ssml-audio-src="/audio/chime.ogg"></span> 
when your time is up.

4. Single-attribute Approach for Including SSML in HTML

By converting SSML tags and attributes into a single HTML attribute with a JSON string value, authors can embed pronunciation (and related spoken presentation) in their HTML document. Authors can combine most supported tags with each other to apply multiple speech effects.

Most of the markup included in SSML is suitable for use by the majority of content developers; however, some features such as, phoneme and prosody may require specialized knowledge. This approach emerged as a means to transform content conforming to the IMS Question & Test Interoperability (QTI) Specification. The QTI standard supports inclusion of SSML in HTML for TTS tools used in educational assessment.

Edgar Allen Poe's The Raven:

EXAMPLE 1
<p data-ssml='{"prosody":{"rate":"slow","pitch":"low"}}'>
	Once upon a midnight
        <span data-ssml='{"phoneme":{"alphabet":"ipa","ph":"ˈdrɪəri"}}'>dreary</span>
	<span data-ssml='{"break":{"time":"500ms"}'></span>,
	while I pondered, weak
	<span data-ssml='{"break":{"time":"150ms"}'></span> and weary,
        <br data-ssml='{"break":{"time":"500ms"}' />
	Over many a quaint and curious volume of forgotten 
	<span data-ssml='{"prosody":{"rate":"x-slow","pitch":"low"}}'>lore—</span><br />
	While I nodded, nearly napping, suddenly there came a tapping,
	<br data-ssml='{"audio":{"src":"/soundlibrary/wood/hits/hits_11"}}'/>
	As of some one gently rapping,
	<span data-ssml='{"audio":{"src":"/soundlibrary/wood/hits/hits_11"}}'></span>
	rapping at my chamber door.
	<span data-ssml='{"audio":{"src":"/soundlibrary/wood/hits/hits_11"}}'></span>
	<br data-ssml='{"audio":{"src":"/soundlibrary/wood/hits/hits_11"}}' />
	<span data-ssml='{"prosody":{"volume":"x-soft","rate":"medium"}}'>
          "'Tis some visitor,"
        </span>
	I muttered, <span data-ssml='{"prosody":{"volume":"x-soft","rate":"x-slow"}}'>
	<span data-ssml='{"phoneme":{"alphabet":"ipa","ph":"tæpɪŋ"}}'>"tapping</span>
	at my chamber door—</span><br data-ssml='{"break":{"time":"750ms"}'/>
	Only this<span data-ssml='{"break":{"strength":"weak"}'></span>
	and nothing<span data-ssml='{"break":{"strength":"none"}'> </span>
	<span data-ssml='{"prosody":{"volume":"soft","rate":"75%"}}'>more."</span>
</p>

4.1 data-ssml Attribute, Properties and Values

The following properties are defined and provide functional equivalence to the their SSML counterpart.

The data-ssml provides functional equivalence to SSML. The attribute is valid on the following HTML elements:

The value of the data-ssml attribute is a JSON string, enclosed with single quotes ('), containing a single JSON object representing a specific SSML function with one or more property/value pairs. The valid objects, properties and associated values are defined in the following sections. The JSON schema is presented in Appendix A.

4.1.1 say-as

Allows the author to classify the element's text content. The JSON definition is derived from the SSML say-as element and associated properties.

interpret-as

Value: date | time | telephone | characters | cardinal | ordinal

format (optional)

Value: time/date format as defined in W3C Note SSML say-as attribute values.

detail (optional)

Value: detail as defined in W3C Note SSML say-as attribute values.

Editor's note
The detail property allows authors to target implementation-specific TTS engine features or behavior.
EXAMPLE 2
According the 2010 US Census, the population of 
<span data-ssml='{"say-as":{"interpret-as":"characters"}}'>90274</span>
increased to 25209 from 24976 over the past 10 years.

4.1.2 phoneme

Defines two required attributes for phonemic/phonetic pronunciation. The element with the phoneme attributes can only contain text (no elements). The JSON definition is derived from the SSML phoneme element and associated properties.

ph

Value: string containing the phonetic characters corresponding to the content to be spoken

data-ssml-phoneme-alphabet

Value: ipa | x-sampa defining the phonetic alphabet used for the ph string

EXAMPLE 3
Once upon a midnight 
<span data-ssml='{"phoneme":{"alphabet":"ipa","ph":"ˈdrɪəri"}}'>dreary</span>

4.1.3 sub

Indicates that the text in the alias attribute value replaces the text content for pronunciation. The required alias property specifies the string to be spoken instead of the text content. The processor should apply text normalization to the alias value. The JSON definition is derived from the SSML sub element and associated properties.

alias

Value: string containing the text to be spoken as a substitution for the text content of the element to which sub is applied.

EXAMPLE 4
<span data-ssml='{"sub":{"alias":"Sodium Chloride"}}'>NaCL</span>

4.1.4 voice

Requests a change in speaking voice. There are two kinds of attributes for voice: those that indicate desired features of a voice and those that control behavior. The JSON definition is derived from the SSML voice element and associated properties.

gender (optional)

Values: female | male | neutral

age (optional)

Value: integer corresponding to age in years

variant (optional)

Value: integer indicating a numeric voice variant

name (optional)

Value: string defining a specific voice name requested from the current TTS engine, e.g., "Microsoft David (English)"

languages (optional)

Value: string a space delimited list of one or more languages to be spoken by this voice.

Editor's note
The voice > languages property only assists the TTS engine with selecting the appropriate voice. It does not indicate the language of content. To specify language, use the HTML lang attribute.
EXAMPLE 5
She said, "<span data-ssml='{"voice":{"gender":"female"}}'>My name is Marie</span>".

4.1.5 emphasis

Requests that the text content of the element to which emphasis spoken with emphasis (also referred to as prominence or stress). The JSON definition is derived from the SSML emphasis element and associated properties.

level

Value: strong | moderate | none | reduced

EXAMPLE 6
Please use <span data-ssml='{"emphasis":{"level":"strong"}}'>extreme caution.</span>

4.1.6 break

Describes the timing associated with an empty element to control the pausing or other prosodic boundaries between tokens. The use of the break between any pair of tokens is optional. If the element is not present between tokens, the synthesis processor is expected to automatically determine a break based on the linguistic context. The JSON definition is derived from the SSML break element and associated properties.

strength

Value: none | x-weak | weak | medium (default) | strong | x-strong

time

Value: string containing a time duration expressed in numeric form as "250ms", "1s", etc. (s=second, ms=milliseconds)

EXAMPLE 7
Take a deep breath,<span data-ssml='{"break":{"time":"1s"}}'></span> and exhale.

4.1.7 prosody

Permits control of the pitch, speaking rate and volume of the speech output. The object has six properties. The JSON definition is derived from the SSML prosody element and associated properties.

pitch

Value: frequency-value"Hz" | +/- change value | "x-low" | "low" | "medium" | "high" | "x-high" | "default"

contour

Value: string of contour change parameters as defined in the SSML 1.1 recommendation

range

Value: string range value as defined in the SSML 1.1 recommendation

rate

Values: non-negative-percentage% | "x-slow" | "slow" | "medium" | "fast"| "x-fast" | "default"

duration

Value: string containing a time duration expressed in numeric form as "250ms", "1s", etc.

volume

Values: +/- soundlevel>"dB" | "silent" | "x-soft" | "soft" | "medium" | "loud" | "x-loud" | "default"

EXAMPLE 8
The tortoise, said (slowly) "
<span data-ssml='{"prosody":{"rate":"x-slow"}}'>I am almost at the finish line</span>."

4.1.8 audio

Supports the insertion of recorded audio files in conjunction with synthesized speech output. The element may be empty. If the element is not empty, then the contents should be the text to be spoken if the audio document is not available. The JSON definition is derived from the SSML audio element and associated properties.

src

Value: The URI of a document with an appropriate media file.

fetchtimeout

Value: string containing a time duration expressed in numeric form as "250ms", "1s", etc.

fetchint

Value: safe | prefetch

maxage

Value: string

maxstale

Value: string

clipBegin

Value: string containing a time duration expressed in numeric form as "250ms", "1s", etc.

clipEnd

Value: string containing a time duration expressed in numeric form as "250ms", "1s", etc.

repeatCount

Value: integer indicating the number of times to repeat the audio clip.

repeatDur

Value: string containing a time duration expressed in numeric form as "250ms", "1s", etc.

EXAMPLE 9
You will hear a brief chime 
<span data-ssml='{"audio":{"src":"/audio/chime.ogg"}}'></span> when your time is up.

5. Technical Considerations

In each approach, implementers must consume data-ssml- attributes, values, and associated text content to produce a valid format required by the target TTS technology. For instance, if targeting the Web Speech API, an implementation must produce valid SSML. How to determine the text content of each pronunciation function will challenge implementers of either approach.

Following the multi-attribute approach, implementors must find all related attributes and collect them into the proper SSML representation. Implementors must determine how to handle authoring errors such as missing required attributes, conflicting functions, or invalid values.

Following the single-attribute approach, implementors must parse JSON string values. No existing W3C recommendation uses JSON strings as attribute values in HTML, but there is evidence of its use for custom applications using the data- attribute.

JSON has potential security concerns, and the impact of malformed JSON strings resulting from errors in authoring is among issues that need wider review. Implementors must determine how to handle malformed JSON as well as incorrect property and value combinations. The use of JSON schemas could help authors and implementors of the single-attribute approach.

While a JSON schema is proposed, there are potentially related standards, such as SpeakableSpecification, in development. Converting SSML to a proper JSON schema could cause confusion for implementers and authors. Often such conversions are "...not exactly 1:1 transformation, but very very close". Authoring tools are hypothesized to address these concerns, by eliminating the need for authors to directly write JSON.

A. SSML JSON Schema

Please see the JSON schema example here.

B. Acknowledgments

This section is non-normative.

The following people contributed to the development of this document.

B.1 Participants active in the Pronunciation TF at the time of publication