Published Sep 28, 2026, 12:30 PM EDT Nick Lewis is an editor at How-To Geek. He has been using computers for 20 years --- tinkering with everything from the UI to the Windows registry to device firmware. Before How-To Geek, he used Python and C++ as a freelance programmer. In college, Nick made extensive use of Fortran while pursuing a physics degree. Nick's love of tinkering with computers extends beyond work. He has been running video game servers from home for more than 10 years using Windows, Ubuntu, or Raspberry Pi OS. He also uses Proxmox to self-host a variety of services, including a Jellyfin Media Server, an Airsonic music server, a handful of game servers, NextCloud, and two Windows virtual machines. He enjoys DIY projects, especially if they involve technology. He regularly repairs and repurposes old computers and hardware for whatever new project is at hand. He has designed crossovers for homemade speakers all the way from the basic design to the PCB. Nick enjoys the outdoors. When he isn't working on a computer or DIY project, he is most likely to be found camping, backpacking, or canoeing. Once every hour, the Raspberry Pi sitting on my desk checks the weather and then plays a song about it. It is a bit like a cuckoo clock, except it tells me the weather instead of the time. The entire thing runs locally on the Pi itself. There are no cloud AI services, no subscriptions, and no streaming audio. The only thing that requires an internet connection is the weather check itself, though you could substitute a DIY weather station built with an ESP32 instead. Creating a Pi that plays music How it turns weather into a mood I started by setting up the Pi's access to the weather. I opted for Open-Meteo because it doesn't require a key or account, which makes it quite simple to use. A plain text document then maps weather to a mood. For example: sunny is joyful, rain is sombre, snow is delicate, and storms are tense. Each mood has a set of rules. Tense has a faster tempo, "plays" different instruments, and has a distinct musical register. Those rules are what define the general vibe of each kind of weather. A local AI composes the melody Actually, creating the music requires a small language model (artificial intelligence), which I'm running locally on my Pi via Ollama. That means there are no costs associated with API access. Basically, the model receives the current mood (which is determined by weather) and then outputs a melody to a JSON file. The AI also confirms that the output has the qualities it should have, so that a sunny day's song is always joyous, and a hallucination doesn't accidentally create a grim song for a sunny day. Critically, the model is run at a fairly high temperature (0.9), which ensures that the output from identical prompts won't be identical. So, two sunny days in a row won't generate identical songs, but they will use similar instruments, fall within a specific tempo range, and generally sound "upbeat." The AI writes notes; it doesn't generate sound Generating sound on a Pi is too demanding There are two different ways that AI can create music. The first is directly synthesizing the audio; the second writes a MIDI file with the notes (like sheet music for a computer, basically) that is played back by a program. If you have the computational resources available, the first approach generates more realistic, compelling music. However, I'm running this on a Raspberry Pi 4—it doesn't exactly have a ton of extra processing power available. So, I opted for the MIDI approach, which can still produce decent music. FluidSynth, a conventional software synthesizer, then turns the MIDI notes into sound using sampled instruments. Splitting composition from playback is critical for practicality. Note data is tiny, easy to generate, and easy to double-check before a song is played. If the AI produces a non-functional JSON or out-of-range notes, the code can reject or fix them. MIDI files are also completely portable. I could save them to my PC or move them over to my digital piano if I wanted. Playing the song At the top of every hour, FluidSynth plays the generated song. After about sixty seconds, the audio fades out and the Pi goes into an idle state until the next song is needed. The hardware defines the limits The biggest limitation is the Pi itself. I'm using a Pi 4 with 8GB of RAM; it can handle small models if you don't need them to run in real time, but the Pi struggles with larger models. However, since I only need one song per hour, the Pi's hardware limitations aren't really a significant issue. Additionally, a small LLM isn't Mozart or John Williams. The output songs will be "fine," but if you're expecting something brilliant, you'll need a much smarter AI. A Pi that sings about the rain By combining a weather API, a constrained local language model, and a synthesizer, you can create a device with something like a daily or hourly mood. This project also reinforces the point that small local models can be genuinely useful if you constrain them to a specific job. If you do want something smarter, you could build something that runs on the cloud and then transfer the file to your Raspberry Pi for playback. If you have a ChatGPT or Claude subscription, generating MIDI music probably won't use enough tokens to put a dent in your usage quota. However, I wanted something that composed music locally. You could create a setup that runs on a desktop-class GPU—the extra memory and computational power would go a long way.
I built a Raspberry Pi that composes music based on the weather
Full Article
Original Source
Read the full article at Howtogeek →KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.