<?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: Charles-Antoine Fournel</title>
    <description>The latest articles on DEV Community by Charles-Antoine Fournel (@cfournel).</description>
    <link>https://dev.to/cfournel</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%2Fuser%2Fprofile_image%2F4137573%2Fac45e719-e371-460d-ac7a-93c7388b0718.jpg</url>
      <title>DEV Community: Charles-Antoine Fournel</title>
      <link>https://dev.to/cfournel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cfournel"/>
    <language>en</language>
    <item>
      <title>Running an LLM on an Android phone: memory is the whole problem</title>
      <dc:creator>Charles-Antoine Fournel</dc:creator>
      <pubDate>Sun, 22 Nov 2026 10:14:11 +0000</pubDate>
      <link>https://dev.to/cfournel/running-an-llm-on-an-android-phone-memory-is-the-whole-problem-15go</link>
      <guid>https://dev.to/cfournel/running-an-llm-on-an-android-phone-memory-is-the-whole-problem-15go</guid>
      <description>&lt;p&gt;&lt;em&gt;Onira writes a self-hypnosis session on the phone with a 2-billion-parameter model. Speed turned out to be the easy part.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The short answer.&lt;/strong&gt; A 2B model quantized to 4 bits runs on a mid-range Android phone with about 5 GB of RAM, but only if the weights stay file-backed. Onira uses llama.cpp with the GGUF memory-mapped, generates one 300-500 word block per call while the previous block is narrated, and unloads the model as soon as the last block is written. On a 6 GB Galaxy S20 FE that means about 1.6 GB resident while generating, 0.31 GB of it anonymous, and 111 MB once the model is gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first runtime did not fit
&lt;/h2&gt;

&lt;p&gt;The first version ran stock Gemma 4 E2B through LiteRT-LM on the CPU. That runtime maps the 2.6 GB model file only while loading it, copies the weights into the native heap, then unmaps the file. Anonymous memory cannot be dropped by the kernel, only swapped to zram.&lt;/p&gt;

&lt;p&gt;Measured with &lt;code&gt;/proc/&amp;lt;pid&amp;gt;/smaps&lt;/code&gt; every two seconds: on a Pixel 7 (7.6 GB RAM), mid generation, about 6 GB PSS, zram 100 % full and kswapd at 72 % CPU. Generation slowed to a crawl and the low-memory killer took the app as soon as it left the foreground. On a 6 GB Galaxy S20 FE it never got that far: killed mid-load, in the foreground, three runs out of three. A warm weight cache changed nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  What fixed it: keep the weights file-backed
&lt;/h2&gt;

&lt;p&gt;The current engine is llama.cpp with a Q4_K_M GGUF, over a small JNI bridge. The settings that mattered, each measured on a phone rather than assumed:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;mmap stays on. With it off, the weights become 1.7 GB of memory the kernel can never reclaim, which is the LiteRT situation again.&lt;/li&gt;
&lt;li&gt;The large per-layer embedding table is read lazily: same speed, 676 MB fewer file pages resident, nine times less swap.&lt;/li&gt;
&lt;li&gt;Weight repacking (a second, anonymous copy of the weights laid out for faster ARM kernels) costs 1.13 GB. On the 6 GB phone: 5.0 words/s repacked with 1.29 GB anonymous, 3.8 words/s without it at 0.32 GB. So it is only switched on from 7 GB of RAM; below that a block takes about 40 seconds longer, hidden behind narration.&lt;/li&gt;
&lt;li&gt;Threads: the performance cores minus one. More is slower: 8 threads ran at a third of the speed of 3, and 4 threads gave 8.8 tokens/s against 10.7 for 3. Pinning threads to cores did not help (within 4 %).&lt;/li&gt;
&lt;li&gt;On unload, the allocator is purged explicitly. Without it about 1.2 GB of freed model memory stayed in the process: 1,280 MB resident after closing the model, 74 MB with the purge.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Generate in blocks, narrate while generating
&lt;/h2&gt;

&lt;p&gt;A session is 30 to 40 minutes of narration, several thousand words. Asking a 2B model for all of it in one call takes too long before anything plays, so the script is an ordered list of blocks: a pre-written induction, then deepening, metaphor, suggestions and anchoring, generated one by one, then a pre-written return to alertness.&lt;/p&gt;

&lt;p&gt;Because the opening is pre-written, narration starts as soon as the model is loaded. Block N+1 generates while block N is read aloud; on the S20 FE a body block arrives about every 100 seconds, faster than it takes to narrate. A block that fails or takes more than five minutes is replaced by a short pre-written bridge, so the listener is never left in silence.&lt;/p&gt;

&lt;p&gt;Each block is a single-turn prompt with the KV cache cleared, not a growing conversation. The model was fine-tuned on single-turn prompts, and in a simulated four-block session the accumulated conversation produced 6.3 duplicated sentences against 0.9 for single-turn. It also keeps the context at 2,048 tokens instead of 10,000.&lt;/p&gt;

&lt;p&gt;And the model is closed the moment the last block is written: the remaining half hour of narration, exactly when people lock their phone, runs with nothing loaded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Budget by duration, not by words
&lt;/h2&gt;

&lt;p&gt;An early version sized the script by word count. Narration speed and the pause between phrases are listener settings, and together they swing the real length by more than three times: some people got 90-minute sessions. The plan is now built from a target duration, converted to words at the listener's own speed and pause setting, minus the exact length of the pre-written parts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules a small model will not follow on its own
&lt;/h2&gt;

&lt;p&gt;Some listeners ask for no breathing cues (tightness in the throat when told to watch their breath) or have limited mobility. Written as prompt rules alone, the model broke them in roughly 10 to 40 % of restricted prompts. The fix was to ban the tokens themselves with a logit bias in the llama.cpp sampler: zero violations on a 120-prompt held-out set. The banned ids belong to the model's vocabulary, so the list is regenerated whenever the model file changes.&lt;/p&gt;

&lt;p&gt;Lower sampling temperatures made repetition loops more frequent, not less, so Onira samples like Gemma does: temperature 1.0, top-k 64, top-p 0.95, no repetition penalty.&lt;/p&gt;

&lt;p&gt;Safety does not rest on the model either. A deterministic check in English, French and Spanish runs on what the listener types before anything is generated, and a 2B model is treated as a second layer, never the first.&lt;/p&gt;

&lt;h2&gt;
  
  
  The model is public
&lt;/h2&gt;

&lt;p&gt;The fine-tune, hypnos-e2b-enfres, is Gemma 4 E2B trained on the exact prompts the app sends and pruned to English, French and Spanish (a 58,488-token vocabulary). It is published under Apache-2.0 on Hugging Face as oytaub/hypnos-e2b-enfres-GGUF, with the training and evaluation details in its model card.&lt;/p&gt;

&lt;p&gt;Phones that cannot run it can choose Onira Cloud, where the same kind of session is written on Onira's own server and never stored. On a phone that can, nothing typed or generated leaves the device and the app works in airplane mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How much RAM does an on-device LLM need on Android?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For a 2B model at 4-bit quantization with memory-mapped weights, about 5 GB of total RAM is enough in our measurements. Runtimes that copy the weights into the heap need far more: the same class of model was killed by the system on a 6 GB phone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why llama.cpp rather than LiteRT-LM?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mostly memory: llama.cpp can keep the weights file-backed through mmap, which the kernel can drop and reload, while the LiteRT-LM CPU backend copies them into anonymous memory. The single-turn prompting and token bans were also easier to control there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How fast is it?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On a Galaxy S20 FE, 3.8 to 5.0 words per second depending on weight repacking, and a 300-500 word block about every 100 seconds, which stays ahead of narration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I use the model myself?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes. It is on Hugging Face under Apache-2.0, as a GGUF file for llama.cpp.&lt;/p&gt;




&lt;p&gt;Originally published on &lt;a href="https://onirahypno.com/guides/running-an-llm-on-a-phone/" rel="noopener noreferrer"&gt;onirahypno.com&lt;/a&gt;. The model is on Hugging Face: &lt;a href="https://huggingface.co/oytaub/hypnos-e2b-enfres-GGUF" rel="noopener noreferrer"&gt;oytaub/hypnos-e2b-enfres-GGUF&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>android</category>
      <category>machinelearning</category>
      <category>performance</category>
    </item>
    <item>
      <title>Memory, not speed, is the hard part of running an LLM on a phone</title>
      <dc:creator>Charles-Antoine Fournel</dc:creator>
      <pubDate>Tue, 22 Sep 2026 12:12:35 +0000</pubDate>
      <link>https://dev.to/cfournel/memory-not-speed-is-the-hard-part-of-running-an-llm-on-a-phone-53mk</link>
      <guid>https://dev.to/cfournel/memory-not-speed-is-the-hard-part-of-running-an-llm-on-a-phone-53mk</guid>
      <description>&lt;p&gt;I ship an Android app (Onira) that generates a personalized hypnosis/relaxation&lt;br&gt;
script on-device with Gemma 4 E2B, through LiteRT-LM, then narrates it with&lt;br&gt;
on-device TTS. Nothing the user types, and nothing the model generates, ever&lt;br&gt;
leaves the phone. This is the part that was actually hard to get right, and it&lt;br&gt;
was not the part I expected.&lt;/p&gt;
&lt;h2&gt;
  
  
  Speed was fine. Memory nearly killed it.
&lt;/h2&gt;

&lt;p&gt;A mid-range phone writes 300-500 words in tens of seconds — acceptable for a&lt;br&gt;
relaxation app where narration masks generation latency. The real problem: the&lt;br&gt;
runtime loads the 2.6GB model into the native heap and does not mmap it.&lt;br&gt;
Measured on a Pixel 7 (7.6GB RAM), mid-generation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;~6GB PSS&lt;/li&gt;
&lt;li&gt;zram 100% full&lt;/li&gt;
&lt;li&gt;kswapd0 at 72% CPU&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The process thrashes, generation crawls, and Android's low-memory killer takes&lt;br&gt;
the app the instant it leaves the foreground. On a 6GB device it's worse.&lt;/p&gt;
&lt;h2&gt;
  
  
  Fix #1: stop holding the model once you're done needing it
&lt;/h2&gt;

&lt;p&gt;The obvious mistake would be keeping the &lt;code&gt;Engine&lt;/code&gt;/&lt;code&gt;Conversation&lt;/code&gt; alive for the&lt;br&gt;
whole session "just in case." But my output is consumed by TTS over the next&lt;br&gt;
30-40 minutes, and for all of that time nothing needs the model resident. So:&lt;br&gt;
close it the instant the last block is generated, and let the rest of the&lt;br&gt;
session narrate with the model unloaded. That window is also, not&lt;br&gt;
coincidentally, exactly when a user is most likely to background the app to do&lt;br&gt;
something else — which is exactly when the low-memory killer was taking it.&lt;/p&gt;

&lt;p&gt;The one deliberate exception: a &lt;code&gt;mediaPlayback&lt;/code&gt; foreground service keeps the&lt;br&gt;
process alive for the whole narration, started right when the user taps&lt;br&gt;
"Begin Session." Without it, backgrounding the app during the first few&lt;br&gt;
generating minutes (model still resident) got the whole session killed&lt;br&gt;
outright. Android 12+ also refuses a foreground-service start from the&lt;br&gt;
background — exactly the moment that request usually comes — so it has to&lt;br&gt;
start earlier than you'd want, while the model is still loaded. The accepted&lt;br&gt;
cost: the device may thrash and lmkd kills &lt;em&gt;other&lt;/em&gt; background apps instead,&lt;br&gt;
until the model unloads a few minutes in.&lt;/p&gt;
&lt;h2&gt;
  
  
  Fix #2: generate in blocks, not one call
&lt;/h2&gt;

&lt;p&gt;A session is an ordered sequence of blocks — induction, deepening, metaphor,&lt;br&gt;
suggestions, anchoring, repeat, emergence. Each is generated as its own turn&lt;br&gt;
on the &lt;em&gt;same&lt;/em&gt; &lt;code&gt;Engine&lt;/code&gt;/&lt;code&gt;Conversation&lt;/code&gt;, so later blocks stay thematically&lt;br&gt;
consistent with earlier ones without re-stating prior text in the prompt.&lt;br&gt;
Two consequences that matter more than the consistency:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Playback starts before the model finishes anything.&lt;/strong&gt; Induction and
emergence are static templates — neither depends on the category or the
user's free text, so there's nothing to personalize — which means narration
can start as soon as the model is &lt;em&gt;loaded&lt;/em&gt;, without waiting on a single
generation call. On a mid-range device the first real generation can take
minutes; a user hearing a voice at second three is a different product than
one staring at a spinner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Failure is local, not fatal.&lt;/strong&gt; A block that fails generation gets a short
pre-written bridging line instead of aborting the session. The listener
never notices; they just got a slightly shorter passage.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The body is capped at 6 blocks — a repeating cycle of&lt;br&gt;
&lt;code&gt;[deepening, metaphor, suggestions, anchoring]&lt;/code&gt;. This bound is what keeps any&lt;br&gt;
single generation call short regardless of total session length, and it's&lt;br&gt;
also exactly what the context window is sized against:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;MAX_BODY_BLOCKS&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;
&lt;span class="nc"&gt;When&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="n"&gt;budget&lt;/span&gt; &lt;span class="n"&gt;doesn&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;fill&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;whole&lt;/span&gt; &lt;span class="n"&gt;cycle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;scheduler&lt;/span&gt; &lt;span class="n"&gt;keeps&lt;/span&gt;
&lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;highest-priority&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="n"&gt;types&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="n"&gt;drops&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="n"&gt;suggestions&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt;
&lt;span class="n"&gt;anchoring&lt;/span&gt; &lt;span class="n"&gt;survive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;metaphor&lt;/span&gt; &lt;span class="n"&gt;goes&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;buildBodyPlan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;targetBodyWords&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SessionBlockType&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;bodyBlocks&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;targetBodyWords&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;WORDS_PER_BLOCK_TARGET&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="nc"&gt;WORDS_PER_BLOCK_TARGET&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;coerceIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;MAX_BODY_BLOCKS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;buildList&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bodyBlocks&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="nc"&gt;CORE_CYCLE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;CORE_CYCLE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nf"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;partialCycle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bodyBlocks&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="nc"&gt;CORE_CYCLE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;))&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;Rounded to the nearest block, not floored — at the short end of the range,&lt;br&gt;
flooring to whole cycles costs four blocks at once and undershoots the target by far more than rounding up overshoots it.&lt;/p&gt;

&lt;p&gt;The thing I got wrong for a while: sizing by word count&lt;br&gt;
My first version budgeted a fixed word count for the whole script — "4200&lt;br&gt;
words ≈ 30 minutes at 140 wpm." It shipped ~90-minute sessions at default&lt;br&gt;
settings. The bug: narration speed and the user's "pause between phrases"&lt;br&gt;
setting (3-15s, applied at every clause boundary) swing real spoken duration&lt;br&gt;
by more than 3x. A fixed word count cannot hold duration steady when the&lt;br&gt;
seconds-per-word ratio itself varies that much per user.&lt;/p&gt;

&lt;p&gt;The fix budgets from a target duration, converted to words using the user's&lt;br&gt;
own playback settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;secondsPerWord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speechRate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sentencePauseSeconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Float&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;Double&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;userScale&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speechRate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;coerceAtLeast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="nc"&gt;REFERENCE_USER_RATE&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toDouble&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;wordsPerMinute&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BASE_WORDS_PER_MINUTE&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="nc"&gt;NARRATION_BASE_RATE&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;userScale&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;speakingSeconds&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;60.0&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="n"&gt;wordsPerMinute&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;pause&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sentencePauseSeconds&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;coerceIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;15f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;pausePerClause&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SENTENCE_BOUNDARY_SHARE&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;pause&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="nc"&gt;SENTENCE_BOUNDARY_SHARE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="nc"&gt;NON_SENTENCE_PAUSE_SECONDS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="n"&gt;userScale&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;speakingSeconds&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;pausePerClause&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="nc"&gt;AVG_WORDS_PER_CLAUSE&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;wordsForSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;targetSeconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;speechRate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sentencePauseSeconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Float&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;10f&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;Int&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;targetSeconds&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="nf"&gt;secondsPerWord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speechRate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sentencePauseSeconds&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toInt&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;coerceAtLeast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AVG_WORDS_PER_CLAUSE and SENTENCE_BOUNDARY_SHARE aren't guesses — they're&lt;br&gt;
measured off the shipped template corpus (~10k words): one clause boundary&lt;br&gt;
every ~17 words, ~85% of them sentence ends that take the user's pause&lt;br&gt;
setting; the rest (ellipsis, semicolon) stay on a fixed, shorter pause. Only&lt;br&gt;
sentence boundaries scale with the user's setting, because that's the only&lt;br&gt;
pause the setting is actually supposed to control.&lt;/p&gt;

&lt;p&gt;The result: total session length is the thing held constant across every&lt;br&gt;
speech-rate and pause-length combination a user can pick, instead of word&lt;br&gt;
count — which is what actually matters for a relaxation session that's&lt;br&gt;
supposed to run 30-40 minutes, not 90.&lt;/p&gt;

&lt;p&gt;The honest costs of on-device&lt;br&gt;
A 2.6GB first-run model download — by a wide margin the largest drop-off in&lt;br&gt;
the funnel.&lt;br&gt;
No server-side moderation layer in front of a model writing&lt;br&gt;
psychologically-framed text for someone who typed in whatever's actually&lt;br&gt;
on their mind. Handled with a deliberately high-recall keyword gate that&lt;br&gt;
runs before the model is ever invoked — false positives (blocking a&lt;br&gt;
benign message) are cheap here; false negatives are not.&lt;br&gt;
Happy to go deeper on the safety gate design or the LiteRT-LM integration&lt;br&gt;
specifically, if there's interest. The app is &lt;a href="https://play.google.com/store/apps/details?id=com.oytaub.mindease" rel="noopener noreferrer"&gt;Onira&lt;/a&gt;&lt;br&gt;
on the Play Store if anyone wants to see the output — but the above is the&lt;br&gt;
part I think is worth discussing.&lt;/p&gt;

</description>
      <category>android</category>
      <category>ai</category>
      <category>machinelearning</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
