<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Elsewhere</title>
    <description>The latest articles on DEV Community by Elsewhere (listenelsewhere).</description>
    <link>https://dev.to/listenelsewhere</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F16221%2Fc8ad6637-1e58-4d11-a58b-ddb38d0b90f0.png</url>
      <title>DEV Community: Elsewhere</title>
      <link>https://dev.to/listenelsewhere</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/listenelsewhere"/>
    <language>en</language>
    <item>
      <title>Underlining the spoken word without touching the book's HTML</title>
      <dc:creator>Ishaan Verma</dc:creator>
      <pubDate>Fri, 20 Nov 2026 11:29:06 +0000</pubDate>
      <link>https://dev.to/listenelsewhere/underlining-the-spoken-word-without-touching-the-books-html-2kmh</link>
      <guid>https://dev.to/listenelsewhere/underlining-the-spoken-word-without-touching-the-books-html-2kmh</guid>
      <description>&lt;p&gt;Hi, I'm Ishaan. I make Elsewhere, a reader that reads a book aloud and underlines each word as it is spoken. This post is about one decision the whole read-along rests on: the book's own markup is never changed to show where the voice is.&lt;/p&gt;

&lt;h2&gt;
  
  
  The obvious way, and why I dropped it
&lt;/h2&gt;

&lt;p&gt;The obvious idea is to wrap each word in a span and swap a class on the current one. For a novel that is thousands of extra elements, and the book's own HTML is no longer the book's own HTML. A span can change line breaks, break a footnote link, or interfere with how the publisher styled a paragraph. And the word changes several times a second, so every change means touching the tree and hoping the layout holds still.&lt;/p&gt;

&lt;p&gt;I wanted the text to stay exactly where the author's markup put it, so a line never jumps because a word got underlined.&lt;/p&gt;

&lt;h2&gt;
  
  
  Highlights that live outside the DOM
&lt;/h2&gt;

&lt;p&gt;The CSS Custom Highlight API lets you register a Range and style it from CSS, with no element wrapped around it. You make a &lt;code&gt;Highlight&lt;/code&gt;, put it in &lt;code&gt;CSS.highlights&lt;/code&gt; under a name, and style that name with &lt;code&gt;::highlight()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The spoken word is one name, and the stylesheet gives it an underline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nf"&gt;highlight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;narration-word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;text-decoration-line&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;underline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;text-decoration-thickness&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nl"&gt;text-underline-offset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.22em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I use an underline in the accent colour, so it still reads for someone who cannot tell the colours apart. And there is no transition. It moves with the voice instead of easing after it.&lt;/p&gt;

&lt;p&gt;Painting is a few lines, trimmed here from what I run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;highlight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Highlight&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;range&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;highlight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;priority&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;WORD_PRIORITY&lt;/span&gt;
&lt;span class="no"&gt;CSS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;highlights&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'narration-word'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;highlight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same mechanism paints the sentence being read, the dimmer text around it, and the colours a reader picks when they mark a passage. None of them add a node to the page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding the Range for a word
&lt;/h2&gt;

&lt;p&gt;Each narrated passage comes with a start and end character for every word. A frame loop asks the audio element for its current time, looks up the word with a binary search, and turns that word's character offsets into a Range over the text nodes on screen.&lt;/p&gt;

&lt;p&gt;Two details cost me an afternoon each.&lt;/p&gt;

&lt;p&gt;One, the audible start of a word comes a little before the time stored for it. I measured about 40 ms on average, so the lookup adds 60 ms of lead and the underline lands on the word you are hearing.&lt;/p&gt;

&lt;p&gt;Two, the Range is attached to text nodes, and the framework that renders the page will sometimes rewrite those nodes when the sentence highlight moves on. A Range can then collapse or slide onto other characters. So on each frame I compare the Range's text with the text it was painted over, and paint it again if they differ.&lt;/p&gt;

&lt;h2&gt;
  
  
  A priority bug I did not expect
&lt;/h2&gt;

&lt;p&gt;The spoken word sits inside the sentence being narrated, and both are highlights. In Safari, the highest-priority highlight over a stretch of text decides its decoration outright. At the default priority the word's underline lost to the sentence's and never showed. Giving the word the top priority fixed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pausing and tabs
&lt;/h2&gt;

&lt;p&gt;The loop runs while audio plays and the tab is visible, and it cancels its frame on every way out. Paused, the word is painted once, and again after each seek, so it is never stale. Where a browser lacks the API, nothing is painted and the book still reads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;You can watch the underline move without making an account at &lt;a href="https://listenelsewhere.com/try" rel="noopener noreferrer"&gt;https://listenelsewhere.com/try&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Plainly, so nobody wastes an evening: Elsewhere opens DRM-free files, so Kindle store books will not open. The voice is a neural voice, not a human narrator. The tab has to stay open while narration is being made, and the app needs a connection (an exported audiobook plays offline).&lt;/p&gt;

&lt;p&gt;I would like to hear from you. If you have used the Custom Highlight API, did you hit the priority quirk too, or find another way to keep a moving mark out of the DOM?&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>Running Piper text-to-speech in the browser with WebAssembly</title>
      <dc:creator>Ishaan Verma</dc:creator>
      <pubDate>Tue, 17 Nov 2026 22:18:45 +0000</pubDate>
      <link>https://dev.to/listenelsewhere/running-piper-text-to-speech-in-the-browser-with-webassembly-n7g</link>
      <guid>https://dev.to/listenelsewhere/running-piper-text-to-speech-in-the-browser-with-webassembly-n7g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Update, 19 November:&lt;/strong&gt; parts of this post are out of date. After I wrote it, I shipped ten English voices that run on the graphics card, on laptops and iPads in Chrome or Edge with WebGPU. The first use downloads a 400 MB model, and they do not run on phones. I found a new model that gets me amazing english voices without the same GPU memory hogging problem. The other voices still run on the CPU. The app now also has voices in 23 other languages, so my line below about English-only voices no longer holds.&lt;/p&gt;




&lt;p&gt;I build Elsewhere, a browser-based ebook reader that reads DRM-free books aloud. The voice is made on the reader's own machine, inside the browser tab, with Piper neural voices running through ONNX Runtime Web on its WebAssembly backend. The text is not sent to a cloud speech API.&lt;/p&gt;

&lt;p&gt;This post covers that part: how it is wired, what the thread count turned out to depend on, what the numbers look like, and a WebGPU experiment that stalled my laptop. &lt;/p&gt;

&lt;h3&gt;
  
  
  How it is wired
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;ONNX Runtime Web runs the Piper model on its WASM backend.&lt;/li&gt;
&lt;li&gt;eSpeak NG turns the text into phonemes first.&lt;/li&gt;
&lt;li&gt;One speech worker holds one voice. Switching voice terminates that worker and starts another.&lt;/li&gt;
&lt;li&gt;ONNX Runtime starts its own threads inside the worker.&lt;/li&gt;
&lt;li&gt;A second, long-lived worker encodes MP3. More on that below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Threads only exist if the page is cross-origin isolated
&lt;/h3&gt;

&lt;p&gt;ONNX Runtime's WASM backend gets its extra threads from SharedArrayBuffer, and browsers only expose that to cross-origin isolated pages. Until I made the site isolated, there was no SharedArrayBuffer, so ONNX Runtime fell back to one thread.&lt;/p&gt;

&lt;p&gt;The difference was large:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Piper, a 37-second passage with the ljspeech voice: about 2.2 seconds on 4 threads, roughly 17 times real time, and roughly 7 times real time on 1 thread.&lt;/li&gt;
&lt;li&gt;Kokoro q8 on WASM: 0.56 times real time on one thread, 1.17 times on 4.
I used &lt;code&gt;Cross-Origin-Embedder-Policy: require-corp&lt;/code&gt; instead of &lt;code&gt;credentialless&lt;/code&gt;, because Safari only supports &lt;code&gt;require-corp&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The default thread count is the smaller of 4 and half the core count. I tested more on an M3 with 4 performance and 4 efficiency cores. With Kokoro, 4, 6, 7 and 8 threads all landed between 1.11 and 1.13 times real time, so I kept 4. I did not retest Piper at other thread counts, so for Piper I only know that 4 beats 1.&lt;/p&gt;

&lt;h3&gt;
  
  
  Voice files and the first load
&lt;/h3&gt;

&lt;p&gt;Each Piper voice is 63 to 79 MB. The browser downloads it straight from Hugging Face and stores it in the Cache API, in a bucket called &lt;code&gt;piper-voices&lt;/code&gt;. The write is all or nothing. If the reader hits Stop or the connection drops mid-download, no half-written model is left behind to break the next load.&lt;/p&gt;

&lt;p&gt;The first load is the part readers feel:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A real 64 MB download of one voice took 34 seconds on my connection.&lt;/li&gt;
&lt;li&gt;The same size of voice took 9.3 seconds in headless Chrome on a faster connection.&lt;/li&gt;
&lt;li&gt;Once the voice is cached, loading it takes about 0.8 to 1 second.
The reader sees a progress notice during the download, and the Studio stays open while it runs. I have not tested what happens when the browser hits its storage quota or evicts the cache, so I cannot say how often a reader has to download a voice again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The numbers
&lt;/h3&gt;

&lt;p&gt;Speed here means seconds of audio produced per second of generation.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Run&lt;/th&gt;
&lt;th&gt;Setup&lt;/th&gt;
&lt;th&gt;Audio&lt;/th&gt;
&lt;th&gt;Generation time&lt;/th&gt;
&lt;th&gt;Speed&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice in Wonderland, about 27,000 words&lt;/td&gt;
&lt;td&gt;Piper [voice, browser and machine to confirm]&lt;/td&gt;
&lt;td&gt;2 h 9 min&lt;/td&gt;
&lt;td&gt;13 min&lt;/td&gt;
&lt;td&gt;about 9.9 times&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The Waste Land, chapter I&lt;/td&gt;
&lt;td&gt;Piper, voice Linda&lt;/td&gt;
&lt;td&gt;about 4 min&lt;/td&gt;
&lt;td&gt;about 25 s&lt;/td&gt;
&lt;td&gt;about 9.6 times&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The Waste Land, chapter I&lt;/td&gt;
&lt;td&gt;Kokoro q4 on the CPU&lt;/td&gt;
&lt;td&gt;210 s&lt;/td&gt;
&lt;td&gt;about 130 s&lt;/td&gt;
&lt;td&gt;about 1.6 times&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One 37 s passage&lt;/td&gt;
&lt;td&gt;Piper ljspeech, 4 threads&lt;/td&gt;
&lt;td&gt;37 s&lt;/td&gt;
&lt;td&gt;2.2 s&lt;/td&gt;
&lt;td&gt;about 17 times&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One 37 s passage&lt;/td&gt;
&lt;td&gt;Piper ljspeech, 1 thread&lt;/td&gt;
&lt;td&gt;37 s&lt;/td&gt;
&lt;td&gt;not recorded&lt;/td&gt;
&lt;td&gt;about 7 times&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;What I have not measured: any phone, battery use, and Firefox. Safari works and so does Chrome. The only memory figure I have is for Kokoro, which uses about 1.3 GB per tab. Treat the table as results from my machine and nothing more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Word timing and the MP3 worker
&lt;/h3&gt;

&lt;p&gt;The read-along needs to know when each word is spoken. I patch the model in the browser to expose its phoneme durations, which costs 4 to 12 ms per model. That meant I did not need to host patched copies of the voices.&lt;/p&gt;

&lt;p&gt;The second worker exists because of a measurement. I first encoded MP3 on the main thread with lamejs, which took about 90 ms per 10 seconds of audio. That was enough to make scrolling hitch. A single long-lived worker now does all the encoding.&lt;/p&gt;

&lt;h3&gt;
  
  
  The WebGPU detour
&lt;/h3&gt;

&lt;p&gt;Piper is the voice that I shipped. Before that I tried a bigger model, Kokoro, and tried to run it on WebGPU. I never tried Piper on WebGPU. I assumed the dynamic shapes in VITS made it a poor fit, and the CPU was already fast enough.&lt;/p&gt;

&lt;p&gt;My machine was a MacBook with an M3, 8 cores and 16 GB of unified memory. Kokoro fp32 on WebGPU ran at about 2.5 times real time (14.6 seconds for the passage), which beats the 1.17 times I got from the q8 model on 4 CPU threads. It also stalled the desktop.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Memory.&lt;/strong&gt; fp32 took all of the unified memory with no cap and blocked the GPU work that draws the screen. I measured sporadic 1 to 3 second frame stalls. I believe unified memory is the cause, but I never profiled it, so treat that as a guess.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;fp16.&lt;/strong&gt; It produced gibberish.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixes that did not fix it.&lt;/strong&gt; The model already ran in a worker. Recycling it every 6 generations only freed ONNX Runtime's leaked GPU buffer pool. I then offered "Graphics card or Processor" as a setting, and finally removed WebGPU entirely.
The processor path had no such problem. Across 468 seconds of Kokoro generation, 3 of 33,660 frames took longer than 50 ms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That was not the end of Kokoro. On the CPU, even at q4 (2.15 times real time), readers still waited about 40 seconds for first audio. So, I removed it completely. Could probably offer it in a paid tier as "premium voices" that generates book audio in the cloud. Let's see.&lt;/p&gt;

&lt;h3&gt;
  
  
  What broke along the way
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A leak I introduced.&lt;/strong&gt; The shared worker built a second ONNX session for a voice it already held, so it leaked one model per chapter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A load that did nothing.&lt;/strong&gt; An earlier design ignored the load call once any model was loaded. A second run on a different backend kept the first model with no indication.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safari and streams.&lt;/strong&gt; Safari cannot iterate a stream with &lt;code&gt;for await&lt;/code&gt;, which broke the unzip step inside the phonemizer. I fixed it at bundle time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;int8 quantization.&lt;/strong&gt; It shrank a voice by about 3 times and made it 2.5 to 3 times slower, so I did not use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Limits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The tab has to stay open while narration is made.&lt;/li&gt;
&lt;li&gt;The voices are English only.&lt;/li&gt;
&lt;li&gt;I have never timed a phone run, so I will not claim that it works well on a phone.&lt;/li&gt;
&lt;li&gt;The timings come from one M3 laptop and a few runs. Treat them as a starting point.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Try it
&lt;/h3&gt;

&lt;p&gt;Disclosure: I built Elsewhere, the app I mention here. It opens DRM-free ebooks, so Kindle store books will not open. The code is closed source and will stay that way. You can hear the voice and the read-along without an account at &lt;a href="https://listenelsewhere.com/try" rel="noopener noreferrer"&gt;listenelsewhere.com/try&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A question for anyone who has tried it: has a VITS-style model with dynamic shapes run on WebGPU for you without starving the desktop on a unified-memory machine? I gave up on it, and I would like to know if I gave up too early.&lt;/p&gt;

</description>
      <category>webassembly</category>
      <category>showdev</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
