UNPKG

epubjs

Version:

Render ePub documents in the browser, across many devices

62 lines (59 loc) 4.59 kB
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE 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_2.html" /><link rel="next" href="./ch03s03_4.html" /></head><body> <p data-origPath="/html/body/section/section[1]/p[6]">The <code class="literal">version</code> and <code class="literal">xmlns</code> namespace declaration attributes are static values, so nothing exciting to see there, as usual. The <code class="literal">xml:lang</code> attribute, however, is required, and must reflect the language of the entries contained in the lexicon. Here we’re declaring that all the entries are in English.</p> <p data-origPath="/html/body/section/section[1]/p[7]">The root would normally contain many more <code class="literal">lexeme</code> elements than in this example, as each defines the word(s) the rule applies to in the child <code class="literal">grapheme</code> element(s). (Graphemes, of course, don’t have to take the form of words, but for simplicity of explanation I’ll stick to the general concept.) When the string is matched, the pronunciation in the <code class="literal">phoneme</code> element gets rendered in place of the default rendering the engine would have performed.</p> <p data-origPath="/html/body/section/section[1]/p[8]">Or, if it helps conceptualize, when the word “acetaminophen” is encountered in the prose, before passing the word to the rendering engine to voice, an internal lookup of the defined graphemes occurs. Because we’ve defined a match, the phoneme and the alphabet it adheres to are swapped in instead for voicing.</p> <p data-origPath="/html/body/section/section[1]/p[9]">That you can include multiple graphemes may not seem immediately useful, but it enables you to create a single entry for regional variations in spelling, for example. British and American variants of “defense” could be defined in a single rule as:</p> <pre class="screen" data-origPath="/html/body/section/section[1]/pre[2]">&lt;lexeme&gt; &lt;grapheme&gt;defense&lt;/grapheme&gt; &lt;grapheme&gt;defence&lt;/grapheme&gt; &lt;phoneme&gt;dI'fEns&lt;/phoneme&gt; &lt;/lexeme&gt;</pre> <p data-origPath="/html/body/section/section[1]/p[10]">It is similarly possible to define more than one pronunciation by adding multiple <code class="literal">phoneme</code> elements. We could add the IPA spelling to the last example as follows, in case reading systems end up only supporting one or the other alphabet:</p> <pre class="screen" data-origPath="/html/body/section/section[1]/pre[3]">&lt;lexeme&gt; &lt;grapheme&gt;defense&lt;/grapheme&gt; &lt;grapheme&gt;defence&lt;/grapheme&gt; &lt;phoneme&gt;dI'fEns&lt;/phoneme&gt; &lt;phoneme alphabet="ipa"&gt;dɪˈfɛns&lt;/phoneme&gt; &lt;/lexeme&gt;</pre> <p data-origPath="/html/body/section/section[1]/p[11]">The <code class="literal">alphabet</code> attribute on the new <code class="literal">phoneme</code> element is required because its spelling doesn’t conform to the default defined on the root. If the rendering engine doesn’t support X-SAMPA, it could now possibly make use of this embedded IPA version instead.</p> <p data-origPath="/html/body/section/section[1]/p[12]">The phoneme doesn’t have to be in another alphabet, however; you could add a regional dialect as a secondary pronunciation, for example. The specification unfortunately doesn’t provide any mechanisms to indicate why you’ve included such additional pronunciations or when they should be used, so there’s not much value in doing so at this time.</p> <p data-origPath="/html/body/section/section[1]/p[13]">There’s much more to creating PLS files than can be covered here, of course, but you’re now versed in the basics and ready to start compiling your own lexicons. You only need to attach your PLS file to your publication to complete the process of enhancing your ebook.</p> </body> </html>