Ken Andersen's blog about technology related subjects.
Saturday, October 24, 2026
Weather Forecasting on Low Power FM Radio
Every radio station needs news and weather. A couple of years ago, KVWJ had a volunteer person to prepare and record forecasts. These would be played on the air twice an hour. A move across the country took our volunteer away.
I got to wondering if it would be possible to pull weather data via API, format it in a way that could be reported, and send it off to an AI service to get a human voice in mp3 format. It turns out the mp3 part was easy. It was the formatting of the weather data into a text report that was the difficult part.
The station pulled from openweathermap.org for a little while, but the forecasts seemed to be more for the Salt Lake area. We then used the tomorrow.io API for over a year. The data from tomorrow.io seemed more accurate, but the data was returned in hourly increments. We had to make some guesses based on these hourly reports when creating morning and evening forecasts.
Recently a listener contacted the station and said that the programming would be perfect if there were more accurate weather forecasts. I got to exploring our weather data again. I found consistent reports saying that Microsoft's Azure Maps Weather API was the most accurate. The problem was that there was a cost associated with this service that our station could not afford.
After more research I found that official non-profit companies can receive grants to use as credits with Microsoft Azure. KVWJ is owned and operated by an officially recognized non-profit, Alumni Records, Inc. It was actually a pretty smooth process to apply for and receive the grant. With that obstacle out of the way, it was time to get to writing code!
The Azure Maps Weather API simply requires an API key and a latitude and longitude. You then make a GET request to atlas.microsoft.com with parameters for how many days of data you want and if you want imperial or metric units. This is the request I settled on using PowerShell:
$RequestHeaders = @{
"subscription-key" = $MicrosoftAPIKey
"Accept" = "application/json"
}
$weather_forecast = Invoke-RestMethod -Uri https://atlas.microsoft.com/weather/forecast/daily/json?api-version=1.1&query=$($Latitude),$($Longitude)&unit=imperial&duration=5" -Method GET -Headers $RequestHeaders
The data that comes back includes a "longPhrase" field that is formatted in a way that describes the conditions like you'd hear on a weather forecast on TV. I no longer had to parse data and construct my own phrasing! The phrasing could simply be combined with something like "KVWJ Weather" or "Hyrum Weather," plus the longPhrase field, and finally adding on the low and/or high temperature that comes back in the data. This results in phrasing similar to:
South valley weather: Partly cloudy overnight with low temps near 36. Mostly sunny and up to 58 on Sunday.
Not bad for an automated forecast! It's been shockingly accurate so far. A couple of weeks ago it even included phrasing that described that the showers we were getting were the remnants of tropical storm Rachel.
The station has been using OpenAI's API for speech. We are exploring the possiblity of switching over to Microsoft's API for this as well.
© The Ramblings of Ken Powered by Bootstrap , Blogger templates and RWD Testing Tool

No comments :
Post a Comment