AISanity2 MIN READ
22.12.2025
.md

Automating Audio Narration with Sanity Blueprints and Google Text-to-Speech

Last updated: 25.12.2025

🎧

Automating Audio Narration with Sanity Blueprints and Google Text-to-Speech

Audio Narration

studio microphone

I recently built an automated audio narration pipeline for my blog using Sanity, Next.js, and Google Cloud Text-to-Speech. The goal was simple: whenever the actual content of a blog post changes, regenerate a high-quality MP3 narration automatically — without manual steps, wasted API calls, or accidental infinite loops.

The key to making this reliable was leaning into Sanity's native automation tools, especially Blueprints, delta detection, and GROQ projections.

The Core Idea

Instead of generating audio on every page request, the system reacts to content changes at the CMS level:

  1. A blog post is updated in Sanity
  2. A Blueprint triggers only on document updates
  3. Sanity's delta function is used to detect whether the body field actually changed
  4. If (and only if) the body changed, Sanity calls a secure webhook
  5. A Next.js API route generates narration using Google Text-to-Speech
  6. The resulting MP3 is uploaded back into Sanity as a file asset
  7. The post is patched with a reference to the audio file

This ensures narration is generated once per meaningful content change, not per request or per publish event.

Why Blueprints + Delta Matter

Sanity already knows exactly what changed in a document. By using delta I avoided fragile solutions like hashing Portable Text or doing deep JSON diffs. Combined with GROQ filters and projections, the Blueprint stays declarative, readable, and easy to maintain.

To prevent infinite loops (since uploading audio also updates the document), the function is only checking the delta in the body text and if the text audio file exist.

Why Store Audio in Sanity?

For a personal blog, storing the MP3 directly in Sanity works surprisingly well:

  • The audio is served via Sanity's CDN
  • Each post owns its narration
  • No extra storage service is required
  • Editorial state and content stay in one place

The Result

The end result is a fully automated, content-driven audio system:

  • No manual triggers
  • No unnecessary TTS calls
  • No client-side secrets
  • Clean separation of concerns

This setup scales well, respects cost limits, and fits naturally into Sanity's content model — exactly what I was aiming for.

Continue Reading
brewfather, mcp & ai
Home BrewingAI2 MIN

I Fed Brewfather's API to Claude and Built My Own MCP Server

Brewfather is a comprehensive app for homebrewers that manages recipe design, batch tracking, fermentation logs, water chemistry, and ingredient inventory, making it a central hub for homebrew recipes. An MCP (Model Context Protocol) server acts like a plugin that exposes local tools and data to an AI such as Claude, letting it call a locally run server without any cloud intermediary or custom UI. Using Brewfather’s REST API, the author fed the documentation to Claude and quickly generated a local MCP server that connects Brewfather to Claude Code. This setup enables three key capabilities: browsing and inspecting real Brewfather recipes, checking the brew schedule and batch stages, and verifying whether the ingredient inventory is sufficient for an upcoming brew day. The main benefit is turning brewing data into a conversational interface, so users can simply ask questions like whether they are ready to brew on a given day. Future extensions could include logging fermentation readings, auto-creating batches from recipes, and sending notifications as batches progress through stages.

Read post
Ai genreated image wat workflow
SanityAI3 MIN

Using the WAT Framework: Writing Sanity MCP Workflows That Make Claude Consistent and Reliable

The text explains why open-ended AI instructions like “write a blog post about TypeScript” lead to inconsistent results. Because models are probabilistic, they vary structure, miss fields, and overlook edge cases, which is problematic for repetitive, structured tasks such as publishing to a CMS. To solve this, it introduces the WAT framework: Workflows, Agents, Tools. Workflows are plain-language markdown SOPs that encode domain knowledge and specify steps. Agents (Claude) handle reasoning and decisions. Tools are deterministic scripts or APIs, like the Sanity MCP, that execute actions. This separation narrows the decision space and keeps behavior consistent across sessions. A concrete example is the draft_blog_post workflow, which fetches authors and categories from Sanity, requires outline approval, and strictly defines document shape and constraints, including a 5000-byte body limit. Workflows evolve through a self-improvement loop: each failure adds new rules and edge cases. To get started, you document repeatable tasks, inputs, tools, steps, and edge cases, store them in .claude/wat/workflows/, and reuse them for faster, cheaper, and more reliable AI-assisted work.

Read post