<?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: Pavel Trubetskov</title>
    <description>The latest articles on DEV Community by Pavel Trubetskov (@pavel_trubetskov).</description>
    <link>https://dev.to/pavel_trubetskov</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3381302%2F66425d0c-36fb-428c-930a-eb9c3968f906.jpg</url>
      <title>DEV Community: Pavel Trubetskov</title>
      <link>https://dev.to/pavel_trubetskov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pavel_trubetskov"/>
    <language>en</language>
    <item>
      <title>I built a voice CBT diary with offline AI — here's how it works</title>
      <dc:creator>Pavel Trubetskov</dc:creator>
      <pubDate>Wed, 27 May 2026 13:56:22 +0000</pubDate>
      <link>https://dev.to/pavel_trubetskov/i-built-a-voice-cbt-diary-with-offline-ai-heres-how-it-works-23c6</link>
      <guid>https://dev.to/pavel_trubetskov/i-built-a-voice-cbt-diary-with-offline-ai-heres-how-it-works-23c6</guid>
      <description>&lt;p&gt;Two years ago I was going through CBT therapy for anxiety and depression. &lt;br&gt;
The homework — keeping a thought diary between sessions — never worked for me. &lt;br&gt;
Typing during a panic attack is impossible. I'd end up filling it from memory &lt;br&gt;
two hours before the session. CBT loses most of its effect that way.&lt;/p&gt;

&lt;p&gt;Voice was the obvious fix. On-device AI was the missing piece.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mentalium&lt;/strong&gt; is a voice CBT diary with offline AI transcription. Press record, &lt;br&gt;
speak the five steps of a CBT thought record — situation, automatic thought, &lt;br&gt;
emotion, reaction, alternative thought — and the AI fills every field. No typing. &lt;br&gt;
No cloud. Your voice never leaves the device.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tech stack
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Flutter + Dart&lt;/strong&gt; for the UI and app logic. One codebase for iOS and Android, &lt;br&gt;
which matters for a solo founder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Whisper.cpp&lt;/strong&gt; for transcription. The &lt;code&gt;ggml-small-q5_1&lt;/code&gt; model (~180 MB) &lt;br&gt;
downloads once on first launch, then runs fully offline forever.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On &lt;strong&gt;iOS&lt;/strong&gt;: compiled against Metal GPU via a Swift bridge. CoreML wasn't 
flexible enough for the quantized model weights I needed.&lt;/li&gt;
&lt;li&gt;On &lt;strong&gt;Android&lt;/strong&gt;: JNI bridge to the native C++ library. 
Getting this to compile cleanly for arm64-v8a and x86_64 took a while.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;SQLite&lt;/strong&gt; (via sqflite) for local storage. Every diary entry stays on-device — &lt;br&gt;
no backend sync, no analytics on the content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AES-256-GCM&lt;/strong&gt; encryption applies only when the user emails an Excel report &lt;br&gt;
to their therapist. That's the only outbound transmission.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hard parts
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Model size vs. accuracy tradeoff.&lt;/strong&gt; The tiny Whisper model is fast but misses &lt;br&gt;
nuance — important for transcribing emotional content accurately. The small-q5_1 &lt;br&gt;
quantized model hits the sweet spot: ~180 MB on disk, good accuracy across &lt;br&gt;
all 7 supported languages, runs in real-time on a 2020 iPhone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First launch UX.&lt;/strong&gt; Downloading 180 MB on first open is a bad experience &lt;br&gt;
if you don't set expectations. I added a progress bar with explicit copy: &lt;br&gt;
"Downloading the AI model — this happens once, then it works offline forever."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Language detection.&lt;/strong&gt; The app supports 7 languages. Whisper handles multilingual &lt;br&gt;
transcription well, but I had to build language-specific keyword matching &lt;br&gt;
for the cognitive distortion analysis (catastrophizing, mind-reading, etc.) &lt;br&gt;
across EN/DE/FR/ES/IT/PT-BR/RU.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;Building for mental health adds constraints most apps don't have. Privacy &lt;br&gt;
isn't a feature — it's the baseline. Users will not trust a voice diary &lt;br&gt;
that uploads to a server, no matter how good the privacy policy is. &lt;br&gt;
On-device AI removes that trust problem entirely.&lt;/p&gt;

&lt;p&gt;The CBT methodology also drove some unusual UX decisions. The five-step &lt;br&gt;
structure is fixed — you can't let users skip steps the way a generic journal would. &lt;br&gt;
That rigidity is the point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it is now
&lt;/h2&gt;

&lt;p&gt;iOS is live on the App Store with a 7-day free trial.&lt;br&gt;
Android is coming.&lt;/p&gt;

&lt;p&gt;→ &lt;a href="https://mentalium.me/en/" rel="noopener noreferrer"&gt;mentalium.me&lt;/a&gt;&lt;br&gt;
→ &lt;a href="https://apps.apple.com/app/id6764609587" rel="noopener noreferrer"&gt;App Store&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy to answer questions about the Whisper.cpp integration, &lt;br&gt;
the Flutter architecture, or the CBT-specific UX decisions.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>ai</category>
      <category>mentalhealth</category>
      <category>buildinpublic</category>
    </item>
  </channel>
</rss>
