<?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: Peter's Lab</title>
    <description>The latest articles on DEV Community by Peter's Lab (@peterslab).</description>
    <link>https://dev.to/peterslab</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%2F3716615%2F7d7d85b5-c225-42a7-acf6-e3aa32c58537.jpg</url>
      <title>DEV Community: Peter's Lab</title>
      <link>https://dev.to/peterslab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/peterslab"/>
    <language>en</language>
    <item>
      <title>Who Plays Whom? Designing the Casting Step for a Multi-Person AI Body Swap</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Mon, 23 Nov 2026 06:47:59 +0000</pubDate>
      <link>https://dev.to/peterslab/who-plays-whom-designing-the-casting-step-for-a-multi-person-ai-body-swap-4jl8</link>
      <guid>https://dev.to/peterslab/who-plays-whom-designing-the-casting-step-for-a-multi-person-ai-body-swap-4jl8</guid>
      <description>&lt;p&gt;Most AI video demos show one person in the frame. Real short videos often have two or three: a duo dance, a trio routine, a skit with a friend in the background.&lt;/p&gt;

&lt;p&gt;I build &lt;a href="https://memevibe.app/" rel="noopener noreferrer"&gt;Memevibe&lt;/a&gt;, an AI body swap for short clips. You drop a clip and a photo, and the person in the clip is replaced with the person in the photo, while the scene, camera and sound stay as filmed.&lt;/p&gt;

&lt;p&gt;With one person in the clip there is nothing to design. With three, there is a question the product has to answer before anything renders: which photo replaces which person? This post is about that step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it is not a face swap problem
&lt;/h2&gt;

&lt;p&gt;A face swap tool can get away with "pick a face in the frame". Body swap replaces the whole person: face, hair, build and outfit all come from the photo. If the mapping is wrong, the user does not get a slightly off result. They get their friend's body dancing in the wrong position for the entire clip, and they have paid for it.&lt;/p&gt;

&lt;p&gt;There is no preview before a render, because the render is the expensive part. So the mapping has to be right the first time, and the user has to be confident that it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: turn the clip into a cast list
&lt;/h2&gt;

&lt;p&gt;After upload, the clip is read and every person in it becomes a card. Each card has three things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a number that matches a marker on the frame&lt;/li&gt;
&lt;li&gt;a position, such as left, centre or right&lt;/li&gt;
&lt;li&gt;a short plain-language description, for example "brown hair tied back, white tank top, grey sweatpants"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The description matters more than I expected. Position alone breaks down as soon as people move, and in a dance they swap places constantly. A number alone means nothing. "The one in the pink sweatshirt" is how a person actually identifies someone in a video.&lt;/p&gt;

&lt;p&gt;A simplified sketch of the shape (illustrative, not the production code):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;PersonSlot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                 &lt;span class="c1"&gt;// matches the marker shown on the frame&lt;/span&gt;
  &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"left"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;"centre"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;"right"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// hair, top, bottoms&lt;/span&gt;
  &lt;span class="n"&gt;photo&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="nc"&gt;UploadedPhoto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// undefined = keep as filmed&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Cast&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;clipId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;slots&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PersonSlot&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;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;h2&gt;
  
  
  Step 2: empty is a valid answer
&lt;/h2&gt;

&lt;p&gt;The key decision is in that optional &lt;code&gt;photo&lt;/code&gt; field. A slot without a photo is not an error. It means "keep this person as filmed".&lt;/p&gt;

&lt;p&gt;This makes three use cases fall out of one model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;replace only the lead and leave the others&lt;/li&gt;
&lt;li&gt;replace two out of three&lt;/li&gt;
&lt;li&gt;recast the whole group, one photo each&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The only rule is that at least one slot needs a photo before the render button is enabled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;canStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Cast&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;cast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;slots&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;slot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;photo&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;undefined&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;I considered requiring a photo for every person. It would have been simpler to explain and it would have killed the most common case, which is one user who wants to be the lead in a group clip.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: say what will not work before the user pays
&lt;/h2&gt;

&lt;p&gt;Some clips cannot be swapped well, and the casting step is the last cheap moment to say so.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A person whose face never shows cannot be swapped. Back views and heavy motion blur give the model nothing to anchor a likeness to.&lt;/li&gt;
&lt;li&gt;When several people are being replaced, the higher tier keeps everyone steadier than the standard one. The interface says this on the cast list, next to the tier choice, not in a help page.&lt;/li&gt;
&lt;li&gt;Clips over 15 seconds only run on the top tier. The tier selector reflects that instead of letting the user pick something that will fail.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The pattern is the same each time: a constraint of the model becomes a visible state in the UI at the point where the user can still change their mind.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: the price follows the choices
&lt;/h2&gt;

&lt;p&gt;Tier, resolution and clip length decide the cost, and the number of credits is written on the start button. Change the tier and the button changes.&lt;/p&gt;

&lt;p&gt;I wrote about the billing side in an earlier post, so I will only repeat the principle: the user should never have to do arithmetic to know what a click will cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: the render is a background job
&lt;/h2&gt;

&lt;p&gt;A render usually takes 3 to 6 minutes. That is too long to hold someone on a spinner, so the job is detached from the page:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the user can leave, and the result shows up in a "My videos" list&lt;/li&gt;
&lt;li&gt;an email can be sent when it is done&lt;/li&gt;
&lt;li&gt;the original audio of the clip is put back under the generated video, so the output is ready to post&lt;/li&gt;
&lt;li&gt;if the render fails or the model's safety check stops it, the credits go back to the balance automatically&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last point shapes the casting step too. Because a failed render costs the user nothing, the UI can warn about risky clips without blocking them outright.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consent is part of the cast list
&lt;/h2&gt;

&lt;p&gt;Body swap puts a real person into a video they did not film. Two rules are enforced at this step:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the user confirms that each photo is of themselves or of someone who agreed to appear&lt;/li&gt;
&lt;li&gt;photos of celebrities and public figures are not accepted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On the data side, photos and clips are passed to the video model through links that expire within an hour, are not used for training, and are deleted after 30 days.&lt;/p&gt;

&lt;p&gt;It would be easy to treat these as legal boilerplate. I think of them as part of the same design problem: the casting step is where a person's likeness gets assigned, so it is where the rules about likeness belong.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would do differently
&lt;/h2&gt;

&lt;p&gt;Likeness is still not guaranteed. The photo is the usual cause when a result looks off, and I surface photo advice too late in the flow. A check at upload time, before the user gets to casting, would save renders.&lt;/p&gt;

&lt;p&gt;I would also like the description on each card to be editable, for the cases where the reading of the clip gets a detail wrong and the user loses confidence in the mapping.&lt;/p&gt;

&lt;p&gt;If you have built a flow where users map inputs to detected people or objects, I am curious how you handled identification. Numbers, thumbnails, descriptions, or something else?&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>showdev</category>
      <category>ux</category>
    </item>
    <item>
      <title>Engineering a 1,000-Page Batch Pipeline for CBZ, EPUB, and PDF Manga Archives</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Mon, 16 Nov 2026 05:11:36 +0000</pubDate>
      <link>https://dev.to/peterslab/engineering-a-1000-page-batch-pipeline-for-cbz-epub-and-pdf-manga-archives-3en6</link>
      <guid>https://dev.to/peterslab/engineering-a-1000-page-batch-pipeline-for-cbz-epub-and-pdf-manga-archives-3en6</guid>
      <description>&lt;p&gt;Building a single-image OCR demo takes a weekend. Things start breaking the moment a real user drops a 250-page &lt;code&gt;.cbz&lt;/code&gt; volume—or a 900 MB &lt;code&gt;.epub&lt;/code&gt; bundle—into your upload zone.&lt;/p&gt;

&lt;p&gt;While scaling our &lt;a href="https://ai-manga-translator.com" rel="noopener noreferrer"&gt;manga translator&lt;/a&gt; to handle full-volume batches up to 1,000 pages (or 1 GB per upload), we ran straight into the limits of traditional server-side file handling. Pushing raw archives to backend routes spiked memory usage, timed out serverless functions, and burned GPU inference on blank divider pages. Moving archive extraction, natural sorting, and page filtering into the browser solved all three bottlenecks.&lt;/p&gt;

&lt;p&gt;Here is how we architected the client-to-edge batch pipeline for multi-format comic archives.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Lexicographical Sorting Trap (&lt;code&gt;page_10.jpg&lt;/code&gt; Before &lt;code&gt;page_2.jpg&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Comic archives (&lt;code&gt;.cbz&lt;/code&gt;, &lt;code&gt;.cbr&lt;/code&gt;, &lt;code&gt;.zip&lt;/code&gt;, &lt;code&gt;.rar&lt;/code&gt;) are just compressed folders of images, and filenames in the wild are rarely zero-padded. When a volume contains &lt;code&gt;page_1.jpg&lt;/code&gt; through &lt;code&gt;page_200.jpg&lt;/code&gt;, a naive &lt;code&gt;files.sort()&lt;/code&gt; orders them lexicographically: &lt;code&gt;page_1.jpg&lt;/code&gt;, &lt;code&gt;page_10.jpg&lt;/code&gt;, &lt;code&gt;page_100.jpg&lt;/code&gt;, &lt;code&gt;page_2.jpg&lt;/code&gt;. In a narrative medium, scrambling page order makes the output unreadable.&lt;/p&gt;

&lt;p&gt;To preserve exact reading flow without brittle regex hacks, we run every extracted entry list through &lt;code&gt;Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })&lt;/code&gt; before assigning page indices. We also filter out hidden OS metadata artifacts like &lt;code&gt;__MACOSX/&lt;/code&gt; and &lt;code&gt;.DS_Store&lt;/code&gt; during the same pass so ghost files never enter the render queue.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Unpacking 1 GB Archives Without Blowing Up Server RAM
&lt;/h3&gt;

&lt;p&gt;Accepting a 1 GB archive on a Next.js API route or Edge worker is an anti-pattern—decompressing hundreds of high-resolution scans in server memory quickly triggers OOM crashes.&lt;/p&gt;

&lt;p&gt;Instead, we unpack archives locally on the client:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ZIP / CBZ &amp;amp; EPUB:&lt;/strong&gt; Parsed directly in the browser using streaming zip readers, extracting image blobs on demand without holding the entire uncompressed archive in memory at once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PDF &amp;amp; RAR / CBR:&lt;/strong&gt; Decoded via WebAssembly workers (&lt;code&gt;PDF.js&lt;/code&gt; and WASM unarchivers) off the main thread so the UI stays responsive while rendering high-DPI page canvases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once unpacked into lightweight client-side page objects, the browser dispatches uploads concurrently with per-page retry logic. If a user's connection blips on page 142, only that single image retries rather than restarting a 900 MB upload.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Pre-Flight Page Filtering to Cut Wasted Inference
&lt;/h3&gt;

&lt;p&gt;A printed tankōbon always includes front and back covers, blank spacer pages, tables of contents, copyright colophons, and publisher ads—often 10% to 15% of the total file. Running OCR, LLM translation, and screentone inpainting on blank pages wastes both user credits and backend GPU time.&lt;/p&gt;

&lt;p&gt;Before a batch starts, we render a fast thumbnail grid directly from the local blobs. Users can uncheck non-dialogue pages in a couple of clicks, ensuring that only actual story panels hit the inference pipeline.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Multi-Volume Queues and Ephemeral Storage
&lt;/h3&gt;

&lt;p&gt;Hardcore readers rarely translate one chapter at a time; they queue up three or four volumes before a weekend flight. Rather than merging multiple archives into one giant fragile job, the client orchestrates each archive as an isolated batch task in a sequential queue—so a malformed file in Volume 3 never blocks Volume 1 or Volume 2 from completing.&lt;/p&gt;

&lt;p&gt;Finally, because personal digital libraries shouldn't linger on cloud storage indefinitely, every uploaded page and rendered output travels over encrypted channels and enters a strict TTL lifecycle: an automated cleanup worker purges all session assets from object storage after 10 days.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>nextjs</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Billing for AI video renders: quotes, credit ledgers and automatic refunds</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:56:20 +0000</pubDate>
      <link>https://dev.to/peterslab/billing-for-ai-video-renders-quotes-credit-ledgers-and-automatic-refunds-4i2f</link>
      <guid>https://dev.to/peterslab/billing-for-ai-video-renders-quotes-credit-ledgers-and-automatic-refunds-4i2f</guid>
      <description>&lt;p&gt;I recently shipped &lt;a href="https://memevibe.app/" rel="noopener noreferrer"&gt;Memevibe&lt;/a&gt;, an AI body swap tool: you drop in a short clip, add a photo, and it renders the clip again with you as the person in it. Every render costs real GPU time, takes a few minutes, and can fail halfway. That makes billing a more interesting problem than the usual "check subscription, allow request".&lt;/p&gt;

&lt;p&gt;This post walks through the billing side: how a price is quoted, how credits are held and settled, and how a failed render gives the credits back without anyone writing to support. The code is simplified TypeScript that shows the shape of the logic, not a copy of production.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The rules the code has to implement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The product rules, as shown to users:&lt;/p&gt;

&lt;p&gt;Price depends on tier (Fast, Standard, Ultra), resolution and clip length.&lt;br&gt;
Table prices are per 12 seconds of video. Shorter or longer clips pay their share by the second.&lt;br&gt;
Clips over 15 seconds always run on the Ultra tier.&lt;br&gt;
The Fast tier is not offered at 1080p.&lt;br&gt;
The exact credit cost is shown on the button before the render starts.&lt;br&gt;
A render that fails, or is stopped by the model's safety check, returns its credits automatically.&lt;br&gt;
&lt;strong&gt;1. One quote function, used everywhere&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most important decision was having a single pure function that turns a request into a price, and using it in both places that matter: the number on the button and the amount actually charged.&lt;/p&gt;

&lt;p&gt;ts&lt;br&gt;
type Tier = "fast" | "standard" | "ultra";&lt;br&gt;
type Resolution = 480 | 720 | 1080;&lt;/p&gt;

&lt;p&gt;// Credits per 12 seconds of video&lt;br&gt;
const BASE: Record&amp;gt;&amp;gt; = {&lt;br&gt;
  fast:     { 480: 8,  720: 17 },&lt;br&gt;
  standard: { 480: 10, 720: 20, 1080: 50 },&lt;br&gt;
  ultra:    { 480: 17, 720: 37, 1080: 93 },&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;const BLOCK_SECONDS = 12;&lt;br&gt;
const ULTRA_ONLY_ABOVE_SECONDS = 15;&lt;/p&gt;

&lt;p&gt;interface Quote {&lt;br&gt;
  tier: Tier;        // the tier that will actually run&lt;br&gt;
  resolution: Resolution;&lt;br&gt;
  credits: number;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function quote(seconds: number, tier: Tier, resolution: Resolution): Quote {&lt;br&gt;
  const effectiveTier: Tier =&lt;br&gt;
    seconds &amp;gt; ULTRA_ONLY_ABOVE_SECONDS ? "ultra" : tier;&lt;/p&gt;

&lt;p&gt;const base = BASE[effectiveTier][resolution];&lt;br&gt;
  if (base === undefined) {&lt;br&gt;
    throw new Error(&lt;code&gt;${effectiveTier} is not offered at ${resolution}p&lt;/code&gt;);&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;const credits = Math.ceil((base * seconds) / BLOCK_SECONDS);&lt;br&gt;
  return { tier: effectiveTier, resolution, credits };&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;quote(12, "standard", 480); // 10 credits&lt;br&gt;
quote(6,  "standard", 480); // 5 credits&lt;br&gt;
quote(15, "standard", 480); // 13 credits&lt;br&gt;
quote(16, "standard", 480); // ultra, 23 credits&lt;/p&gt;

&lt;p&gt;Two details are worth pointing out.&lt;/p&gt;

&lt;p&gt;The function returns the effective tier, not just a number. When a 16-second clip is bumped to Ultra, the UI needs to say so. Returning the tier alongside the price means the button can show "Ultra, 23 credits" instead of a number the user can't explain.&lt;/p&gt;

&lt;p&gt;The server never trusts the client's number. The browser calls quote() to render the button, but the render endpoint calls it again with the server's own measurement of the clip length. If the two disagree, the request is rejected and the UI refreshes the quote. The price on the button is a promise, so the charge has to come from the same function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. A ledger instead of a balance column&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is tempting to store credits_balance on the user row and decrement it. I used an append-only ledger instead: every change to a user's credits is a row, and the balance is the sum.&lt;/p&gt;

&lt;p&gt;ts&lt;br&gt;
interface LedgerEntry {&lt;br&gt;
  id: string;&lt;br&gt;
  userId: string;&lt;br&gt;
  delta: number;            // +35 for a purchase, -13 for a render&lt;br&gt;
  reason: "purchase" | "render_hold" | "render_refund";&lt;br&gt;
  jobId?: string;&lt;br&gt;
  createdAt: Date;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;This costs a little at read time and pays for itself the first time someone asks "why do I have 7 credits?". Every answer is a list of rows. It also makes refunds trivial: a refund is not an edit to history, it is a new positive row that points at the same job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Hold on start, settle on finish&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A render takes minutes, so the charge can't wait until the end (the user could start ten renders on one credit). Credits are taken when the job is created, inside the same transaction that creates the job:&lt;/p&gt;

&lt;p&gt;ts&lt;br&gt;
async function startRender(userId: string, req: RenderRequest) {&lt;br&gt;
  const seconds = await measureClipSeconds(req.clipId); // server-side&lt;br&gt;
  const q = quote(seconds, req.tier, req.resolution);&lt;/p&gt;

&lt;p&gt;return db.transaction(async (tx) =&amp;gt; {&lt;br&gt;
    const balance = await tx.ledger.sumForUser(userId, { lock: true });&lt;br&gt;
    if (balance &amp;lt; q.credits) throw new InsufficientCredits(q.credits, balance);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const job = await tx.jobs.insert({
  userId,
  status: "queued",
  tier: q.tier,
  resolution: q.resolution,
  credits: q.credits,
});

await tx.ledger.insert({
  userId,
  jobId: job.id,
  delta: -q.credits,
  reason: "render_hold",
});

return job;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;});&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Because the job row and the ledger row are written together, there is no state where a job exists without its charge, or a charge exists without a job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. The refund path is part of the state machine&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A job moves through a small set of states:&lt;/p&gt;

&lt;p&gt;queued -&amp;gt; rendering -&amp;gt; completed&lt;br&gt;
                    -&amp;gt; failed    (credits returned)&lt;br&gt;
                    -&amp;gt; blocked   (safety check, credits returned)&lt;/p&gt;

&lt;p&gt;The refund is not a support action. It is what the failed and blocked transitions do:&lt;/p&gt;

&lt;p&gt;ts&lt;br&gt;
type Outcome = "completed" | "failed" | "blocked";&lt;/p&gt;

&lt;p&gt;async function finishJob(jobId: string, outcome: Outcome) {&lt;br&gt;
  await db.transaction(async (tx) =&amp;gt; {&lt;br&gt;
    const job = await tx.jobs.lockById(jobId);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Callbacks can arrive twice. A finished job stays finished.
if (job.status !== "queued" &amp;amp;&amp;amp; job.status !== "rendering") return;

await tx.jobs.update(jobId, { status: outcome });

if (outcome !== "completed") {
  await tx.ledger.insert({
    userId: job.userId,
    jobId,
    delta: +job.credits,
    reason: "render_refund",
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;});&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;The early return is what makes this safe. Model providers retry callbacks, workers crash and restart, and a naive handler would refund the same job twice. Locking the job row and checking its state first means the second call is a no-op. A unique index on (jobId, reason) in the ledger is a cheap second line of defense.&lt;/p&gt;

&lt;p&gt;One more case: a job that never reports back. A periodic sweep marks jobs stuck in rendering past a timeout as failed, which sends them down the same refund path. No separate code, no manual cleanup.&lt;/p&gt;

&lt;p&gt;A completed render is not refunded, since the compute has been spent. That rule is stated on the pricing page, next to a plain note that AI video output varies between renders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Putting the original sound back&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The video model generates frames. The audio the user expects is the original clip's audio, untouched, so the last step of a render is a mux: take the video stream from the generated file and the audio stream from the source clip.&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
ffmpeg -i swapped.mp4 -i original.mp4 \&lt;br&gt;
  -map 0✌️0 -map 1🅰️0 \&lt;br&gt;
  -c:v copy -c:a aac -shortest \&lt;br&gt;
  output.mp4&lt;/p&gt;

&lt;p&gt;Copying the video stream avoids a second encode, and -shortest guards against a generated clip that is a few frames shorter than its source. Keeping the audio out of the generation step entirely is also what keeps the result in sync with the trend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Deleting things on schedule&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Uploaded photos and rendered videos are deleted after 30 days. That is a privacy promise on the site, so it is enforced by a scheduled job, not by good intentions: each stored object carries its creation time, and a daily task removes anything past the window along with its database references. The ledger rows stay, because they hold no personal media and are needed for the purchase history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I'd do differently, and a question&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The part I underestimated was how many paths lead to "the job did not finish": provider errors, safety blocks, timeouts, crashed workers. Modeling them as one transition with one side effect, early on, would have saved me some patching.&lt;/p&gt;

&lt;p&gt;The open question I have for anyone who has built per-generation billing: do you hold credits at job start, as above, or authorize and capture at the end? Holding is simpler and prevents overspending, but it means the user's balance drops before they have anything to show for it. I'd like to hear how others handled that.&lt;/p&gt;

&lt;p&gt;If you want to see what the product does with all this, there is a short explainer on &lt;a href="https://memevibe.app/blog/what-is-ai-body-swap" rel="noopener noreferrer"&gt;what AI body swap is and how it differs from face swap&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>typescript</category>
      <category>showdev</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Fitting Translated Speech Back Into the Original Timeline: The Duration Problem in AI Dubbing</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Fri, 06 Nov 2026 08:34:13 +0000</pubDate>
      <link>https://dev.to/peterslab/fitting-translated-speech-back-into-the-original-timeline-the-duration-problem-in-ai-dubbing-27gc</link>
      <guid>https://dev.to/peterslab/fitting-translated-speech-back-into-the-original-timeline-the-duration-problem-in-ai-dubbing-27gc</guid>
      <description>&lt;p&gt;Everyone who builds an AI dubbing pipeline hits the same wall in week two. The ASR works, the translation reads fine, the TTS sounds like the speaker. Then you lay the synthesized German over the original video and it is still talking 1.3 seconds after the speaker’s mouth closed, and the next line starts on top of it.&lt;/p&gt;

&lt;p&gt;This post is about that wall. Not the voice model, not the translation model, but the step between them that nobody writes about: taking a translated segment whose natural spoken duration is wrong and making it land where the original did. At AI Video Translator this step went through four rewrites before it stopped generating support tickets, and the final version is less clever than the first one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ai-video-translator.com/" rel="noopener noreferrer"&gt;https://ai-video-translator.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Why the durations are wrong in the first place&lt;/p&gt;

&lt;p&gt;Translated text is a different length from the source. By character count, English to German typically expands 10 to 35 percent, Spanish 15 to 25, French 15 to 20, while Japanese and Chinese contract by a third or more. Speech rate then modulates this: Spanish and Japanese speakers produce around 7.8 syllables per second, English about 6.2, German about 6.0. So Spanish expansion partly cancels out, Japanese contraction almost fully cancels out, and German gets hit twice: more material and a slower rate.&lt;/p&gt;

&lt;p&gt;The practical result: a 4.0 s English segment comes back from TTS as roughly 4.0 to 4.4 s in Japanese, 4.3 to 4.8 s in Spanish, and 4.8 to 5.6 s in German. Nothing about that is a defect. It is what the languages do.&lt;/p&gt;

&lt;p&gt;The naive fix and why it fails&lt;/p&gt;

&lt;p&gt;The first thing everyone does:&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
ratio = target_duration / synthesized_duration&lt;br&gt;
audio = time_stretch(audio, ratio)   # phase vocoder / WSOLA&lt;/p&gt;

&lt;p&gt;Stretch every segment to its original slot. It works up to about a 10 percent compression. Between 10 and 15 percent listeners notice something is off even if they cannot say what. Beyond 15 percent the dub sounds like legal disclaimers at the end of a radio ad. German needs 20 to 40 percent on a bad line, so the naive fix produces unusable German while looking fine on Japanese test clips. If your test set is Japanese, you will ship this and find out from users.&lt;/p&gt;

&lt;p&gt;What the final version does&lt;/p&gt;

&lt;p&gt;The current approach is a budget-and-fallback chain. Each segment carries a timing budget derived from the original, and four strategies are tried in order of how much they damage the result.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compute the real budget, not the segment duration&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The original segment runs from t_start to t_end, but the speaker does not necessarily start talking again at t_end. There is usually silence after it: a breath, a cut, a pause before the next sentence. That silence is free time, as long as it belongs to the same speaker.&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
def budget(seg, next_seg, speaker_turn_end):&lt;br&gt;
    hard_end = min(next_seg.start, speaker_turn_end)&lt;br&gt;
    slack = hard_end - seg.end&lt;br&gt;
    return seg.duration + min(slack, MAX_SPILL)   # MAX_SPILL ~ 0.6 s&lt;/p&gt;

&lt;p&gt;Two details that mattered. First, cap the spill; a line that drifts a full second late feels wrong even if nothing collides with it, because the viewer sees the mouth stop. Second, the speaker-turn boundary is a hard wall. With one speaker you can borrow any pause. With two, the pause after speaker A’s line may be the lead-in to speaker B’s line, and borrowing it makes the two synthesized voices overlap where the originals never did.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Mild time stretch, bounded
python
MAX_STRETCH = 1.12
needed = synth_dur / budget
if needed &amp;lt;= MAX_STRETCH:
return time_stretch(audio, 1 / needed)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A 12 percent ceiling is conservative. It is also the point past which our own listening tests stopped agreeing on whether the voice was “fine”, so it is where the automatic path stops.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Re-translate against a length target&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is the strategy with the most headroom and the one most pipelines skip because it means the translation step and the timing step have to talk to each other.&lt;/p&gt;

&lt;p&gt;When a segment exceeds the stretch ceiling, we call the translation model again with the same context plus a constraint: the target rendering should be at most N syllables (or characters, for languages where syllable counting is unreliable) and should preserve meaning over phrasing. N is derived from the budget and the language’s speech rate:&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
syllable_rate = {"de": 5.97, "en": 6.19, "es": 7.82, "fr": 7.18, "ja": 7.84}&lt;br&gt;
max_syllables = int(budget * syllable_rate[lang] * 0.95)&lt;/p&gt;

&lt;p&gt;The model is good at this. “We’re now going to take a look at how this works in practice” becomes “Now let’s see how this works.” The meaning survives and the line fits. We allow at most two re-translation attempts with tightening budgets; after that we stop, because the third attempt starts dropping information.&lt;/p&gt;

&lt;p&gt;One subtlety: re-translating a single line in isolation can break consistency with the lines around it (a term rendered one way in the long version and another way in the short one). The glossary layer that pins fixed terms across the whole document also applies here, and the re-translation call gets the same surrounding-context window the first pass got.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Flag it for a human&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the line still does not fit after re-translation plus mild stretch, it gets marked in the review UI with the overrun amount, and the user can edit the text and re-voice just that line. The billing follows: re-voicing one line costs seconds of new speech, not a full render, because if fixing a line costs the same as the whole video nobody fixes lines.&lt;/p&gt;

&lt;p&gt;The order is the point. Stretch is cheap and bounded. Re-translation is free in audio terms and has the most range. Human editing is the backstop. The first version of this pipeline did them in the wrong order (stretch as hard as needed, then give up) and the fourth version is the one above.&lt;/p&gt;

&lt;p&gt;Measuring it&lt;/p&gt;

&lt;p&gt;The metric that tracks user complaints best is not average overrun but the 95th percentile of synth_dur / budget per video, after all automatic strategies. A video with a p95 under 1.0 almost never gets a timing complaint. A video with p95 above 1.15 almost always does, even if the mean looks fine, because the viewer remembers the one line that spilled over the scene cut.&lt;/p&gt;

&lt;p&gt;Per language on our content mix, after the full chain: Japanese and Mandarin need no re-translation on most segments; Spanish and French need it on roughly one segment in ten; German on roughly one in four. German remains the language where the human step gets used, and it is the language I would test first if I were evaluating anyone else’s dubbing tool.&lt;/p&gt;

&lt;p&gt;Things I’d tell myself at the start&lt;br&gt;
Build the budget from the next speech onset, not the segment end. Most of the free time is in the pauses.&lt;br&gt;
Treat speaker boundaries as walls from day one, even if you only support one speaker today.&lt;br&gt;
Length-constrained re-translation is the big lever. Wire the MT step so it can be called with a budget.&lt;br&gt;
Don’t tune on Japanese. It is the easy case and it will lie to you.&lt;br&gt;
Expose overruns to the user per line. They will fix the two lines that matter far faster than you can tune the model to.&lt;/p&gt;

&lt;p&gt;The user-facing version of this, with the W3C and Lyon speech-rate numbers behind it, is here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ai-video-translator.com/blog/why-ai-dubs-run-long" rel="noopener noreferrer"&gt;https://ai-video-translator.com/blog/why-ai-dubs-run-long&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>webdev</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Keeping character names consistent across 1,000 manga pages: why I added a glossary to my AI translator</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Fri, 30 Oct 2026 09:50:53 +0000</pubDate>
      <link>https://dev.to/peterslab/keeping-character-names-consistent-across-1000-manga-pages-why-i-added-a-glossary-to-my-ai-h15</link>
      <guid>https://dev.to/peterslab/keeping-character-names-consistent-across-1000-manga-pages-why-i-added-a-glossary-to-my-ai-h15</guid>
      <description>&lt;p&gt;The most common complaint I got from users of my manga translation tool was not about translation quality on any single page. It was about page 190.&lt;/p&gt;

&lt;p&gt;Someone would upload a whole volume, the first chapter would read fine, and then halfway through a side character would quietly change names. "Shiori" became "Siori". A guild called "the Black Hand" turned into "the Dark Hand". The honorific "-senpai" was kept on one page and dropped on the next. Each page in isolation was fine. The volume as a whole was not.&lt;/p&gt;

&lt;p&gt;This post is about why that happens, why it is harder to fix than it sounds, and what I ended up shipping in AI Manga Translator to deal with it: a per-upload glossary with CSV import and export.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ai-manga-translator.com" rel="noopener noreferrer"&gt;https://ai-manga-translator.com&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why names drift in the first place
&lt;/h2&gt;

&lt;p&gt;A manga page goes through a pipeline: detect speech bubbles, work out reading order, OCR the Japanese, translate, inpaint the original text out, typeset the translation back in. The translation step is where names get decided.&lt;/p&gt;

&lt;p&gt;The problem is that a name written in kanji or katakana often has several defensible romanizations, and a made-up term has several defensible translations. An LLM picks one. Ask it again with a slightly different context, and it may pick another. Over 200 pages you accumulate hundreds of these small decisions, and some fraction of them land differently.&lt;/p&gt;

&lt;p&gt;Three things make it worse for manga specifically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pages are translated in batches, not as one giant prompt.&lt;/strong&gt; A 1,000-page archive does not fit in a single context window at usable cost, so the model sees chunks. Each chunk can drift from the last.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Japanese drops the subject constantly.&lt;/strong&gt; A line that is just a verb gets its subject inferred from context. If the model misreads who is speaking, it can also misattribute a name.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reader expectations are strict.&lt;/strong&gt; Prose readers might tolerate a one-off spelling variation. Manga readers follow series for years and have strong opinions about whether it is "Zoro" or "Zolo".&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What I tried first
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Carrying context forward.&lt;/strong&gt; I pass a summary of recently seen names and terms from earlier chunks into later chunks. This helps a lot and is the main reason the tool already kept names stable for most volumes. But "most" is not "all", and it is a soft signal: the model is told what it used before, not what it must use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bigger chunks.&lt;/strong&gt; Fewer boundaries means fewer chances to drift. It also means slower first results and higher cost per job, and it still does not solve the cross-volume case, where a user translates volume 3 today and volume 4 next month.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Post-processing find-and-replace.&lt;/strong&gt; Tempting, but you cannot safely regex a name across typeset speech bubbles after the fact, and you do not know which variant the user wanted in the first place.&lt;/p&gt;

&lt;p&gt;None of these address the real gap: the person who knows what the names should be is the user, and I was never asking them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What shipped: a glossary per upload
&lt;/h2&gt;

&lt;p&gt;The fix was boring, which is usually a good sign. Each upload can now carry a glossary: a list of fixed renderings, source term to target term, that the translation step must respect.&lt;/p&gt;

&lt;p&gt;Design decisions, with the reasoning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Per upload, not auto-saved.&lt;/strong&gt; I considered a global glossary tied to the account. Users translate different series, and a global list would silently apply "Shiori" to a completely different character in another manga. So the glossary attaches to the job. To reuse it, you export it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSV import and export.&lt;/strong&gt; Scanlation groups already keep terminology sheets in spreadsheets. Asking them to retype into a custom UI would have killed adoption. CSV means they paste what they already have, and the exported file travels to the next volume.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hard cap of 100 entries.&lt;/strong&gt; Most volumes need 10 to 30. The cap keeps the prompt budget predictable and discourages people from pasting an entire dictionary and wondering why quality dropped.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No extra page charge.&lt;/strong&gt; Glossary entries add tokens to every translation call, so there is a real cost. I decided it should not be a line item, because the whole point is to make long-volume translation worth doing. The alternative, where a careful user pays more than a careless one, felt backwards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Works with the style preview.&lt;/strong&gt; Users can translate a few pages first, see which names appear and how they were rendered, then fill the glossary before running the full archive. Fifteen minutes of setup versus hunting for the wrong page afterwards.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How it fits in the pipeline
&lt;/h2&gt;

&lt;p&gt;At a high level, the glossary is injected as a constraint into the translation step for every chunk, alongside the carried-forward context. The carried-forward context says "here is what you did before"; the glossary says "here is what you must do". When they conflict, the glossary wins.&lt;/p&gt;

&lt;p&gt;The OCR step also benefits indirectly. Knowing that a specific katakana string is a name, not a word, lets the pipeline treat it as an atomic token instead of trying to translate it, which fixes a class of errors where a name that happens to look like a common noun gets translated literally.&lt;/p&gt;

&lt;p&gt;I will not go into prompt specifics here, but the pattern is general enough that it applies to any batched LLM translation job: separate "what you did before" (soft, advisory) from "what the user requires" (hard, authoritative), and give the user a way to author the second one in a format they already use.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would tell someone building something similar
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Consistency across batches is a product problem before it is a model problem. The best model still does not know which romanization your users want.&lt;/li&gt;
&lt;li&gt;Let users bring their own terminology in the format they already have. For my audience that was CSV. For yours it might be a JSON file or a Notion export.&lt;/li&gt;
&lt;li&gt;Put the glossary where the job is, not where the account is. Scope prevents a whole category of silent errors.&lt;/li&gt;
&lt;li&gt;Pair it with a cheap preview step so people can discover what needs to go in the glossary before paying for the full run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to see the end result, the manga translator takes CBZ, CBR, PDF and EPUB archives, with the glossary and style preview available on every upload:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ai-manga-translator.com/tools/manga-translator" rel="noopener noreferrer"&gt;https://ai-manga-translator.com/tools/manga-translator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy to answer questions about the batching and context-carrying approach in the comments.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>showdev</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Why I Put a Human Review Step Before TTS in My AI Dubbing Pipeline</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Wed, 21 Oct 2026 04:54:34 +0000</pubDate>
      <link>https://dev.to/peterslab/why-i-put-a-human-review-step-before-tts-in-my-ai-dubbing-pipeline-f5a</link>
      <guid>https://dev.to/peterslab/why-i-put-a-human-review-step-before-tts-in-my-ai-dubbing-pipeline-f5a</guid>
      <description>&lt;p&gt;I run &lt;a href="https://ai-video-translator.com/" rel="noopener noreferrer"&gt;AI Video Translator&lt;/a&gt; as a solo dev. This week I shipped three features that all came from the same user complaint: &lt;strong&gt;"I only find out the translation is wrong after the dub is done."&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: errors surfaced at the most expensive step
&lt;/h2&gt;

&lt;p&gt;The original pipeline ran end to end in one pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;STT → translation → voice cloning / TTS → time-stretch + remix → output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Users heard the result, then noticed a name translated literally, a tone that didn't fit the video, or a term that came out differently in episode 3. The only fix was rerunning the whole dub.&lt;/p&gt;

&lt;p&gt;The cost asymmetry was obvious once I looked at it. Editing a line of text is almost free. Regenerating speech is not. So the goal became simple: &lt;strong&gt;let users fix mistakes at the cheapest point in the pipeline.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The new pipeline
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;STT
 |
 v
Translation (glossary applied)
 |
 v
[NEW] Human review: line-by-line edit
 |
 v
Voice cloning / TTS (per speaker)
 |
 v
Time-stretch + remix
 |
 v
Dubbed video + SRT (burn-in optional)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1. A review step before synthesis
&lt;/h3&gt;

&lt;p&gt;After translation, the script is shown line by line next to the source. Whatever the user edits becomes the input to TTS.&lt;/p&gt;

&lt;p&gt;The main UX constraint is &lt;strong&gt;line length&lt;/strong&gt;. Translated speech already tends to run longer than the source. If a user expands a line with extra explanation, it still has to fit the same time slot, so the voice speeds up. The rule I push in the UI: change the meaning if needed, keep the length close.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. A glossary applied at translation time
&lt;/h3&gt;

&lt;p&gt;Review fixes one video. Without a glossary, the same mistake comes back in the next one and users fix the same word again and again.&lt;/p&gt;

&lt;p&gt;So users can now register source terms with a fixed target translation, applied during the translation step. It's the same idea as the glossary layer I built for character names in my manga translator (&lt;a href="https://dev.to/peterslab/keeping-character-names-consistent-across-200-chapters-a-glossary-layer-for-llm-translation-o4k"&gt;write-up here&lt;/a&gt;), except in video it's product names, technical terms, and channel-specific phrases. CSV import and export make it reusable across a series and shareable across a team.&lt;/p&gt;

&lt;p&gt;The two features feed each other: &lt;strong&gt;any word you fix twice during review is a glossary candidate.&lt;/strong&gt; The first episode takes real review time. By episode ten, review is a quick scan.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. SRT as a separate output
&lt;/h3&gt;

&lt;p&gt;Previously the only output was a video with subtitles burned in. Fixing one caption typo meant re-rendering the whole video.&lt;/p&gt;

&lt;p&gt;Now every dub ships with a separate SRT file, and burn-in is optional. The SRT is built from the reviewed script, so edits land in both the audio and the captions. Creators can upload a clean video to YouTube and add the SRT in YouTube Studio, or upload captions separately to a course platform.&lt;/p&gt;

&lt;p&gt;This sits on top of the multi-speaker detection I shipped a day earlier, where each speaker in the video keeps their own voice.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong at the start
&lt;/h2&gt;

&lt;p&gt;I originally pitched "fully automatic, from translation to dub" as the main selling point. But users dubbing long series and course content didn't want less control. They wanted &lt;strong&gt;a place to intervene&lt;/strong&gt;. The automation stays; I just added a handle at the point where human input is cheapest.&lt;/p&gt;

&lt;p&gt;I wrote a fuller, user-facing walkthrough of the workflow (including a training and course video use case) here: &lt;a href="https://ai-video-translator.com/blog/review-edit-ai-dubbing-translations" rel="noopener noreferrer"&gt;How to Review and Edit AI Dubbing Translations (and Keep Terminology Consistent)&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback welcome
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Is line-by-line the right review granularity, or would grouping by paragraph or speaker be better?&lt;/li&gt;
&lt;li&gt;For per-series glossaries, is CSV good enough, or is there a better format for teams?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks to everyone who asked for these.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgypyfy6uk3gmp5sc6vcp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgypyfy6uk3gmp5sc6vcp.png" alt="AI Video Translator homepage with a NASA video clip dubbed into Chinese, showing translated Chinese subtitles at the bottom of the video and a list of features including voice cloning and SRT/VTT subtitles." width="800" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>showdev</category>
      <category>webdev</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Why Vertical Japanese Text Breaks Standard OCR (And How We Engineered an Inpainting Pipeline in Next.js)</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Tue, 13 Oct 2026 08:39:27 +0000</pubDate>
      <link>https://dev.to/peterslab/why-vertical-japanese-text-breaks-standard-ocr-and-how-we-engineered-an-inpainting-pipeline-in-c1e</link>
      <guid>https://dev.to/peterslab/why-vertical-japanese-text-breaks-standard-ocr-and-how-we-engineered-an-inpainting-pipeline-in-c1e</guid>
      <description>&lt;p&gt;Reading raw Japanese manga should be seamless in 2026. Yet millions of international readers still hit the same wall: paste a comic panel into standard OCR tools or generic browser extensions, and you get fragmented nonsense covered by ugly white rectangular patches.&lt;/p&gt;

&lt;p&gt;When building &lt;strong&gt;AI Manga Translator&lt;/strong&gt; (&lt;a href="https://ai-manga-translator.com" rel="noopener noreferrer"&gt;https://ai-manga-translator.com&lt;/a&gt;), our biggest bottleneck was not prompting translation LLMs. It was the complete failure rate of conventional computer vision when confronted with tategaki (vertical text), non-convex speech bubbles, and half-tone screentones.&lt;/p&gt;

&lt;p&gt;Here is an architectural breakdown of why generic OCR pipelines break on comics, and how we engineered an in-browser detection and inpainting pipeline using Next.js, SegFormer, and custom client-side heuristics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Geometry Breakdown: Horizontal Anchor Bias vs. Tategaki&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Standard OCR engines (Tesseract, PaddleOCR, Apple Vision) are tuned on standard horizontal Latin and CJK documents such as invoices, receipts, and books. They rely on horizontal projection profiles to detect text baselines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Manga breaks every baseline assumption:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;• Top-to-Bottom, Right-to-Left (Tategaki): Columns read right-to-left, but glyphs flow top-to-bottom. Horizontal clustering models frequently link glyphs across adjacent columns, merging two distinct thoughts into garbled output.&lt;br&gt;
• Furigana Collisions: Japanese manga frequently prints ruby text (small phonetic furigana) right beside complex kanji. Generic bounding boxes merge furigana into the main glyph, destroying character recognition accuracy.&lt;br&gt;
• Complex Non-Convex Polygons: Dialogue balloons vary from ellipses and rounded rectangles to spiked shock-bursts. Applying axis-aligned bounding boxes (AABB) captures halftone background textures, speed lines, and character hair, triggering severe false positives.&lt;/p&gt;

&lt;p&gt;To solve the column-ordering failure mode, we implemented a custom heuristic to cluster vertical text boxes along their true semantic flow:&lt;/p&gt;

&lt;p&gt;interface DetectedBox {&lt;br&gt;
x: number;&lt;br&gt;
y: number;&lt;br&gt;
width: number;&lt;br&gt;
height: number;&lt;br&gt;
text: string;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;export function clusterVerticalColumns(boxes: DetectedBox[], lineThreshold = 18): DetectedBox[][] {&lt;br&gt;
const sorted = [...boxes].sort((a, b) =&amp;gt; b.x - a.x);&lt;br&gt;
const columns: DetectedBox[][] = [];&lt;/p&gt;

&lt;p&gt;for (const box of sorted) {&lt;br&gt;
const matchedCol = columns.find(col =&amp;gt;&lt;br&gt;
Math.abs(col[col.length - 1].x - box.x) &amp;lt; lineThreshold&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;if (matchedCol) {&lt;br&gt;
  matchedCol.push(box);&lt;br&gt;
  matchedCol.sort((a, b) =&amp;gt; a.y - b.y);&lt;br&gt;
} else {&lt;br&gt;
  columns.push([box]);&lt;br&gt;
}&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;return columns;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Instead of rigid bounding boxes, we deploy a comic-fine-tuned semantic segmentation backbone based on SegFormer. It outputs pixel-level probability masks separating speech bubble contours, in-bubble vertical text strokes, and sound effects (SFX) alongside ambient text overlays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Replacing White Rectangles with Inpainting (LaMa Architecture)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most notorious flaw of browser translation extensions is the "white patch." Standard tools draw an opaque rectangular SVG or div over the bubble, completely destroying hand-drawn screentones, line art, and atmospheric dark backgrounds.&lt;/p&gt;

&lt;p&gt;To achieve clean scans, we treat text replacement as an image restoration problem across three explicit passes:&lt;/p&gt;

&lt;p&gt;• Stroke Dilation Masking: Instead of blanking the whole bubble, our model generates a tight mask covering only the black ink strokes of the Japanese characters, expanded by a 2px morphological dilation to catch anti-aliasing artifacts.&lt;br&gt;
• Fast Inpainting Pass: We run an optimized resolution-robust inpainting model based on Large Mask Inpainting (LaMa with fast FFT convolutions). It predicts underlying textures, such as halftone screentones or paper grain, without washing out adjacent bubble boundaries.&lt;br&gt;
• Adaptive Canvas Typesetting: Using the HTML5 Canvas API on the client side, the translated target text is dynamically wrapped into the bubble's bounding polygon, automatically balancing font sizing, line height, and hyphenation to prevent text overflowing the bubble boundary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Edge Pipeline &amp;amp; Performance: Beating the GPU Latency Wall&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A 25-page chapter can easily choke backend inference if you stream raw 4K scans. We built an edge-optimized workflow inside our Next.js architecture to keep processing times under sub-second thresholds:&lt;/p&gt;

&lt;p&gt;• Client-Side Offloading: For the AI Manga Translator Chrome Extension (&lt;a href="https://ai-manga-translator.com/extension" rel="noopener noreferrer"&gt;https://ai-manga-translator.com/extension&lt;/a&gt;), the browser inspects DOM/Canvas elements directly on sites like Pixiv, BookWalker, and DLsite, extracting only dynamic canvas viewports rather than dumping massive full-page payloads.&lt;br&gt;
• Concurrent Chunk Dispatching: Extracted regions are processed via asynchronous micro-batches. While bubble #1 is getting inpainted, bubble #2 is already streaming translation from our fine-tuned comic LLM endpoint.&lt;br&gt;
• SSR Fallback with Next.js 14: On the web platform, we use Next.js server actions to handle parallel file streaming, allowing users to drop raw CBZ, ZIP, or PDF files and immediately inspect real-time progress via Server-Sent Events (SSE).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Architecture in Action&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Eliminating the friction between reading and understanding shouldn't mean turning art into flat, robotic documents.&lt;/p&gt;

&lt;p&gt;By treating comic pages as multi-layered graphic compositions rather than flat text files, we preserve the illustrator's line work while rendering native-feeling translations in real time.&lt;/p&gt;

&lt;p&gt;If you are curious to see how the segmentation and inpainting hold up on complex raw panels, you can test AI Manga Translator (&lt;a href="https://ai-manga-translator.com" rel="noopener noreferrer"&gt;https://ai-manga-translator.com&lt;/a&gt;) directly on the web with 5 free pages—no account sign-up required.&lt;/p&gt;

&lt;p&gt;What techniques are you using to handle non-standard text directions in your vision pipelines? Drop your thoughts and benchmarks below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjeppnsr8xpizbz8kicp6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjeppnsr8xpizbz8kicp6.png" alt="A deep dive into why generic OCR fails on vertical Japanese manga, how we eliminated white overlay boxes using LaMa inpainting, and our production Next.js pipeline." width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>ai</category>
      <category>softwareengineering</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>Keeping Character Names Consistent Across 200 Chapters: A Glossary Layer for LLM Translation</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Wed, 07 Oct 2026 14:17:59 +0000</pubDate>
      <link>https://dev.to/peterslab/keeping-character-names-consistent-across-200-chapters-a-glossary-layer-for-llm-translation-o4k</link>
      <guid>https://dev.to/peterslab/keeping-character-names-consistent-across-200-chapters-a-glossary-layer-for-llm-translation-o4k</guid>
      <description>&lt;p&gt;LLMs are surprisingly good at translating a single page of dialogue. Tone, slang, implied subjects, they handle a lot of it well.&lt;/p&gt;

&lt;p&gt;The problem shows up later. Translate chapter 1 and chapter 40 separately, and the same character can come out with two different spellings. A sect name gets transliterated in one chapter and translated literally in the next. A nickname quietly turns into the character's full name halfway through the series.&lt;/p&gt;

&lt;p&gt;Each page looks fine on its own. Read them in sequence and the story falls apart.&lt;/p&gt;

&lt;p&gt;This post is about a simple fix that works well in practice: a small glossary layer that sits between your text and the model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this happens&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most translation pipelines process one page or one chapter at a time. The model has no memory of what it decided before, so every page is a fresh guess.&lt;/p&gt;

&lt;p&gt;Names are especially fragile because:&lt;/p&gt;

&lt;p&gt;Japanese names have multiple readings. The same kanji can be read several ways, and the model has to guess.&lt;br&gt;
Romanization varies. Shō, Sho, Shou and Shoh are all "correct" for the same name.&lt;br&gt;
Chinese and Korean names often look like ordinary words. A name made of characters meaning "forest" and "wind" can get translated literally.&lt;br&gt;
Order varies. Family name first or last? The model may switch depending on context.&lt;/p&gt;

&lt;p&gt;Giving the model the whole series as context isn't realistic. What it actually needs is the decisions, not the text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The glossary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A glossary is just a list of source terms and how they should be rendered. Keep it boring and explicit:&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
from dataclasses import dataclass, field&lt;/p&gt;

&lt;p&gt;@dataclass&lt;br&gt;
class Term:&lt;br&gt;
    source: str            # as it appears in the original text&lt;br&gt;
    target: str            # how it should appear in the translation&lt;br&gt;
    kind: str = "name"     # name, place, technique, title, ...&lt;br&gt;
    note: str = ""         # optional hint for the model&lt;br&gt;
    aliases: list[str] = field(default_factory=list)&lt;/p&gt;

&lt;p&gt;glossary = [&lt;br&gt;
    Term("田中", "Tanaka", note="family name, keep family-name-first"),&lt;br&gt;
    Term("翔", "Shou", note="given name, use 'Shou' not 'Sho' or 'Shō'"),&lt;br&gt;
    Term("林风", "Lin Feng", note="person's name, do not translate the meaning"),&lt;br&gt;
    Term("九天雷掌", "Nine Heavens Thunder Palm", kind="technique"),&lt;br&gt;
]&lt;/p&gt;

&lt;p&gt;The note field matters more than it looks. "Do not translate the meaning" or "keep the honorific" gives the model the why, which helps it handle variations it hasn't seen before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Only send what's relevant&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You don't want to stuff a 500-entry glossary into every prompt. It costs tokens, and long irrelevant lists can actually make the model less reliable.&lt;/p&gt;

&lt;p&gt;Instead, scan the source text and include only the terms that appear in this chunk:&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
def relevant_terms(text: str, glossary: list[Term]) -&amp;gt; list[Term]:&lt;br&gt;
    hits = []&lt;br&gt;
    for term in glossary:&lt;br&gt;
        if term.source in text or any(a in text for a in term.aliases):&lt;br&gt;
            hits.append(term)&lt;br&gt;
    return hits&lt;/p&gt;

&lt;p&gt;For Japanese and Chinese, plain substring matching works surprisingly well because there are no spaces to worry about. For languages with inflection or particles attached to names, you may need a light normalization step first.&lt;/p&gt;

&lt;p&gt;One catch: short terms can produce false matches inside longer words. Sorting terms by length and matching longest first reduces that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Put it in the prompt as a hard constraint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Format the matched terms as a clear table and tell the model they are non-negotiable:&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
def build_prompt(text: str, terms: list[Term], target_lang: str) -&amp;gt; str:&lt;br&gt;
    lines = [f"- {t.source} → {t.target}" + (f"  ({t.note})" if t.note else "")&lt;br&gt;
             for t in terms]&lt;br&gt;
    glossary_block = "\n".join(lines) if lines else "(none)"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return f"""Translate the following manga dialogue into {target_lang}.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Use these renderings exactly. Do not change spelling, order or form:&lt;br&gt;
{glossary_block}&lt;/p&gt;

&lt;p&gt;Dialogue:&lt;br&gt;
{text}&lt;br&gt;
"""&lt;/p&gt;

&lt;p&gt;Short and explicit beats clever. Models follow a small, clearly formatted list far more reliably than a paragraph of instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check the output anyway&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even with the glossary in the prompt, models occasionally drift. A cheap post-check catches most of it:&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
def missing_terms(source: str, translation: str, terms: list[Term]) -&amp;gt; list[Term]:&lt;br&gt;
    """Terms that appear in the source but whose target is missing from the output."""&lt;br&gt;
    return [t for t in terms&lt;br&gt;
            if t.source in source and t.target.lower() not in translation.lower()]&lt;/p&gt;

&lt;p&gt;If something is missing, you have options: retry with a stronger instruction, flag the line for review, or log it so you can see which terms cause trouble.&lt;/p&gt;

&lt;p&gt;This check isn't perfect. A translation might legitimately use a pronoun instead of repeating a name. But as a signal, it's very useful, and it costs almost nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Growing the glossary over time&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The interesting part is how the glossary gets built. A few approaches that work:&lt;/p&gt;

&lt;p&gt;Seed it manually for the main cast. Ten to twenty entries cover most of the dialogue in a typical series.&lt;br&gt;
Ask the model to extract candidates. After translating a chapter, ask it to list proper nouns it encountered and how it rendered them. New entries go to a review queue rather than straight into the glossary.&lt;br&gt;
Promote on repetition. A name that appears in three or more chapters is worth locking in.&lt;br&gt;
Let humans override. If a reader or translator corrects a name, that correction should win everywhere, retroactively if possible.&lt;/p&gt;

&lt;p&gt;Scanlation teams have done this by hand for years: a shared document of every name, term and spelling decision for the series. The glossary layer is really just that practice, made machine-readable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it doesn't solve&lt;/strong&gt;&lt;br&gt;
Readings that only appear once. If a name's reading is given only in a tiny furigana on the first appearance and OCR misses it, the glossary starts with a wrong entry. Garbage in, consistent garbage out.&lt;br&gt;
Context-dependent rendering. Sometimes a character is called by a nickname in casual scenes and by their full name in formal ones. That's a style decision, and a flat glossary can flatten it.&lt;br&gt;
Honorifics. Whether "-san" or "-kun" stays attached to a name is a series-wide convention, best handled as a separate rule rather than per-name entries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrapping up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The core idea is simple: LLMs don't need your whole series as context. They need a short, explicit list of the decisions you've already made, scoped to the text in front of them, plus a cheap check that they actually followed it.&lt;/p&gt;

&lt;p&gt;It's a small piece of code, but in long-running translation work, consistency is often what separates something readable from something that feels machine-made. This is one of the problems I keep coming back to while working on &lt;a href="https://ai-manga-translator.com/" rel="noopener noreferrer"&gt;AI Manga Translator&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>llm</category>
      <category>python</category>
    </item>
    <item>
      <title>Beyond General Vision: How We Scaled Real-Time Manga Localization for Indie Hackers</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Mon, 21 Sep 2026 07:31:26 +0000</pubDate>
      <link>https://dev.to/peterslab/beyond-general-vision-how-we-scaled-real-time-manga-localization-for-indie-hackers-4jgp</link>
      <guid>https://dev.to/peterslab/beyond-general-vision-how-we-scaled-real-time-manga-localization-for-indie-hackers-4jgp</guid>
      <description>&lt;p&gt;Most general vision models fail miserably when pointed at a manga page. They get confused by the non-linear reading flow, misinterpret vertical typography, and butcher the typesetting inside speech bubbles.&lt;/p&gt;

&lt;p&gt;If you are building media localization tools using standard OCR and off-the-shelf LLMs, you are likely burning API credits on broken formatting. We ran into the same brick wall while building our platform—so here is how we engineered a robust, production-ready pipeline that actually works.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Bottleneck of Standard Vision Pipelines&lt;/strong&gt;&lt;br&gt;
When processing raw manga scans, standard multi-modal models stumble upon three classic roadblocks:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Panel Flow Trap:&lt;/strong&gt; Reading order in manga flows from right-to-left and top-to-bottom. General models default to Western left-to-right parsing, completely scrambling the narrative context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bubble Segmentation Noise:&lt;/strong&gt; Sound effects (SFX) overlapping with character art often get misclassified as dialogue text, leading to messy translation artifacts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typesetting Nightmares:&lt;/strong&gt; Translating text back into speech bubbles often results in overflow because characters require different aspect ratios and bounding box constraints depending on the target language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Our Engineered Solution&lt;/strong&gt;&lt;br&gt;
To bypass these hurdles, we decoupled the detection and translation phases using a streamlined Next.js 14 backend paired with a custom spatial-aware parser:&lt;/p&gt;

&lt;p&gt;TypeScript&lt;br&gt;
// Simplified pipeline snippet for bounding box validation&lt;br&gt;
async function processMangaPanel(imageBuffer: Buffer) {&lt;br&gt;
  const detectedBubbles = await spatialModel.detectBubbles(imageBuffer);&lt;br&gt;
  const sortedBubbles = sortMangaReadingOrder(detectedBubbles);&lt;/p&gt;

&lt;p&gt;return await translateAndTypeset(sortedBubbles);&lt;br&gt;
}&lt;br&gt;
By enforcing strict right-to-left sorting algorithms before sending text chunks to the translation engine, we reduced structural errors by over 40%.&lt;/p&gt;

&lt;p&gt;You can check out how we implemented this in production over at &lt;a href="https://ai-manga-translator.com/" rel="noopener noreferrer"&gt;AI Manga Translator&lt;/a&gt;—our live tool dedicated to solving raw comic translation for creators and readers worldwide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scale and Ship Fast&lt;/strong&gt;&lt;br&gt;
Building cool tech is only half the battle; distribution is where indie revenue happens. Once your article goes live on Dev.to, ensure you execute these deployment steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Google Search Console (GSC)&lt;/strong&gt;: Submit your new post URL for immediate indexing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sitemap Ping&lt;/strong&gt;: Ensure your publication or portfolio sitemap is up to date.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backlink Distribution&lt;/strong&gt;: Share the snippet on Reddit (r/IndieHackers, r/LocalLLaMA) and X to drive initial velocity.&lt;/p&gt;

&lt;p&gt;Keep shipping, stay resilient, and let’s keep pushing forward!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnfxpyjum8n4xwv8rwlur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnfxpyjum8n4xwv8rwlur.png" alt="Instant Japanese-to-English manga translation, handling vertical text and typesetting." width="800" height="999"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>nextjs</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How We Engineered an AI Manga Translator: Solving RTL OCR, Screentone Inpainting, and Edge Pipelines</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Wed, 16 Sep 2026 09:06:33 +0000</pubDate>
      <link>https://dev.to/peterslab/how-we-engineered-an-ai-manga-translator-solving-rtl-ocr-screentone-inpainting-and-edge-pipelines-2fog</link>
      <guid>https://dev.to/peterslab/how-we-engineered-an-ai-manga-translator-solving-rtl-ocr-screentone-inpainting-and-edge-pipelines-2fog</guid>
      <description>&lt;p&gt;&lt;em&gt;Building a production-ready manga translation pipeline means fighting vertical text, preserving fragile halftone screentones, and optimizing heavy image processing at the edge. Here is our architectural breakdown.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Building a translation tool sounds simple on paper: extract text, pass it to an LLM, translate it, and render it back onto the image. But the moment you point a standard OCR and translation pipeline at a raw Japanese manga chapter, everything breaks.&lt;/p&gt;

&lt;p&gt;Manga is not a standard document, and it is not a webtoon. It is a complex visual medium featuring vertical typography, right-to-left (RTL) reading flows, and intricate halftone dot patterns known as &lt;strong&gt;screentones&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Curious to see it in action? You can test the web app directly over at the &lt;a href="https://ai-manga-translator.com/" rel="noopener noreferrer"&gt;AI Manga Translator&lt;/a&gt; or install the &lt;a href="https://ai-manga-translator.com/extension" rel="noopener noreferrer"&gt;Chrome Extension&lt;/a&gt; to read raw chapters seamlessly right in your browser.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here is a technical look at the architectural challenges we faced while building this pipeline and how we solved them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The OCR &amp;amp; Layout Nightmare: RTL vs. LTR&lt;/strong&gt;&lt;br&gt;
Standard OCR pipelines (like basic Tesseract configurations or default cloud vision APIs) assume a Left-to-Right (LTR) horizontal flow. When applied to manga, they fail catastrophically:&lt;/p&gt;

&lt;p&gt;The Reading Order Crisis: Speech bubbles and text blocks must be parsed strictly from right to left, top to bottom. If your bounding box clustering algorithm assumes LTR, the dialogue sequence gets completely scrambled, turning a dramatic conversation into gibberish.&lt;/p&gt;

&lt;p&gt;Vertical Text (Tategaki): Japanese characters are frequently written vertically. Standard OCR engines often misinterpret vertical glyph bounding boxes as independent horizontal tokens.&lt;/p&gt;

&lt;p&gt;Our Fix: We implemented a custom layout-awareness parser wrapper that clusters speech bubbles based on spatial proximity while prioritizing right-to-left coordinate sorting before sending token payloads downstream.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Inpainting Challenge: Protecting Screentones&lt;/strong&gt;&lt;br&gt;
Once you extract and translate the Japanese text, you have to clear the original text box. This is where standard image editing algorithms fail.&lt;/p&gt;

&lt;p&gt;If you use naive pixel-filling or aggressive blurring to erase text, you destroy the screentones—the delicate dot patterns used by mangakas to create shading and gradients. A bad inpainting pass leaves ugly white smudges or muddy grey patches over the artwork.&lt;/p&gt;

&lt;p&gt;Our Fix: We built a context-aware inpainting pipeline optimized for comic book line art. By isolating text bounding masks from the underlying vector/raster grid, the model repairs only the pixels occupied by the glyphs while preserving the surrounding halftone frequency and character linework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Edge-Optimized Performance and Frontend Rendering&lt;/strong&gt;&lt;br&gt;
Manga pages are heavy assets. Processing multi-page chapters via slow server-side Python monoliths introduces massive latency, killing the user experience during rapid chapter binge-reading.&lt;/p&gt;

&lt;p&gt;To keep the application fast and responsive, our tech stack relies on a high-performance architecture:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next.js &amp;amp; Edge Runtime&lt;/strong&gt;: Utilizing Vercel Edge routing to handle lightweight proxying and session states instantly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Client-Server Hybrid Pipelines&lt;/strong&gt;: Offloading initial asset preprocessing and utilizing optimized API endpoints to process image slices concurrently without choking bandwidth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
Building vertical SaaS tools in the indie hacking space forces you to solve hyper-specific engineering problems that generic APIs ignore. By treating manga translation as an advanced computer vision and layout problem rather than a simple text translation wrapper, we built a pipeline that respects the art as much as the language.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9r7w6ej7ma06yx9i7jh4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9r7w6ej7ma06yx9i7jh4.png" alt="Pipeline architecture: From raw RTL spatial parsing to context-aware inpainting and typesetting." width="800" height="999"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>ai</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How I Built a Programmatic SEO Architecture with Next.js 14 and SSR for AI Apps</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Mon, 10 Aug 2026 02:36:12 +0000</pubDate>
      <link>https://dev.to/peterslab/how-i-built-a-programmatic-seo-architecture-with-nextjs-14-and-ssr-for-ai-apps-4ine</link>
      <guid>https://dev.to/peterslab/how-i-built-a-programmatic-seo-architecture-with-nextjs-14-and-ssr-for-ai-apps-4ine</guid>
      <description>&lt;p&gt;A practical breakdown of combining SSR, Next.js 14 App Router, and dynamic intent pages to drive organic traffic while managing AI API overhead.&lt;br&gt;
When building an AI application, driving initial user acquisition without a massive ad budget comes down to one critical engineering decision: how you handle your dynamic landing pages for search engines.&lt;/p&gt;

&lt;p&gt;While building &lt;a href="https://personalizedsong.ai/" rel="noopener noreferrer"&gt;PersonalizedSong.ai&lt;/a&gt;—a platform that transforms personal stories and shared memories into custom, studio-quality tracks—I knew organic search was going to be our main growth engine.&lt;/p&gt;

&lt;p&gt;However, user intent in the gifting space is fragmented:&lt;/p&gt;

&lt;p&gt;custom birthday song&lt;/p&gt;

&lt;p&gt;anniversary gifts for wife&lt;/p&gt;

&lt;p&gt;personalized song for husband&lt;/p&gt;

&lt;p&gt;Instead of manually creating dozens of static routes, I architected a dynamic, Programmatic SEO (pSEO) system built on Next.js 14. Here is how it works under the hood and why SSR was non-negotiable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Why Client-Side Rendering (CSR) Fails for Intent-Based AI SaaS&lt;/strong&gt;&lt;br&gt;
Many modern AI wrappers are built as heavy Single Page Applications (SPAs) rendered purely on the client side. While this keeps initial development fast, it creates a massive SEO disadvantage:&lt;/p&gt;

&lt;p&gt;Hydration Delays for Crawlers: Even though search bots have gotten better at executing JavaScript, reliant CSR routes often delay rendering key structured data.&lt;/p&gt;

&lt;p&gt;Dynamic Meta Tags: Social previews (OpenGraph) and dynamic JSON-LD schemas need to be served instantly in the raw HTML payload for proper indexing and social sharing.&lt;/p&gt;

&lt;p&gt;By leveraging Next.js 14 App Router with Server-Side Rendering (SSR), every dynamic intent page evaluates the incoming request, fetches the corresponding metadata, and returns fully-rendered HTML straight to the edge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Dynamic Route Architecture&lt;/strong&gt;&lt;br&gt;
Using Next.js 14, dynamic routes allow us to serve thousands of long-tail keyword combinations through unified dynamic pages:&lt;/p&gt;

&lt;p&gt;TypeScript&lt;br&gt;
// app/[occasion]/page.tsx&lt;br&gt;
import { Metadata } from 'next';&lt;br&gt;
import { getOccasionData } from '@/lib/seo-data';&lt;/p&gt;

&lt;p&gt;type Props = {&lt;br&gt;
  params: { occasion: string };&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;export async function generateMetadata({ params }: Props): Promise {&lt;br&gt;
  const data = await getOccasionData(params.occasion);&lt;/p&gt;

&lt;p&gt;return {&lt;br&gt;
    title: &lt;code&gt;${data.title} | Personalized Song Generator&lt;/code&gt;,&lt;br&gt;
    description: data.description,&lt;br&gt;
    openGraph: {&lt;br&gt;
      title: data.ogTitle,&lt;br&gt;
      images: [data.ogImage],&lt;br&gt;
    },&lt;br&gt;
  };&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;export default async function OccasionPage({ params }: Props) {&lt;br&gt;
  const data = await getOccasionData(params.occasion);&lt;/p&gt;

&lt;p&gt;return (&lt;br&gt;
    &lt;/p&gt;
&lt;br&gt;
      &lt;h1&gt;{data.heading}&lt;/h1&gt;
&lt;br&gt;
      &lt;p&gt;{data.subheading}&lt;/p&gt;
&lt;br&gt;
      {/* Interactive Creation Form Component */}&lt;br&gt;
    &lt;br&gt;
  );&lt;br&gt;
}

&lt;p&gt;&lt;strong&gt;3. Balancing SSR Performance with API Costs&lt;/strong&gt;&lt;br&gt;
In a typical AI app, you don't want your server rendered pages hitting expensive AI LLMs or music generation endpoints on every single request or bot crawl.&lt;/p&gt;

&lt;p&gt;The architecture separates Intent &amp;amp; Pre-rendering from Audio Generation:&lt;/p&gt;

&lt;p&gt;SSR Layer: Delivers lightweight, ultra-fast pre-rendered HTML containing structural context, custom prompts, schema markup, and UI controls.&lt;/p&gt;

&lt;p&gt;Client/API Layer: The actual AI audio generation is triggered only upon user interaction (answering our 4 prompt questions).&lt;/p&gt;

&lt;p&gt;This separation keeps server response times sub-second while protecting server logs and API keys from automated crawlers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Takeaways for Web Devs&lt;/strong&gt;&lt;br&gt;
Treat SEO as Architecture: Don't bolt on SEO as an afterthought. Structure your App Router layouts and page hierarchies from day one.&lt;/p&gt;

&lt;p&gt;Server-Side Render Intent Pages: Give crawlers pure HTML containing semantic tags and JSON-LD schemas.&lt;/p&gt;

&lt;p&gt;Decouple Dynamic Pages from Heavy AI APIs: Serve fast SSR pages first; trigger AI tasks strictly via authenticated client events.&lt;/p&gt;

&lt;p&gt;I’d love to hear how other full-stack devs are structuring their dynamic routes and handling SSR caching in Next.js 14! Check out PersonalizedSong.ai to see the frontend in action, and drop your questions in the comments below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjus44ynytnly1btawjqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjus44ynytnly1btawjqf.png" alt="PersonalizedSong.ai Homepage featuring dark theme and AI song generation call to action" width="800" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>showdev</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>How to Build Interactive "Tap and Hold" Twitter Images (And Why They Drive Engagement)</title>
      <dc:creator>Peter's Lab</dc:creator>
      <pubDate>Sat, 25 Jul 2026 17:27:05 +0000</pubDate>
      <link>https://dev.to/peterslab/how-to-build-interactive-tap-and-hold-twitter-images-and-why-they-drive-engagement-9di</link>
      <guid>https://dev.to/peterslab/how-to-build-interactive-tap-and-hold-twitter-images-and-why-they-drive-engagement-9di</guid>
      <description>&lt;p&gt;Have you ever stumbled across a tweet where the thumbnail shows one thing, but as soon as you &lt;strong&gt;&lt;a href="https://tapandhold.com/" rel="noopener noreferrer"&gt;tap and hold&lt;/a&gt;&lt;/strong&gt; on mobile (or open the full media viewer), a completely different image or secret message appears?&lt;/p&gt;

&lt;p&gt;It’s one of the most effective interactive media tricks on Twitter/X right now. Whether you are building an indie project, running a viral marketing campaign, or launching an interactive puzzle, "tap and hold" images spark instant curiosity and massively boost user engagement.&lt;/p&gt;

&lt;p&gt;In this post, we’ll break down the technical mechanics behind how tap-and-hold images work on Twitter's rendering engine and how you can implement or generate them easily.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Tech Behind Twitter’s "Tap and Hold" Magic&lt;/strong&gt;&lt;br&gt;
At first glance, it might look like Twitter supports native multi-layered image toggling. In reality, it relies on how Twitter's mobile feed renders transparent PNGs against its dark/light mode background and how the full-screen media viewer handles image compositing.&lt;/p&gt;

&lt;p&gt;Here is what happens under the hood:&lt;/p&gt;

&lt;p&gt;Alpha Channel &amp;amp; Transparency Rules: Twitter’s feed preview compresses and flattens image previews over a default background color (often white or light grey depending on the theme).&lt;/p&gt;

&lt;p&gt;Foreground vs. Background Contrast: By carefully manipulating pixel transparency, color channels, and alpha values, you can craft an image where:&lt;/p&gt;

&lt;p&gt;State A (Feed View): Low-contrast alpha pixels blend into the feed background, making only Layer 1 visible.&lt;/p&gt;

&lt;p&gt;State B (Tap &amp;amp; Hold / Viewer View): When a user taps and holds the image, Twitter opens the media lightbox with a dark/black backdrop. This shift in backdrop illumination instantly reveals Layer 2 while making Layer 1 blend into the dark background.&lt;/p&gt;

&lt;p&gt;Understanding color matrix transformations and PNG alpha channel encoding is essential if you are constructing this manually via canvas or WebGL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Create Tap and Hold Images Programmatically or via Web Tools&lt;/strong&gt;&lt;br&gt;
If you want to build this into your own pipeline or quickly generate one for your next product launch, you don't need to manually spend hours tweaking alpha levels in Photoshop.&lt;/p&gt;

&lt;p&gt;You can check out our dedicated technical walkthrough and generator here:&lt;br&gt;
👉 &lt;a href="https://tapandhold.com/tools/how-to-make-tap-and-hold-images" rel="noopener noreferrer"&gt;How to Make Tap and Hold Images Guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to convert your images right away without writing custom image processing scripts, you can use the main tool at TapAndHold.com.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Concept (JavaScript / HTML5 Canvas Idea)&lt;/strong&gt;&lt;br&gt;
If you're building a custom client-side generator using HTML5 Canvas, the high-level steps look like this:&lt;/p&gt;

&lt;p&gt;JavaScript&lt;br&gt;
// Conceptual snippet for blending two images into a tap-and-hold PNG&lt;br&gt;
const canvas = document.createElement('canvas');&lt;br&gt;
const ctx = canvas.getContext('2d');&lt;/p&gt;

&lt;p&gt;// 1. Load preview image (Image A) and hidden image (Image B)&lt;br&gt;
// 2. Extract ImageData arrays for both images&lt;br&gt;
// 3. Calculate alpha values pixel-by-pixel so Image A shows on bright backgrounds &lt;br&gt;
//    and Image B reveals on dark backgrounds&lt;br&gt;
// 4. Export as a uncompressed PNG to preserve precise alpha thresholds&lt;br&gt;
Why Indie Hackers &amp;amp; Creators Are Using Tap and Hold Media&lt;br&gt;
Higher Engagement Rates: Interactive tweets require active participation from the user, signaling positive engagement signals to Twitter’s recommendation algorithm.&lt;/p&gt;

&lt;p&gt;Easter Eggs &amp;amp; Product Teasers: Perfect for showing "Before / After" code refactoring, revealing hidden discount codes, or teasing unreleased feature updates.&lt;/p&gt;

&lt;p&gt;Meme Culture: It fits seamlessly into modern social media mechanics where curiosity drives clicks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try It Out&lt;/strong&gt;&lt;br&gt;
If you're launching a product on X soon, give this format a try to see how your audience responds.&lt;/p&gt;

&lt;p&gt;Full Guide: &lt;a href="https://tapandhold.com/blog/how-to-make-tap-and-hold-images-for-x-twitter" rel="noopener noreferrer"&gt;How to Make Tap and Hold Images&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Main Tool: &lt;a href="https://tapandhold.com/" rel="noopener noreferrer"&gt;TapAndHold.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have you experimented with alpha-channel image tricks on Twitter or other social platforms before? Let’s chat in the comments!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>showdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
