How to add a speech bubble with Claude

A white comic speech bubble with a black outline pops out of the top of the bottle, its tail pointing down at it, and fills with the voiceover's words one by one as they're spoken.

Get this effect

  1. Switch to Code in your Claude Desktop App

  2. Install the skill (once)

    Show the prompt
    Install the Recharm video effects skill: download https://recharm-growth-staging.s3.us-east-2.amazonaws.com/website/downloads/recharm-video-effects.zip and unzip it into ~/.claude/skills
  3. Ask for the effect

    Add a speech bubble to input.mp4 using the word timings in words.json
    Bubble center, as shares of the frame width and height: (0.42, 0.11)
    Bubble width and height, as shares of the frame: (0.8, 0.19)

Several videos, several effects, one ask

Put your clips in the folder, mention them with @, and ask for everything at once. Claude runs one tested script after another on each clip, then joins them.

Add a speech bubble to @clip1.mp4, put a sale badge on @clip2.mp4, give @clip3.mp4 a VHS look, then join all three with crossfades.

Settings you can change

Ask Claude to change any of these, or edit them at the top of the script.

SettingDefaultWhat it does
CENTER(0.42, 0.11)Bubble center, as shares of the frame width and height.
SIZE(0.8, 0.19)Bubble width and height, as shares of the frame.
TAIL(0.5, 0.215)Where the tail points: the speaker's mouth or head.
TEXT0.058Text height as a share of the frame width.
HOLD0.6Seconds the bubble stays after the last word.

Without the skill

Don’t want to install the skill? Paste this prompt into Claude Code and Claude writes the script itself.

Show the prompt
Add a comic speech bubble to input.mp4 using the word timings in words.json. The bubble is a white (255, 255, 255) ellipse 80% of the frame width wide and 19% of the frame height tall, centered at 42% across and 11% down, with a black outline 0.9% of the frame width thick and a triangular tail whose tip points at 50% across and 21.5% down. It pops in 0.15 seconds before the first word, growing out of the tail's tip over 0.25 seconds with a slight overshoot. Inside it, the whole phrase is wrapped into centered lines no wider than 62% of the bubble's width, in bold black text 5.8% of the frame width tall, and each word appears at its start time while earlier words stay. The bubble stays 0.6 seconds after the last word ends, then shrinks back into the tail's tip over 0.25 seconds. Use Python with Pillow to draw it and ffmpeg to put it on the video (don't rely on ffmpeg's drawtext filter), keep the audio, and save it as output.mp4.

Run it without Claude

This is the exact script we tested. Save it as speech-bubble.py and run:

python3 speech-bubble.py input.mp4 words.json output.mp4
Show the script
#!/usr/bin/env python3
"""Speech bubble: a comic bubble pops up above the subject and fills with the words as they are spoken.

Usage: python3 speech-bubble.py input.mp4 words.json output.mp4
words.json holds word timings, for example from Whisper:
  [{"word": "This", "start": 0.30, "end": 0.69}, {"word": "serum", "start": 0.77, "end": 1.13}, ...]
Needs ffmpeg and Pillow (pip install pillow).
"""
import json
import math
import subprocess
import sys
from pathlib import Path

from PIL import Image, ImageDraw, ImageFilter, ImageFont

CENTER = (0.42, 0.11)   # bubble center, as shares of the frame width and height
SIZE = (0.8, 0.19)      # bubble width and height, as shares of the frame width and height
TAIL = (0.5, 0.215)     # where the tail's tip points (the speaker's mouth or head)
OUTLINE = 0.009         # outline thickness as a share of the frame width
TEXT = 0.058            # text height as a share of the frame width
WRAP = 0.62             # longest line as a share of the bubble width
LEAD = 0.15             # seconds before the first word that the bubble pops in
POP = 0.25              # seconds the pop in (and the pop out) takes
HOLD = 0.6              # seconds the bubble stays after the last word
FONTS = ["/System/Library/Fonts/Supplemental/Arial Bold.ttf",     # macOS
         "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",  # Linux
         "C:/Windows/Fonts/arialbd.ttf"]                          # Windows
FONT_FILE = next((f for f in FONTS if Path(f).exists()), None) or sys.exit("No bold font found: add one to FONTS")


def layout():
    """Wrap the words into lines that fit the bubble and return each word's position."""
    space = font.getlength(" ")
    lines, line = [], []
    for word in words:
        text = word["word"].strip()
        width = sum(font.getlength(t) for t, _ in line) + space * len(line) + font.getlength(text)
        if line and width > w * SIZE[0] * WRAP:
            lines.append(line)
            line = []
        line.append((text, word["start"]))
    lines.append(line)
    line_h = font.size * 1.2
    placed = []
    for row, line in enumerate(lines):
        x = w * CENTER[0] - (sum(font.getlength(t) for t, _ in line) + space * (len(line) - 1)) / 2
        y = h * CENTER[1] + (row - (len(lines) - 1) / 2) * line_h
        for text, start in line:
            placed.append((x, y, text, start))
            x += font.getlength(text) + space
    return placed


def bubble(img, s):
    """Paint the white ellipse and tail with a black outline, scaled by s around the tail's tip."""
    def at(x, y):
        return w * (TAIL[0] + (x - TAIL[0]) * s), h * (TAIL[1] + (y - TAIL[1]) * s)

    (cx, cy), (rx, ry) = CENTER, (SIZE[0] / 2, SIZE[1] / 2)
    shape = Image.new("L", (w, h))
    draw = ImageDraw.Draw(shape)
    draw.ellipse([*at(cx - rx, cy - ry), *at(cx + rx, cy + ry)], fill=255)
    draw.polygon([at(cx - 0.02, cy + ry * 0.7), at(cx + 0.12, cy + ry * 0.6), at(*TAIL)], fill=255)
    stroke = max(1, round(w * OUTLINE * s))
    img.paste("black", mask=shape.filter(ImageFilter.MaxFilter(2 * stroke + 1)))
    img.paste("white", mask=shape)


def scale(t):
    """0 before the bubble, overshooting to 1 as it pops in, back to 0 as it pops out."""
    start, end = words[0]["start"] - LEAD, words[-1]["end"] + HOLD
    if t < start or t >= end + POP:
        return 0
    if t >= end:
        return 1 - (t - end) / POP
    p = min(1, (t - start) / POP)
    return 1 + 2.7 * (p - 1) ** 3 + 1.7 * (p - 1) ** 2  # ease-out with a slight overshoot


def overlay(t):
    img = Image.new("RGBA", (w, h))
    s = scale(t)
    if s > 0:
        bubble(img, s)
        draw = ImageDraw.Draw(img)
        if s >= 0.98:
            for x, y, text, start in placed:
                if t >= start:
                    draw.text((x, y), text, font=font, anchor="lm", fill="black")
    return img


def probe(path):
    info = json.loads(subprocess.check_output(["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries",
                                               "stream=width,height,r_frame_rate:format=duration", "-of", "json", path]))
    s = info["streams"][0]
    num, den = s["r_frame_rate"].split("/")
    return s["width"], s["height"], s["r_frame_rate"], float(num) / float(den), float(info["format"]["duration"])


def render(src, out):
    """Draw overlay(t) on every frame of src and save to out, keeping the audio."""
    ff = subprocess.Popen(["ffmpeg", "-y", "-v", "error", "-i", src,
                           "-f", "rawvideo", "-pix_fmt", "rgba", "-s", f"{w}x{h}", "-r", rate, "-i", "-",
                           "-filter_complex", "[0:v][1:v]overlay=shortest=1,format=yuv420p[v]",
                           "-map", "[v]", "-map", "0:a?", "-c:v", "libx264", "-crf", "18", "-c:a", "copy", out],
                          stdin=subprocess.PIPE)
    for i in range(math.ceil(duration * fps)):
        ff.stdin.write(overlay(i / fps).tobytes())
    ff.stdin.close()
    if ff.wait():
        sys.exit("ffmpeg failed")


src, words_file, out = sys.argv[1:4]
words = json.loads(Path(words_file).read_text())
w, h, rate, fps, duration = probe(src)
font = ImageFont.truetype(FONT_FILE, round(w * TEXT))
placed = layout()
render(src, out)

Find 3x winning ads

Recharm cuts your ad footage into tagged, searchable clips: hooks, testimonials, product shots. Find the shots that win, add the effect with Claude, and ship 3x more ad edits.

Start 14-day free trial