epubjs
Version:
Render ePub documents in the browser, across many devices
93 lines (88 loc) • 5.54 kB
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Tell It Like It Is: Text-to-Speech (TTS)</title>
<link rel="stylesheet" type="text/css" href="css/epub.css" />
<link rel="stylesheet" media="speech" href="css/synth.css" />
<link rel="pronunciation" href="lexicon/en.pls" type="application/pls+xml" hreflang="en" />
<link rel="pronunciation" href="lexicon/fr.pls" type="application/pls+xml" hreflang="fr" />
<meta name="dat-origPath" value="/html/body/section/section[1]" /><link rel="prev" href="./ch03s03_3.html" /><link rel="next" href="./ch03s03_5.html" /></head><body>
<p data-origPath="/html/body/section/section[1]/p[14]">The first step is to include an entry for the PLS file in the EPUB manifest:</p>
<pre class="screen" data-origPath="/html/body/section/section[1]/pre[4]"><item href="lexicon.pls" id="pls" media-type="application/pls+xml"/></pre>
<p data-origPath="/html/body/section/section[1]/p[15]">The <code class="literal">href</code> attribute defines the location of the file
relative to the package document and the <code class="literal">media-type</code> attribute value “application/pls+xml” identifies to a
reading system that we’ve attached a PLS file.</p>
<p data-origPath="/html/body/section/section[1]/p[16]">Including one or more PLS files does not mean they apply by default to all your
content, however; in fact, they apply to none of it by default. You next have to
explicitly tie each PLS lexicon to each XHTML content document it is to be used
with by adding a <code class="literal">link</code> element to the document’s
header:</p>
<pre class="screen" data-origPath="/html/body/section/section[1]/pre[5]"><html …>
<head>
…
<link
rel="pronunciation"
href="lexicon.pls"
type="application/pls+xml"
hreflang="en" />
…
</head>
…
</html></pre>
<p data-origPath="/html/body/section/section[1]/p[17]">There are a number of differences between the declaration for the PLS file in the
publication manifest above and in the content file here. The first is the use of
the <code class="literal">rel</code> attribute to include an explicit
relationship (that the referenced file represents pronunciation information).
This attribute represents somewhat redundant information, however, since the
media type is once again specified (here in the <code class="literal">type</code> attribute). But as it is a required attribute in HTML5, it
can’t be omitted.</p>
<p data-origPath="/html/body/section/section[1]/p[18]">The HTML <code class="literal">link</code> element also includes an additional
piece of information to allow selective targeting of lexicons: the <code class="literal">hreflang</code> attribute. This attribute specifies the
language to which the included pronunciations apply. For example, if you have an
English document (as defined in the <code class="literal">xml:lang</code>
attribute on the html <code class="literal">root</code> element) that embeds
French prose, you could include two lexicon files:</p>
<pre class="screen" data-origPath="/html/body/section/section[1]/pre[6]"><link
rel="pronunciation"
href="lexicon/en.pls"
type="application/pls+xml"
hreflang="en" />
<link
rel="pronunciation"
href="lexicon/fr.pls"
type="application/pls+xml"
hreflang="fr" /></pre>
<p data-origPath="/html/body/section/section[1]/p[19]">Assuming all your French passages have <code class="literal">xml:lang</code>
attributes on them, the reading system can selectively apply the lexicons to
prevent any possible pronunciation confusion:</p>
<pre class="screen" data-origPath="/html/body/section/section[1]/pre[7]"><p>It's the Hunchback of <i xml:lang="fr"><span xml:lang="fr">Notre Dame</span></i> not of Notre Dame.</p></pre>
<p data-origPath="/html/body/section/section[1]/p[20]">A unilingual person reading this prose probably would not understand the
distinction being made here: that the French pronunciation is not the same as
the Americanization. Including separate lexicons by language, however, would
ensure that readers would hear the Indiana university name differently than the
French cathedral if they turn on TTS:</p>
<pre class="screen" data-origPath="/html/body/section/section[1]/pre[8]"><lexicon
version="1.0"
alphabet="x-sampa"
xml:lang="en"
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon">
<lexeme>
<grapheme>Notre Dame</grapheme>
<phoneme>noUt@r 'deIm</phoneme>
</lexeme>
</lexicon>
<lexicon
version="1.0"
alphabet="x-sampa"
xml:lang="fr"
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon">
<lexeme>
<grapheme><span xml:lang="fr">Notre Dame</span></grapheme>
<phoneme>n%oUtr@ d"Am</phoneme>
</lexeme>
</lexicon></pre>
<p data-origPath="/html/body/section/section[1]/p[21]">When the contents of the <code class="literal">i</code> tag are encountered, and
identified as French, the pronunciation from the corresponding lexicon gets
applied instead of the one from the default English lexicon.</p>
</body>
</html>