This Python program fetches weather data from Weather.com, generates a speech-based weather report, and outputs it as an MP3 file with background music for radio stations. The report includes current weather, an 8-hour forecast in 2-hour increments, and a 3-day forecast.
weather_update.mp4
- Fetches current, hourly, and daily weather data from Weather.com API.
- Generates a detailed weather report with temperature, conditions, and forecasts.
- Converts the weather report text into speech using Google Cloud Text-to-Speech API.
- Adds background music with fade-in and fade-out effects to the speech audio.
- Outputs the final weather report as an MP3 file with metadata tags.
- Python 3.7 or higher
requestslibrarygoogle-cloud-texttospeechlibrarypydublibrarymutagenlibrary
To use the Google Cloud Text-to-Speech API, you need to create a Google Cloud service account and download a JSON key.
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to IAM & Admin > Service Accounts.
- Click Create Service Account.
- Enter a name for the service account and click Create.
- Grant the service account Editor permissions.
- Under Keys, click Add Key > Create new key and select JSON.
- Download the JSON key file.
- Save the file to a folder called /etc/radio_weather_report/
Place this file in a secure location, and set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of this file in your system.
To fetch weather data, you need to obtain a Weather.com API key.
- Open wunderground.com (Wunderground is owned by Weather.com).
- Right-click on the page and select View Page Source.
- Search for
"apiKey"in the source code. - Copy the value of the API key.
Install the required Python libraries:
requestsgoogle-cloud-texttospeechpydubmutagen
To run the weather report generation script automatically, you can create a cron job.
-
Open your crontab file by running:
crontab -e -
Add the following line to run the script every hour on the half hour:
5 * * * * /usr/bin/python3 /path/to/weather.py >> /path/for/log/weather.log 2>&1
This cron job will execute the script every hour at minute 5, logging output to /path/for/log/weather.log.
In the script, make sure to customize the following variables:
output_file: The path where the weather report MP3 file will be saved.radio_station: The name of your radio station.weather_report_name: The name you want for the weather report.WEATHER_API_KEY: The key you retrieved from wunderground.comLATITUDE= Latitude for Radio StationLONGITUDE= Longitude for Radio Station
- Pick a royalty-free background music track. You can find suitable music on sites like YouTube Audio Library, Free Music Archive, or Incompetech.
- Download file to /etc/radio_weather_report as music.mp3
Run the script manually to generate a weather report.
The script will fetch weather data, generate the weather report, convert it to speech, and output the report as an MP3 file with background music.
This project is licensed under the MIT License - see the LICENSE file for details.
- The Google Cloud Text-to-Speech API provides high-quality voice synthesis.
- The Weather.com API provides accurate weather data.
If you like this project, consider supporting it with a donation!