为视频添加旁白¶
创建一个带有旁白的完整视频比创建纯视觉的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的实际示例。