Skip to main content

MeditationAudioGenerator

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

Installation

pip install meditation-audio-generator-openai

Usage

To use the MeditationAudioGenerator class, you need to initialize it with various parameters and then run the pipeline to generate the meditation. The system uses binaural beats unless you switch them off. Note: when the meditation has been generated, the working directory is left in place but can be manually deleted. The audio file is 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 parameters 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. Sometimes a perfectly innocent meditation topic can trigger OpenAI's content filter. This will cause the meditation to abort. (But you can re-run from that point on by adjusting the pipeline, see below.)

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.
  • 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.
  • expansion_size: int - Size of the expansion for the text, if expand_on_section is True.
  • force_voice: str - Allows user to force selection of OpenAI voice, e.g., onyx.
  • power_ratio: float - Ratio (higher means louder voice) of the power of the binaural beats or ambient to the power of the voice audio.

Example Usages

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

from meditation_audio_generator import MeditationAudioGenerator

# Initialize the meditation audio generator
mag = MeditationAudioGenerator(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, audio_filename = mag.run_meditation_pipeline()
# subsections is a list of the generated meditation texts
# audio_filename is the path to the generated meditation audio file

Generate a 5-minute meditation 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_audio_generator import MeditationAudioGenerator

mag = MeditationAudioGenerator(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, audio_filename = mag.run_meditation_pipeline()

Generate a 20-minute affirmation without binaural beats:

from meditation_audio_generator import MeditationAudioGenerator

mag = MeditationAudioGenerator(length=20, api_key="YOUR_API_KEY",
                               topic="""You are loved""",
                               affirmations_only=True)
subsections, audio_filename = mag.run_meditation_pipeline()

Generate a 20-minute affirmation just repeating the phrase "I am a good person who deserves good things", without binaural beats:

from meditation_audio_generator import MeditationAudioGenerator

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

Generate a 5-minute affirmation directly from the provided text without binaural beats. 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_audio_generator import MeditationAudioGenerator

# Initialize the meditation audio generator
mag = MeditationAudioGenerator(length=5, api_key="YOUR_API_KEY",
                               topic="A beautiful poem",
                               two_voices=True,
                               balance_even=-0.85,
                               balance_odd=0.85)
subsections, audio_filename = mag.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. """)

Metadata

Release files for meditation-audio-generator-openai 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for meditation-audio-generator-openai 1.0.1
File Size Uploaded
meditation-audio-generator-openai-1.0.1.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for meditation-audio-generator-openai 1.0.1
File Interpreter ABI Platform
meditation_audio_generator_openai-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 35.8 kB

Release files / meditation-audio-generator-openai-1.0.1.tar.gz

Download URL meditation-audio-generator-openai-1.0.1.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ae8cd0f8cec71aa40170040c35a3c101f135525b3a1b8781e0303107ce8af501
BLAKE2b-256 checksum
How to use checksums
7a34c23434f143285ef5785f9946d8c9ab377d38aae71c4d2a68347f93bccf92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.4

Release files / meditation_audio_generator_openai-1.0.1-py3-none-any.whl

Download URL meditation_audio_generator_openai-1.0.1-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
435b47e48c8892692ddee4e764e7def61fae2cdf60c1f67ce4d65c70e5b3c55b
BLAKE2b-256 checksum
How to use checksums
c86cc34d782097d273a7114f33e5bc493afadaf942b04f85ad75bda07a2d475f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page