AI272/speaker / ppt-speech-writer
ppt-speech-writer
VerifiedRead a real .pptx using text extraction, OOXML inspection, slide rendering, OCR, visual inventory, and vision-capable screenshot review; then write academic speaker notes grounded in every visible slide element, generate a complete display-version document, and inject clean notes into the PowerPoint notes pane. Use when the user wants speaker notes, presenter notes, a speech script, narration, or annotated notes for an existing PowerPoint deck, especially when slides contain images, charts, tables, SmartArt, axes, legends, or screenshot text.
| File | Kind | Size |
|---|---|---|
| LOGIC.md | markdown | 11.8 KB |
| SKILL.md | skill md | 21.2 KB |
| scripts/inject_notes.pyexecutable | script | 3.7 KB |
| scripts/read_slides.pyexecutable | script | 9.1 KB |
| scripts/render_slides.pyexecutable | script | 2.6 KB |
| scripts/vision_review.pyexecutable | script | 5.5 KB |
| scripts/visual_inventory.pyexecutable | script | 7.8 KB |
| scripts/write_display_docx.pyexecutable | script | 7.6 KB |
scripts/visual_inventory.py
View on GitHub#!/usr/bin/env python3
"""Create a slide-by-slide visible-element inventory.
This combines structured extraction, rendered slide image paths, and optional
OCR output. The inventory is intended to guide speaker-note coverage.
"""
from __future__ import annotations
import argparse
import json
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
def _tesseract(image: Path) -> str:
exe = shutil.which("tesseract")
if not exe:
return ""
# Resolve symlinks: tesseract's leptonica fopenReadStream can fail to open a
# path that traverses a symlinked directory (e.g. macOS /tmp -> /private/tmp).
try:
image = Path(image).resolve()
except OSError:
pass
result = subprocess.run(
[exe, str(image), "stdout"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
)
if result.returncode != 0:
return ""
text = result.stdout.decode("utf-8", errors="ignore")
return "\n".join(line.strip() for line in text.splitlines() if line.strip())
def run_ocr(image: Path) -> str:
"""OCR the entire rendered slide image."""
return _tesseract(image)
def picture_regions(shapes: list[dict], slide_w_emu, slide_h_emu, img_w: int, img_h: int) -> list[dict]:
"""Map picture/media bounding boxes (EMU) to pixel crop boxes on the rendered image."""
if not (slide_w_emu and slide_h_emu and img_w and img_h):
return []
scale_x = img_w / slide_w_emu
scale_y = img_h / slide_h_emu
regions: list[dict] = []
for shape in shapes:
kind = str(shape.get("kind", "")).upper()
if "PICTURE" not in kind and "MEDIA" not in kind:
continue
bbox = shape.get("bbox_emu") or {}
left, top, width, height = bbox.get("left"), bbox.get("top"), bbox.get("width"), bbox.get("height")
if None in (left, top, width, height):
continue
x0 = max(0, int(left * scale_x))
y0 = max(0, int(top * scale_y))
x1 = min(img_w, int((left + width) * scale_x))
y1 = min(img_h, int((top + height) * scale_y))
if x1 - x0 < 8 or y1 - y0 < 8:
continue
regions.append(
{
"shape_index": shape.get("shape_index"),
"name": shape.get("name"),
"box": [x0, y0, x1, y1],
}
)
return regions
def ocr_regions(image: Path, shapes: list[dict], slide_w_emu, slide_h_emu) -> tuple[str, list[dict], str]:
"""OCR only the picture/media regions of a slide.
Returns (combined_text, per_region_results, scope_used). Falls back to a
full-image OCR when Pillow is unavailable or slide geometry is missing, so
OCR evidence is never silently dropped.
"""
try:
from PIL import Image
except ImportError:
return run_ocr(image), [], "full (Pillow unavailable)"
with Image.open(image) as im:
img_w, img_h = im.size
regions = picture_regions(shapes, slide_w_emu, slide_h_emu, img_w, img_h)
if not regions:
return "", [], "image-regions (no picture regions)"
results: list[dict] = []
for region in regions:
crop = im.crop(tuple(region["box"]))
tmp_path = Path(tempfile.mkstemp(suffix=".png")[1])
try:
crop.save(tmp_path)
text = _tesseract(tmp_path)
finally:
tmp_path.unlink(missing_ok=True)
if text:
results.append(
{"shape_index": region["shape_index"], "name": region["name"], "text": text}
)
combined = "\n".join(r["text"] for r in results)
return combined, results, "image-regions"
def slide_image(rendered_dir: Path, slide_num: int) -> Path | None:
candidates = [
rendered_dir / f"slide-{slide_num:03d}.png",
rendered_dir / f"slide-{slide_num}.png",
]
for candidate in candidates:
if candidate.exists():
return candidate
images = sorted(rendered_dir.glob("*.png"))
if 1 <= slide_num <= len(images):
return images[slide_num - 1]
return None
def summarize_shape(shape: dict) -> dict:
item = {
"shape_index": shape.get("shape_index"),
"name": shape.get("name"),
"kind": shape.get("kind"),
"bbox_emu": shape.get("bbox_emu"),
}
for key in ("text", "tables", "chart", "visual_note"):
if key in shape:
item[key] = shape[key]
return item
def build_inventory(extract: dict, rendered_dir: Path, use_ocr: bool, ocr_scope: str) -> dict:
slide_w = extract.get("slide_width_emu")
slide_h = extract.get("slide_height_emu")
slides = []
for slide in extract.get("slides", []):
num = int(slide["slide"])
image = slide_image(rendered_dir, num)
shapes = [summarize_shape(shape) for shape in slide.get("shapes", [])]
has_visual_object = any(
"PICTURE" in str(shape.get("kind", "")).upper()
or "CHART" in str(shape.get("kind", "")).upper()
or shape.get("chart")
or shape.get("tables")
for shape in shapes
)
ocr_text = ""
ocr_region_results: list[dict] = []
scope_used = "off"
if use_ocr and image:
if ocr_scope == "image-regions":
ocr_text, ocr_region_results, scope_used = ocr_regions(image, shapes, slide_w, slide_h)
else:
ocr_text = run_ocr(image)
scope_used = "full"
slides.append(
{
"slide": num,
"title": slide.get("title", ""),
"rendered_image": str(image) if image else "",
"needs_direct_visual_inspection": bool(has_visual_object or ocr_text),
"structured_elements": shapes,
"raw_ooxml_text_not_in_shapes": slide.get("raw_ooxml_text_not_in_shapes", []),
"ocr_scope": scope_used,
"ocr_text": ocr_text,
"ocr_regions": ocr_region_results,
"coverage_checklist": [
"title and text boxes",
"tables and important cells",
"chart axes, legend, labels, series, visible values",
"images, screenshots, diagrams, SmartArt, icons, and annotations",
"citations, footnotes, and small labels",
],
}
)
return {
"deck": extract.get("deck", ""),
"slide_count": extract.get("slide_count", len(slides)),
"rendered_dir": str(rendered_dir),
"slides": slides,
}
def main(argv: list[str]) -> int:
parser = argparse.ArgumentParser(description="Build visible-element inventory for a rendered .pptx.")
parser.add_argument("--extract", required=True, type=Path)
parser.add_argument("--rendered-dir", required=True, type=Path)
parser.add_argument("--output", required=True, type=Path)
parser.add_argument("--ocr", choices=["auto", "off"], default="auto")
parser.add_argument(
"--ocr-scope",
choices=["image-regions", "full"],
default="image-regions",
help="image-regions OCRs only picture/media crops (text boxes already come from XML); full OCRs the whole slide.",
)
args = parser.parse_args(argv)
if not args.extract.exists():
sys.stderr.write(f"Extract JSON not found: {args.extract}\n")
return 1
data = json.loads(args.extract.read_text(encoding="utf-8"))
inventory = build_inventory(data, args.rendered_dir, args.ocr == "auto", args.ocr_scope)
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(json.dumps(inventory, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
print(f"saved: {args.output}")
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv[1:]))
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |