Skip to content

marcolucchini/mail_to_audio_news_digest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Email to Audio News Digest

This project automates the process of converting email newsletters into audio summaries. It fetches emails from a specified Gmail account, cleans and translates the content, converts it to a high-quality audio file, and sends it to a Telegram chat. This is perfect for listening to your favorite newsletters on the go.

Features

  • Email Fetching: Connects to a Gmail account to fetch the latest emails from specified senders.
  • Content Processing: Uses OpenAI's GPT models to clean up HTML content and extract the core message.
  • Translation: Translates content from one language to another (e.g., English to Italian).
  • Text-to-Audio: Converts the processed text into natural-sounding speech using OpenAI's TTS model.
  • Audio Speed Control: Adjusts the speed of the generated audio for a customized listening experience (e.g., 1.2x speed).
  • Telegram Integration: Automatically sends the final audio file to a specified Telegram chat.
  • Caching: Keeps track of processed emails to avoid duplicates.
  • Configurable: Easily configure email senders, languages, and API keys.

Workflow

  1. Fetch Email: The script connects to Gmail and retrieves the latest email from a predefined list of senders.
  2. Save Raw Content: The raw email text is saved to the data/input_emails directory.
  3. Clean & Translate: The text is cleaned to remove boilerplate and then translated using an LLM. Intermediate files are stored in data/cleaned_emails and data/translated_emails.
  4. Generate Audio: The translated text is converted to an MP3 audio file.
  5. Adjust Speed: The audio speed is increased using pytsmod. The final file is saved in data/generated_audio.
  6. Send to Telegram: The MP3 file is sent as an audio message to a Telegram chat.
  7. Cache: The email's ID is cached to prevent reprocessing.

Setup and Installation

  1. Clone the repository:

    git clone <repository_url>
    cd <repository_name>
  2. Install dependencies: It's recommended to use a virtual environment.

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
    pip install -r requirements.txt
  3. Create .env file: Create a .env file in the project root and add the following credentials.

    # OpenAI API Key
    OPENAI_API_KEY="your_openai_api_key"
    
    # Gmail Credentials (use an App Password for security)
    EMAIL_ADDRESS="your_email@gmail.com"
    EMAIL_PASSWORD="your_gmail_app_password"
    
    # Telegram Bot Credentials
    TELEGRAM_BOT_TOKEN="your_telegram_bot_token"
    TELEGRAM_CHAT_ID="your_telegram_chat_id"

    Note on Gmail App Password: It is highly recommended to use an App Password for EMAIL_PASSWORD instead of your regular Google account password.

Configuration

  • Allowed Senders: To specify which email newsletters to process, edit the ALLOWED_EMAILS_ADDRESS list in scripts/constants.py.
    # scripts/constants.py
    ALLOWED_EMAILS_ADDRESS = [
        ("dan@tldrnewsletter.com", "TLDR AI"),
    ]
  • Audio Speed: You can change the default audio speed by modifying the speed_factor argument in the text_to_audio call within main.py or directly in the text_to_audio.py function definition.

Usage

To run the full pipeline, execute the main.py script:

python main.py

The script will log its progress to the console and to log files in the .logs directory.

About

Automatic tool to convert daily mail into daily audio like a podcast

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages