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.
- 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.
- Fetch Email: The script connects to Gmail and retrieves the latest email from a predefined list of senders.
- Save Raw Content: The raw email text is saved to the
data/input_emailsdirectory. - Clean & Translate: The text is cleaned to remove boilerplate and then translated using an LLM. Intermediate files are stored in
data/cleaned_emailsanddata/translated_emails. - Generate Audio: The translated text is converted to an MP3 audio file.
- Adjust Speed: The audio speed is increased using
pytsmod. The final file is saved indata/generated_audio. - Send to Telegram: The MP3 file is sent as an audio message to a Telegram chat.
- Cache: The email's ID is cached to prevent reprocessing.
-
Clone the repository:
git clone <repository_url> cd <repository_name>
-
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
-
Create
.envfile: Create a.envfile 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_PASSWORDinstead of your regular Google account password.
- Allowed Senders: To specify which email newsletters to process, edit the
ALLOWED_EMAILS_ADDRESSlist inscripts/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_factorargument in thetext_to_audiocall withinmain.pyor directly in thetext_to_audio.pyfunction definition.
To run the full pipeline, execute the main.py script:
python main.pyThe script will log its progress to the console and to log files in the .logs directory.