Skip to content

Commit

Permalink
Make Example Use Manim-Voiceover
Browse files Browse the repository at this point in the history
  • Loading branch information
taibeled committed Nov 11, 2024
1 parent a058cb4 commit 0e0007a
Show file tree
Hide file tree
Showing 5 changed files with 3,446 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ paper/media/
coverage.xml

rendering_times.csv

# Manim Voice Over
.env
59 changes: 39 additions & 20 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
# flake8: noqa: F403, F405
# type: ignore

from manim_voiceover import VoiceoverScene
from manim_voiceover.services.gtts import GTTSService
OPENAI = False

from manim_slides import Slide, ThreeDSlide
from manim_slides.slide import MANIM, MANIMGL
from manim_slides.slide import MANIM, MANIMGL, MANIM_VOICEOVER

if MANIM:
from manim import *
elif MANIMGL:
from manimlib import *

if MANIM_VOICEOVER:
from manim_voiceover import VoiceoverScene
if OPENAI:
from manim_voiceover.services.openai import OpenAIService as SpeechService
else:
from manim_voiceover.services.gtts import GTTSService as SpeechService

class BasicExample(Slide, VoiceoverScene):
def construct(self):
self.set_speech_service(GTTSService())
if not MANIM_VOICEOVER:
class BasicExample(Slide):
def construct(self):
circle = Circle(radius=3, color=BLUE)
dot = Dot()

circle = Circle(radius=3, color=BLUE)
dot = Dot()
self.play(GrowFromCenter(circle))

with self.voiceover(text="This is a circle") as tracker:
self.play(GrowFromCenter(circle), run_time=tracker.duration)
self.next_slide(loop=True)
self.play(MoveAlongPath(dot, circle), run_time=2, rate_func=linear)
self.next_slide()

self.next_slide(loop=True)
with self.voiceover(text="Now a dot is moving along the circle") as tracker:
self.play(
MoveAlongPath(dot, circle), rate_func=linear, run_time=tracker.duration
)
self.next_slide()
self.play(dot.animate.move_to(ORIGIN))
else:
class BasicExample(Slide, VoiceoverScene):
def construct(self):
self.set_speech_service(SpeechService())

circle = Circle(radius=3, color=BLUE)
dot = Dot()

with self.voiceover(text="This is a circle") as tracker:
self.play(GrowFromCenter(circle), run_time=tracker.duration)

self.next_slide(loop=True)
with self.voiceover(text="Now a dot is moving along the circle") as tracker:
self.play(
MoveAlongPath(dot, circle), rate_func=linear, run_time=tracker.duration
)
self.next_slide()

with self.voiceover(
text="Now the dot is moving back to the center of the circle"
) as tracker:
self.play(dot.animate.move_to(ORIGIN), run_time=tracker.duration)
with self.voiceover(
text="Now the dot is moving back to the center of the circle"
) as tracker:
self.play(dot.animate.move_to(ORIGIN), run_time=tracker.duration)


class ConvertExample(Slide):
Expand Down
2 changes: 2 additions & 0 deletions manim_slides/slide/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__all__ = [
"MANIM",
"MANIMGL",
"MANIM_VOICEOVER",
"API_NAME",
"Slide",
"ThreeDSlide",
Expand Down Expand Up @@ -48,6 +49,7 @@ def __init__(self) -> None:

MANIM: bool = API_NAME == "manim"
MANIMGL: bool = API_NAME == "manimlib"
MANIM_VOICEOVER: bool = "manim_voiceover" in sys.modules

if MANIM:
try:
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ docs = [
"sphinxext-opengraph>=0.7.5",
]
full = [
"manim-slides[magic,manim,sphinx-directive]",
"manim-slides[magic,manim,sphinx-directive,voiceover]",
]
magic = ["manim-slides[manim]", "ipython>=8.12.2"]
manim = ["manim>=0.18.0"]
Expand All @@ -65,6 +65,9 @@ pyqt6-full = ["manim-slides[full,pyqt6]"]
pyside6 = ["pyside6>=6.6.1"]
pyside6-full = ["manim-slides[full,pyside6]"]
sphinx-directive = ["docutils>=0.20.1", "manim-slides[manim]"]
voiceover = [
"manim-voiceover[all]>=0.3.7",
]
tests = [
"manim-slides[full,manimgl,pyqt6,pyside6,sphinx-directive]",
"pytest>=7.4.0",
Expand Down Expand Up @@ -232,4 +235,5 @@ override-dependencies = [
"manimpango>=0.5.0,<1.0.0",
"numpy<=1.24;python_version < '3.12'",
"numpy>=1.26;python_version >= '3.12'",
"openai-whisper==20240927",
]
Loading

0 comments on commit 0e0007a

Please sign in to comment.