Skip to content

AgriciDaniel/claude-blog / skills/blog-audio

blog-audio

Verified

Paid Gemini TTS audio for a finished blog post: summary, full read-aloud, or two-speaker dialogue, with an MP3 and an HTML5 embed. Asks for explicit consent before the first paid call. Runs only on an explicit request: /blog audio, "generate audio for this blog post", "narrate this blog post", "audio version of this post", or "podcast version of this post". Not for general speech or dictation questions.

FileKindSize
SKILL.mdskill md13.9 KB
references/models.mdmarkdown1.4 KB
references/voices.mdmarkdown6.4 KB
scripts/__init__.pyscript62 B
scripts/generate_audio.pyscript32.8 KB
scripts/requirements.lockother51.3 KB
scripts/requirements.txtmanifest499 B
scripts/run.pyscript3.6 KB
scripts/runtime_paths.pyscript2.6 KB
scripts/setup_environment.pyscript6.1 KB

scripts/setup_environment.py

View on GitHub
#!/usr/bin/env python3
"""
Environment Setup for Blog Audio Skill.

Manages virtual environment and dependencies automatically.
"""

import json
import os
import subprocess
import sys
import venv
from pathlib import Path

# Load only the helper shipped beside this installed script, never from CWD.
sys.path.insert(0, str(Path(__file__).resolve().parent))
from runtime_paths import resolve_runtime_paths


PIP_TIMEOUT_SECONDS = 900  # a hung index or build should fail, not block setup forever


def _output_tail(text: str | bytes | None, lines: int = 20) -> str:
    """Return the last few lines of captured process output."""
    if isinstance(text, bytes):
        text = text.decode("utf-8", "replace")
    return "\n".join((text or "").strip().splitlines()[-lines:])


class SkillEnvironment:
    """Manages skill-specific virtual environment"""

    def __init__(self, quiet: bool = False):
        self.skill_dir = Path(__file__).resolve().parent.parent
        self.venv_dir = resolve_runtime_paths(self.skill_dir, "blog-audio").venv
        self.quiet = quiet
        # Prefer the lock file (hash-verified). Fall back to loose
        # requirements.txt if no lock present (closes audit VULN-006).
        self.lock_file = self.skill_dir / "scripts" / "requirements.lock"
        self.requirements_file = self.skill_dir / "scripts" / "requirements.txt"

        if os.name == 'nt':
            self.venv_python = self.venv_dir / "Scripts" / "python.exe"
            self.venv_pip = self.venv_dir / "Scripts" / "pip.exe"
        else:
            self.venv_python = self.venv_dir / "bin" / "python"
            self.venv_pip = self.venv_dir / "bin" / "pip"

    def say(self, message: str) -> None:
        """Print a message unless JSON mode requested quiet output."""
        if not self.quiet:
            print(message)

    def ensure_venv(self) -> bool:
        """Ensure virtual environment exists and is set up"""
        if self.is_in_skill_venv():
            return True

        if not self.venv_dir.exists():
            self.say(f"Creating virtual environment in {self.venv_dir.name}/")
            try:
                venv.create(self.venv_dir, with_pip=True)
            except Exception as e:
                self.say(f"Failed to create venv: {e}")
                return False

        # Use lock file when available (hash-verified, reproducible).
        if self.lock_file.exists():
            install_args = ["install", "--require-hashes", "-r", str(self.lock_file)]
            install_label = "lock file (hash-verified)"
        elif self.requirements_file.exists():
            install_args = ["install", "-r", str(self.requirements_file)]
            install_label = "requirements.txt (no hash verification)"
        else:
            self.say("No requirements.txt or requirements.lock found; skipping install")
            return True

        self.say(f"Installing dependencies from {install_label}...")
        try:
            subprocess.run(
                [str(self.venv_pip)] + install_args,
                check=True, capture_output=True, text=True,
                timeout=PIP_TIMEOUT_SECONDS,
            )
            self.say("Dependencies installed")
            return True
        except subprocess.TimeoutExpired:
            self.say(f"Failed to install dependencies: pip did not finish within {PIP_TIMEOUT_SECONDS} seconds")
            return False
        except subprocess.CalledProcessError as e:
            self.say(f"Failed to install dependencies: {e}")
            tail = _output_tail(e.stderr)
            if tail:
                # stderr keeps --json output on stdout machine-readable.
                print(f"pip said:\n{tail}", file=sys.stderr)
            return False

    def is_in_skill_venv(self) -> bool:
        """Check if running in the skill's venv"""
        if hasattr(sys, 'real_prefix') or (
            hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix
        ):
            return Path(sys.prefix) == self.venv_dir
        return False

    def get_python_executable(self) -> str:
        """Get the correct Python executable"""
        if self.venv_python.exists():
            return str(self.venv_python)
        return sys.executable


def main():
    """Main entry point for environment setup"""
    import argparse

    parser = argparse.ArgumentParser(description='Setup Blog Audio skill environment')
    parser.add_argument('--check', action='store_true', help='Check if environment is set up')
    parser.add_argument('--json', action='store_true', help='Output structured JSON')
    args = parser.parse_args()

    try:
        env = SkillEnvironment(quiet=args.json)
    except ValueError as exc:
        if args.json:
            print(json.dumps({"status": "error", "error": str(exc)}))
        else:
            print(f"ERROR: {exc}")
        return 1

    if args.check:
        data = {
            "status": "ok" if env.venv_dir.exists() else "missing",
            "venv_dir": str(env.venv_dir),
            "python": env.get_python_executable() if env.venv_dir.exists() else None,
        }
        if args.json:
            print(json.dumps(data, indent=2))
            return 0 if env.venv_dir.exists() else 1
        if env.venv_dir.exists():
            print(f"Virtual environment exists: {env.venv_dir}")
            print(f"   Python: {env.get_python_executable()}")
        else:
            print("No virtual environment found")
        return 0 if env.venv_dir.exists() else 1

    if env.ensure_venv():
        if args.json:
            print(json.dumps({
                "status": "success",
                "venv_dir": str(env.venv_dir),
                "python": env.get_python_executable(),
            }, indent=2))
            return 0
        print(f"\nEnvironment ready!")
        print(f"   Virtual env: {env.venv_dir}")
        print(f"   Python: {env.get_python_executable()}")
    else:
        if args.json:
            print(json.dumps({
                "status": "error",
                "error": "Environment setup failed",
                "venv_dir": str(env.venv_dir),
            }, indent=2))
            return 1
        print("\nEnvironment setup failed")
        return 1


if __name__ == "__main__":
    sys.exit(main() or 0)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall