Manim Voiceover

repository·main·Indexed 43 days ago

https://github.com/manimcommunity/manim-voiceover

A plugin for the Manim animation engine that integrates voiceovers directly into the Python workflow. It supports manual recording via RecorderService, AI-generated speech through services like Gemini, Azure, and gTTS, and precise per-word animation synchronization using OpenAI Whisper.

Tokens
10.6K
Snippets
46
Records
58
Agent score
55%

What's inside Manim Voiceover

  1. Overview of Manim Voiceover

    main

    Manim Voiceover is a plugin for Manim that allows you to integrate voiceovers directly into your animation workflow using Python. It eliminates the need for external video editors by providing several key features:

    • Direct Python Integration: Add voiceovers to Manim videos without leaving your code.
    • Voice Recording: Record your own voice via a command-line interface during the rendering process.
    • AI Voice Generation: Use Text-to-Speech (TTS) services to generate automated voices.
    • Per-word Timing: Trigger animations at specific words in a voiceover (including manual recordings) using OpenAI Whisper for precise synchronization.
  2. Overview of Manim Voiceover features

    main

    Manim Voiceover is a plugin for Manim that allows you to integrate voiceovers directly into your animation workflow in Python, eliminating the need for external video editors.

    Key capabilities include:

    • Direct Python Integration: Add voiceovers to Manim videos without a video editor.
    • Microphone Recording: Record voiceovers during the rendering process using a CLI-based RecorderService.
    • AI Voice Generation: Use various free and proprietary AI services to generate voices automatically.
    • Per-word Timing: Trigger animations at specific words in the voiceover (including manual recordings) using OpenAI Whisper for precise synchronization.
  3. Compare available speech services

    main

    Manim Voiceover supports several speech services via the SpeechService base class. Choose a service based on your needs for quality, offline capability, and cost:

    ServiceQualityOffline?Paid/Account?Notes
    RecorderServiceN/AN/AN/AUtility to record your own voice via microphone.
    GeminiServiceVery goodNoYesRecommended for AI voices. Requires Python 3.11+ and Gemini API key.
    AzureServiceVery goodNoYes500min/month free quota. Requires Azure account.
    ElevenLabsServiceVery goodNoYesHighly natural/emotive voices. Requires ElevenLabs account.
    GTTSServiceGoodNoNoFree Google Translate API (unreliable long-term).
    OpenAIServiceVery goodNoYesRequires OpenAI developer account.
    PyTTSX3ServiceBadYesNoRequires espeak. Unreliable on Mac.
  4. How to implement scene translation using gettext

    main

    Manim Voiceover uses the gettext convention to support multilingual scenes. To implement this, you wrap your voiceover strings in a translation function (conventionally named _()). This allows the system to look up the strings in .po files based on the provided LOCALE and DOMAIN.

    Workflow:

    1. Set LOCALE and DOMAIN environment variables.
    2. Use get_gettext() from manim_voiceover.translate to initialize the translation function.
    3. Wrap all text arguments in self.voiceover() with the _() function.
    4. Use a TTS service (like GTTSService) configured with the appropriate lang parameter.
    import os
    from manim import *
    from manim_voiceover import VoiceoverScene
    from manim_voiceover.services.gtts import GTTSService
    from manim_voiceover.translate import get_gettext
    
    # 1. Setup environment variables
    LOCALE = os.getenv("LOCALE")
    DOMAIN = os.getenv("DOMAIN")
    
    # 2. Initialize the gettext function
    _ = get_gettext()
    
    class TranslationExample(VoiceoverScene):
        def construct(self):
            # 3. Set TTS language via LOCALE
            self.set_speech_service(GTTSService(lang=LOCALE))
    
            # 4. Wrap strings in _()
            with self.voiceover(text=_("This circle is drawn as I speak.")) as tracker:
                self.play(Create(Circle()), run_time=tracker.duration)
  5. Verify Manim Voiceover installation

    main

    To ensure your installation is working correctly, download the gtts-example.py and run it using Manim. Note that the gTTS provider requires an active internet connection to communicate with the Google Translate API.

    wget https://github.com/ManimCommunity/manim-voiceover/raw/main/examples/gtts-example.py
    manim -pql gtts-example.py --disable_caching
  6. Install PortAudio and PyAudio for voice recording

    main

    If you want to record voiceovers during rendering, you must install PyAudio, which depends on the PortAudio system library. Installation steps vary by operating system:

    # Debian/Ubuntu
    sudo apt install portaudio19-dev
    sudo pip install pyaudio
    # OR
    sudo apt install python3-pyaudio
    
    # macOS
    brew install portaudio
    pip install pyaudio
    
    # Windows
    python -m pip install pyaudio
  7. Explore the Manim Voiceover Example Gallery

    main
    The Manim Voiceover example gallery provides best-practice code snippets for various library functionalities. You can find a complete list of examples in the examples/ directory of the repository. These examples are licensed under the MIT license and are intended to be copied and used in your own projects.