给视频添加画外音¶
制作带有画外音的完整视频比制作纯视觉的Manim场景更为复杂。视频渲染完成后,需要使用视频编辑软件来添加画外音。这个过程可能很困难且耗时,因为它需要大量的规划和准备工作。
为了简化给视频添加画外音的过程,我们创建了 Manim Voiceover,这是一个允许你直接在 Python 中为场景添加画外音的插件。要安装它,请运行
pip install "manim-voiceover[azure,gtts]"
访问安装页面了解有关如何安装 Manim Voiceover 的更多详细信息。
基本用法¶
Manim Voiceover 允许您…
直接在 Python 中为 Manim 视频添加画外音,无需使用视频编辑器。
通过简单的命令行界面,在渲染期间使用麦克风录制画外音。
使用来自各种免费和专有服务的自动生成 AI 声音来开发动画。
它提供了一个非常简单的 API,允许您指定画外音脚本,然后在渲染期间录制它。
from manim import *
from manim_voiceover import VoiceoverScene
from manim_voiceover.services.recorder import RecorderService
# Simply inherit from VoiceoverScene instead of Scene to get all the
# voiceover functionality.
class RecorderExample(VoiceoverScene):
def construct(self):
# You can choose from a multitude of TTS services,
# or in this example, record your own voice:
self.set_speech_service(RecorderService())
circle = Circle()
# Surround animation sections with with-statements:
with self.voiceover(text="This circle is drawn as I speak.") as tracker:
self.play(Create(circle), run_time=tracker.duration)
# The duration of the animation is received from the audio file
# and passed to the tracker automatically.
# This part will not start playing until the previous voiceover is finished.
with self.voiceover(text="Let's shift it to the left 2 units.") as tracker:
self.play(circle.animate.shift(2 * LEFT), run_time=tracker.duration)
要开始使用 Manim Voiceover,请访问快速入门指南。
访问示例库以查看 Manim Voiceover 的实际应用示例。