<?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: てつや</title>
    <description>The latest articles on DEV Community by てつや (@_aa1e63046b47c1c9b4f5c).</description>
    <link>https://dev.to/_aa1e63046b47c1c9b4f5c</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%2F4272426%2F87560300-6194-4340-acb7-7fd968edcb57.png</url>
      <title>DEV Community: てつや</title>
      <link>https://dev.to/_aa1e63046b47c1c9b4f5c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_aa1e63046b47c1c9b4f5c"/>
    <language>en</language>
    <item>
      <title>Building an Offline Text-to-Shorts Pipeline: kokoro-onnx + FFmpeg, Measured Subtitle Timing, and a Pre-Upload QA Gate</title>
      <dc:creator>てつや</dc:creator>
      <pubDate>Sun, 29 Nov 2026 14:22:43 +0000</pubDate>
      <link>https://dev.to/_aa1e63046b47c1c9b4f5c/building-an-offline-text-to-shorts-pipeline-kokoro-onnx-ffmpeg-measured-subtitle-timing-and-a-1e55</link>
      <guid>https://dev.to/_aa1e63046b47c1c9b4f5c/building-an-offline-text-to-shorts-pipeline-kokoro-onnx-ffmpeg-measured-subtitle-timing-and-a-1e55</guid>
      <description>&lt;p&gt;I wanted to prototype short-form video pipelines without paying per-character TTS fees or depending on a cloud video tool. The result is a small, MIT-licensed Python script that turns text into a narrated, subtitled 1080x1920 MP4 using only local tools. This post walks through the architecture and the design decisions, including one that matters more than it looks: where subtitle timing comes from.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Repo (MIT):&lt;/strong&gt; &lt;a href="https://github.com/tuan10208-prog/faceless-ai-video-factory-lite" rel="noopener noreferrer"&gt;github.com/tuan10208-prog/faceless-ai-video-factory-lite&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;90s Walkthrough:&lt;/strong&gt; &lt;a href="https://youtu.be/DQnu241gywA" rel="noopener noreferrer"&gt;youtu.be/DQnu241gywA&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Pipeline overview
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;text -&amp;gt; sentence split -&amp;gt; kokoro-onnx (local TTS) -&amp;gt; WAV + measured cue times
     -&amp;gt; SRT -&amp;gt; FFmpeg (1080x1920 H.264/AAC, subtitles) -&amp;gt; MP4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything runs on CPU. The only network access is a one-time download of the open Kokoro model files (about 340 MB) into &lt;code&gt;./models&lt;/code&gt;; after that, the script works offline.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Why &lt;code&gt;kokoro-onnx&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Kokoro is an 82M-parameter open-weight TTS model, and the ONNX runtime build runs acceptably on a laptop CPU with no GPU and no API key. For this use case, that removes the two usual costs of automated narration: per-character billing and rate limits. Voice selection is a flag (&lt;code&gt;--voice am_fenrir&lt;/code&gt;, &lt;code&gt;af_heart&lt;/code&gt;, &lt;code&gt;bm_george&lt;/code&gt;), and speed is &lt;code&gt;--speed&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Subtitle timing: measure it, don't guess
&lt;/h3&gt;

&lt;p&gt;The common approach is to synthesize audio, then run a speech-to-text pass (for example Whisper) to recover word timings. That is a second model, more latency, and a second source of drift.&lt;/p&gt;

&lt;p&gt;Here the timing comes for free. Each sentence is synthesized separately, and its duration is exact because the sample count is known:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sample_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;kokoro&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sentence&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;voice&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;voice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"en-us"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;dur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sample_rate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;cues&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cursor&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;dur&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sentence&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;cursor&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;dur&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;pause_sec&lt;/span&gt;   &lt;span class="c1"&gt;# 0.18s breath pause between sentences&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cues are written straight to an &lt;code&gt;.srt&lt;/code&gt;. Because cue times are derived from the same array that becomes the audio track, there is no drift between voice and captions. The trade-off is granularity: captions are sentence-level, not word-level. For word-level highlighting, you would need forced alignment on top.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. The FFmpeg render
&lt;/h3&gt;

&lt;p&gt;The render step is a single FFmpeg invocation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1080x1920 canvas at 30 fps, either a solid color or a background image with a slow &lt;code&gt;zoompan&lt;/code&gt; Ken Burns effect.&lt;/li&gt;
&lt;li&gt;H.264 video, AAC audio, &lt;code&gt;+faststart&lt;/code&gt; so the file is playable before it finishes downloading.&lt;/li&gt;
&lt;li&gt;Subtitles burned in via the &lt;code&gt;subtitles&lt;/code&gt; filter (&lt;code&gt;libass&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not every FFmpeg build ships &lt;code&gt;libass&lt;/code&gt;. If burning fails, the script falls back to a soft &lt;code&gt;mov_text&lt;/code&gt; subtitle track instead of aborting. That keeps the pipeline usable on minimal builds, at the cost of captions that the player, not the video, controls.&lt;/p&gt;

&lt;p&gt;On a standard CPU, a short clip of about 5 seconds rendered in a few seconds in my runs, and the output was roughly 125 KB for a solid-color background. Your numbers will vary with hardware and background type.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. The part that is not in the Lite repo: a pre-upload QA gate
&lt;/h3&gt;

&lt;p&gt;Generating videos is the easy half. The harder half is not publishing broken ones. Automated channels tend to fail on mundane defects: dead air, frozen frames, captions sitting under the platform UI. I handle that with a deterministic gate that runs before anything is uploaded. It uses FFmpeg's own detectors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# dead air&lt;/span&gt;
ffmpeg -i out.mp4 -af &lt;span class="nv"&gt;silencedetect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;-45dB:d=0.45 -f null -

&lt;span class="c"&gt;# frozen frames&lt;/span&gt;
ffmpeg -i out.mp4 -vf &lt;span class="nv"&gt;freezedetect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0.003:d=1.2 -f null -

&lt;span class="c"&gt;# black frames&lt;/span&gt;
ffmpeg -i out.mp4 -vf &lt;span class="nv"&gt;blackdetect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0.5:pix_th=0.05 -f null -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The gate fails a video if silence exceeds &lt;code&gt;0.45s&lt;/code&gt;, a freeze exceeds &lt;code&gt;1.2s&lt;/code&gt;, or captions fall outside a safe-zone margin, and it also applies a set of hard veto rules plus a 100-point rubric where 90 or above is a pass (I call it &lt;code&gt;GOLD_PASS&lt;/code&gt;). Anything below the threshold never reaches the upload step.&lt;/p&gt;

&lt;p&gt;This gate caught a real bug in my own pipeline: a clip concatenation that silently produced repeated frames. The detectors above flagged it immediately, which is the point of running them as a gate rather than eyeballing output.&lt;/p&gt;

&lt;p&gt;To be clear about scope: the QA gate, trend scouting, scripted generation, and publishing automation are part of a separate paid kit. The Lite repo linked above is standalone and only covers voice, subtitles, and render. If you only want the three &lt;code&gt;ffmpeg&lt;/code&gt; commands, they are above and free to copy.&lt;/p&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/tuan10208-prog/faceless-ai-video-factory-lite.git
&lt;span class="nb"&gt;cd&lt;/span&gt; faceless-ai-video-factory-lite
python -m venv .venv
&lt;span class="c"&gt;# Windows: .\.venv\Scripts\Activate.ps1   |  macOS/Linux: source .venv/bin/activate&lt;/span&gt;
pip install -r requirements.txt
python demo_tts_ffmpeg.py --text &lt;span class="s2"&gt;"What if the Moon disappeared tonight?"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output lands in &lt;code&gt;output/lite_demo.mp4&lt;/code&gt;. You need FFmpeg on your &lt;code&gt;PATH&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Feedback on the FFmpeg filtergraph, or on how to get word-level captions without a second model, is very welcome in the comments or as a GitHub issue.&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>automation</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
