Skip to main content

A tool to create guided meditations like those found on YouTube using OpenAI.

Project description

MeditationVideoGenerator

The MeditationVideoGenerator class is a comprehensive solution for creating meditation videos. It leverages various libraries and services to generate text, synthesize speech, apply audio effects, and combine audio and video into a cohesive meditation experience.

Installation

pip install meditation-video-generator

Usage

To use the MeditationVideoGenerator class, you need to initialize it with various parameters and then run the pipeline to generate the meditation video. The generation also displays up to 30 suggested keywords you can use if uploading to social media. The system uses copyright-free (or copyright-YouTube-authorised) music/sound extracts unless you specify binaural beats. Note: when the meditation has been generated, the working directory is left in place but can be manually deleted. The video and audio file are copied into your own working directory.

Known Issues

GPT-4o is a statistical model and has therefore occasionally returned JSON that is not parsable by this code - this will raise and error and abort. Similarly any paramaters which attempt to control the elements returned from GPT-4o may not give the precise results expected. OpenAI have a rate limiter on their API. For example, if you create a meditation with dozens of text parts, then during synthesis you may get rate limited and the process aborts. Testing: occasionally the test pytest test_meditation_video_generator.py fails. This is due to the random nature of the meditation generation not being deterministic.

Initialization Parameters

  • topic: str - The topic of the meditation.
  • length: float - The length of the meditation in minutes.
  • api_key: str - OpenAI API key for accessing the speech synthesizer.
  • base_on_text: bool - If True, generate a meditation based on (but not consisting only of) the provided text.
  • text: str - Text to generate the meditation from.
  • num_sentences: int - Number of sentences in each part of the meditation.
  • bass_boost: bool - If True, apply bass boost to the voice audio.
  • balance_even: float - The balance for even segments (0.0 is centered, -1.0 is left, 1.0 is right).
  • balance_odd: float - The balance for odd segments (0.0 is centered, -1.0 is left, 1.0 is right).
  • two_voices: bool - If True, use two different voices for odd and even parts of the meditation.
  • expand_on_section: bool - If True, expand on each section of the meditation in more detail.
  • sounds_dir: str - Directory containing ambient sounds.
  • limit_parts: int - Limit the number of parts in the meditation.
  • num_loops: int - Allows all voice parts to be looped multiple times across the whole meditation (e.g. repeat a single affirmation).
  • in_spanish: bool - If True, generate the meditation in Spanish.
  • affirmations_only: bool - If True, generate affirmations only, not meditations.
  • binaural: bool - If True, generate binaural beats.
  • all_voices: bool - If True, choose from all available voices (not just the "best" two).
  • binaural_fade_out_duration: float - Duration of the fade-out at the end of the binaural beats.
  • binaural_file_gain_db: int - How much binaural beats should be quieter than the input voice audio.
  • start_beat_freq: float - Initial frequency difference for the binaural effect.
  • end_beat_freq: float - Final frequency difference for the binaural effect.
  • base_freq: float - Base frequency for the binaural beats.
  • sample_rate: int - Sample rate for the mixer.
  • num_samples_to_chop: int - Number of samples to chop off the beginning of the ambient sound files.
  • fade_in_time: float - Duration of the fade-in at the beginning of the ambient sound overlay.
  • fade_out_time: float - Duration of the fade-out at the end of the ambient sound overlay.
  • ambient_file_gain_db: int - How much ambient sound should be quieter than the input voice audio.

Example Usages

The following will generate a 10-minute meditation video with audio and a fixed image inspired by the Shire from Lord of the Rings, with approximately 7 sentences per meditation segment:

from meditation_video_generator import MeditationVideoGenerator

# Initialize the meditation video generator
mvg = MeditationVideoGenerator(length=10, api_key="YOUR_API_KEY",
                               topic="""A calming stroll through Hobbiton in the Shire""",
                               binaural=False,
                               num_sentences=7, 
                               bass_boost=True)
subsections, video_filename = mvg.run_meditation_pipeline()
# subsections is a list of the generated meditation texts
# video_filename is the path to the generated meditation video

Generate a 5-minute meditation video with binaural beats and more detailed wordings. The binaural base frequency is 220Hz and over the 5 minutes the beat frequency will reduce from 32Hz to 2Hz:

from meditation_video_generator import MeditationVideoGenerator

mvg = MeditationVideoGenerator(length=5, api_key="YOUR_API_KEY",
                               topic="""Dealing with work pressures""",
                               binaural=True,
                               bass_boost=True,
                               expand_on_section=True,
                               start_beat_freq = 32,  
                               end_beat_freq = 2,  
                               base_freq = 220)
subsections, video_filename = mvg.run_meditation_pipeline()

Generate a 20-minute affirmation video:

from meditation_video_generator import MeditationVideoGenerator

mvg = MeditationVideoGenerator(length=20, api_key="YOUR_API_KEY",
                               topic="""You are loved""",
                               affirmations_only=True)
subsections, video_filename = mvg.run_meditation_pipeline()

Generate a 20-minute affirmation video just repeating the phrase "I am a good person who deserves good things":

from meditation_video_generator import MeditationVideoGenerator

mvg = MeditationVideoGenerator(length=20, api_key="YOUR_API_KEY",
                               topic="I am a good person who deserves good things",
                               num_loops=200)
subsections, video_filename = mvg.run_meditation_pipeline(
    content = "I am a good person who deserves good things")

Generate a 5-minute affirmation video directly from the provided text. Use two different voices for odd and even parts of the meditation with one voice on the left and the other on the right. Note the double newlines in the content string:

from meditation_video_generator import MeditationVideoGenerator

# Initialize the meditation video generator
mvg = MeditationVideoGenerator(length=5, api_key="YOUR_API_KEY",
                               topic="A beautiful poem",
                               two_voices=True,
                               balance_even=-0.85,
                               balance_odd=0.85)
subsections, video_filename = mvg.run_meditation_pipeline(
    content = """Do not stand at my grave and weep

    I am not there. I do not sleep.
    
    I am a thousand winds that blow.
    
    I am the diamond glints on snow.
    
    I am the sunlight on ripened grain.
    
    I am the gentle autumn rain.
    
    When you awaken in the morning's hush
    
    I am the swift uplifting rush
    
    Of quiet birds in circled flight.
    
    I am the soft stars that shine at night.
    
    Do not stand at my grave and cry;
    
    I am not there. I did not die. """)

Generate just the image and video and keywords, assuming a previous run of the pipeline did the rest:

from meditation_video_generator import MeditationVideoGenerator

# Initialize the meditation video generator
mvg = MeditationVideoGenerator(length=20, api_key="YOUR_API_KEY",
                               topic="""Python coders are the best""",
                               affirmations_only=True)
mvg.pipeline = {
            "texts": False,
            "audio_files": False,
            "combine_audio_files": False,
            "audio_fx": False,
            "background_audio": False,
            "image": True,
            "video": True,
            "keywords": True
        }
subsections, video_filename = mvg.run_meditation_pipeline()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meditation_video_generator_openai-1.0.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file meditation_video_generator_openai-1.0.0.tar.gz.

File metadata

File hashes

Hashes for meditation_video_generator_openai-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bf6f10011394957f4a7781f3f1cfad631c063109e55060c944eb09cbc493dfaa
MD5 b913b522018a8e8b002d06b4c0608869
BLAKE2b-256 8cc45bcd634a2d52ab9a1633c85d71c8a7d00222206eda740c3b9109858a8927

See more details on using hashes here.

File details

Details for the file meditation_video_generator_openai-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for meditation_video_generator_openai-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a98073ffe132539215a8e2cd53b69de81e475f9ad36d6aa1ce669e2d7ee93bc
MD5 161ae5b70b395645481139e4f02b3868
BLAKE2b-256 c614910079ab1178159ce9bfe248330488e3fe5a668d95105bcee8a47f266cfa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page