返回顶部
m

manim-animation数学动画生成

Create mathematical animations with synchronized voiceover narration and subtitles using Manim Community and manim-voiceover. Use when users want to create animated videos with narration, math animations with voice, educational videos with subtitles, or any request involving Manim scene generation with TTS voiceover. Trigger phrases include: manim animation, math animation, animated video with voice, manim voiceover, create animation video, or any request to generate narrated mathematical/educat

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.3
安全检测
已通过
131
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

manim-animation

Manim动画:动画 + 配音 + 字幕生成器

作者: ericksun(孙自翔)

概述

本技能使用Manim Community生成数学/教育动画,集成manim-voiceover插件实现TTS语音旁白和同步字幕。所有处理均在本地运行——无需付费API。

核心能力:

  • - 🎬 动画生成:使用Manim创建数学公式、几何图形、图表等动画
  • 🎙️ 语音旁白:通过manim-voiceover插件集成TTS,实现动画与语音自动同步
  • 📝 字幕系统:场景内字幕(Manim文本)+ SRT外部字幕(ffmpeg烧录)
  • 🔄 一键流水线:描述需求 → 生成代码 → 渲染视频 → 烧录字幕

TTS引擎(推荐gTTS):

  • - gTTS(推荐):谷歌免费TTS,支持中文,无需API密钥
  • pyttsx3(备选):离线TTS,无需网络
  • Azure/OpenAI/ElevenLabs(高质量):需要付费API密钥

前置条件

🔍 一键环境检查

首次使用前,运行环境检查脚本验证所有依赖是否就绪:

bash
python3 {SKILLDIR}/scripts/checkenvironment.py

该脚本检查:

  • - ✅ Manim Community安装(manim命令)
  • ✅ manim-voiceover + gTTS插件
  • ✅ FFmpeg + libx264编码器(Manim硬编码依赖,必需
  • ✅ FFmpeg + libass(用于SRT字幕烧录)
  • ✅ Python依赖
  • ✅ 中文字体可用性

必需的系统工具

  • - Manim Community:pip install manim
  • FFmpeg(含libx264 + libass):Manim在视频渲染中硬编码使用libx264编码器;字幕烧录需要libass
- macOS(Homebrew):brew install ffmpeg(默认包含x264和libass) - macOS(Conda):conda install x264 -c conda-forge(⚠️ conda的ffmpeg默认不包含libx264) - Linux:sudo apt install ffmpeg libx264-dev libass-dev
  • - Python 3.9+ 和 pip

必需的Python包

bash

核心


pip install manim

配音 + TTS

pip install manim-voiceover[gtts]

可选(增强功能)

  • - pyttsx3:离线TTS(pip install manim-voiceover[pyttsx3])

⚡ 快速安装

bash
pip install manim manim-voiceover[gtts]

macOS(Homebrew)— 推荐,包含libx264 + libass

brew install ffmpeg

macOS(Conda)— 需要额外安装x264,否则Manim渲染会报UnknownCodecError: libx264

conda install x264 -c conda-forge

验证ffmpeg支持libx264和libass

ffmpeg -codecs 2>&1 | grep libx264 # 应显示:encoders: libx264 ffmpeg -filters 2>&1 | grep subtitles # 应显示:subtitles filter

工作流程

快速开始 — 一键运行

用户描述需求后,使用流水线脚本一键执行:

bash
python3 {SKILLDIR}/scripts/runpipeline.py \
--scenefile file.py> \
--scene_name \
--quality high \
--burn_subtitles

常用选项:

选项默认值描述
--scenefile必需Manim场景Python文件
--scenename
必需 | 场景类名 |
| --quality | high | 渲染质量:low/medium/high/production |
| --burn_subtitles | False | 是否使用ffmpeg烧录SRT字幕 |
| --speed | 1.35 | 播放速度倍率(如1.35表示1.35倍速;设为1.0禁用) |
| --preview | False | 渲染后自动打开预览 |
| --output_dir | ./output | 输出目录 |

完整工作流程(4步)

第1步:理解用户需求并生成Manim场景代码

根据用户描述,生成Manim场景Python文件。场景代码应遵循以下模式:

无配音模式(仅动画):

python
from manim import *

class MyScene(Scene):
def construct(self):
title = Text(标题, font_size=48, color=BLUE)
self.play(Write(title))
self.wait(1)

配音模式(动画 + 语音 + 字幕):

python
from manim import *
from manim_voiceover import VoiceoverScene
from manim_voiceover.services.gtts import GTTSService

class MyScene(VoiceoverScene):
def makesubtitle(self, text_str):
在屏幕底部创建带深色背景的字幕。
sub = Text(textstr, fontsize=22, color=WHITE, weight=BOLD)
# 防止字幕溢出左右边缘
maxwidth = config.framewidth - 1.0 # 每边0.5边距
if sub.width > max_width:
sub.scaletofitwidth(maxwidth)
sub.to_edge(DOWN, buff=0.4)
bg = BackgroundRectangle(sub, color=BLACK, fill_opacity=0.6, buff=0.15)
return VGroup(bg, sub)

def construct(self):
self.setspeechservice(GTTSService(lang=en))

sub_text = 欢迎来到演示
with self.voiceover(text=sub_text) as tracker:
sub = self.makesubtitle(sub_text)
title = Text(演示, font_size=48)
self.play(Write(title), FadeIn(sub), run_time=tracker.duration)

self.play(FadeOut(sub))
self.wait(0.3)

关键模式 — 配音上下文管理器:

python
with self.voiceover(text=语音文本) as tracker:
# tracker.duration = TTS语音时长(秒)
# 此块内的动画自动与语音同步
self.play(SomeAnimation(), run_time=tracker.duration)

with self.voiceover(text=...) as tracker 执行三项操作:

  1. 1. 调用TTS引擎生成语音音频
  2. 自动计算语音时长
  3. 提供tracker.duration以同步动画与语音

字幕最佳实践:

  • - 场景内字幕:使用makesubtitle()辅助函数在屏幕底部显示带深色背景的白色粗体文本
  • 溢出预防makesubtitle()自动检测字幕宽度,超出帧边界时按比例缩放(scaletofitwidth);长文本使用fontsize=22
  • 字幕同步:在配音块内的第一个self.play()中FadeIn(sub),确保字幕与语音同步出现——不要延迟
  • 在每个配音块开始时淡入字幕,结束后淡出
  • 字幕文本应与配音文本匹配

⚠️ 避免双重字幕: 如果场景代码已使用makesubtitle()渲染场景内字幕,不要再使用--burn_subtitles烧录SRT字幕,否则会出现两层重叠字幕。只选择一种方式:

  • - 方式A(推荐):在代码中使用makesubtitle()渲染字幕,不烧录SRT
  • 方式B:不在代码中渲染字幕,通过--burn_subtitles烧录SRT

第2步:配置渲染参数

在与场景文件相同的目录中创建manim.cfg:

ini
[CLI]
quality = high_quality
preview = False

[ffmpeg]
video_codec = h264

质量参考表:

质量标志分辨率FPSmanim.cfg值
-ql480p15lowquality
-qm | 720p | 30 | medium
quality |
| 高 | -qh | 1080p | 60 | high_quality |
| 生产 | -qp | 2160p | 60 | production_quality |

第3步:渲染视频

bash
manim render

输出路径模式:media/videos///.mp4

第4

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 manim-animation-en-1776061322 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 manim-animation-en-1776061322 技能

通过命令行安装

skillhub install manim-animation-en-1776061322

下载

⬇ 下载 manim-animation v1.0.3(免费)

文件大小: 16.62 KB | 发布时间: 2026-4-14 14:12

v1.0.3 最新 2026-4-14 14:12
Add required_tools (manim, ffmpeg with libx264+libass, python3), required_packages, and network_access metadata to SKILL.md frontmatter. Addresses OpenClaw finding about missing binary declarations.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部