As you can see, I have a strip of NeoPixels that sets the mood for my workspace. I’ve always loved using ambient lighting to reflect the time of day, my energy level, or even my focus mode.
But I wanted to go one step further:
What if I could talk to my lights — not just telling them a color, but describing my mood —have AI interpret my mood and change the color accordingly?
Using Gemini, Google’s new AI model, I built a system that listens to my voice, interprets my mood or direct color request, posts the selected color to Mastodon and updates Cheerlights in real time.
Conceptual OverviewWhat You'll Learn
- How to get started with Gemini
- How to add Voice UI to Your Project
- How to access high quality natural language voices on Google Cloud
- How to interact with Cheerlights
- (Optional) How to build your own Cheerlights display
The good news about this IoT project is that you can complete the entire thing using just your laptop with built-in microphone and speakers. The quickest route is to get your own API keys and run the Python script provided. To see the results (i.e. the color change) you can simply keep a web page open where I have a live Cheerlights application running. (https://www.sanddollarapps.com)
Get Your Gemini Studio API KeyBefore you can run this project, you'll need to create an.env file to hold the environment variables that connect it to Gemini, Google Cloud, and Mastodon For reference, it should look like this:
GOOGLE_API_KEY=[your-google-api-key-here]
GCP_TTS_KEY_PATH=[path-to-your-service-account.json]
MASTODON_TOKEN=[your-mastodon-access-token-here]
MASTODON_API_URL=https://mastodon.social/api/v1/statuses
You can get the Gemini API Key from Gemini AI Studio. It allows your Python code to interact with Gemini models. (You can get the key from the "Get API key" button in the center of the toolbar at top of the page).
Google Cloud Service Account Key (for Text-to-Speech)- Go to the Google Cloud Console
- Create a new project (or select an existing one
- In the left sidebar, go to APIs & Services > Library
- Search for Text-to-Speech API
- Enable the Text-to-Speech API
- In the sidebar, go to APIs & Services > Credential
- Click Create Credentials > Service Account
- Give your Service Account a name (example: gemini-tts)
- Click Create and Continue (default roles are fine for this project)
- After the Service Account is created, find it in the list and click it
- Under the Keys tab, click Add Key > Create New Key
- Choose JSON format and Download the key
Save this .json file at the root level of your project directory. Then set the path to it in your .env file as GCP_TTS_KEY_PATH
PRO TIP: Google Cloud may ask you to set up a billing account when enabling the Text-to-Speech API, even if you stay within the free tier. For this project’s light usage, it's unlikely you will incur any charges.
Setup Your Mastodon AccountTo communicate with Cheerlights, you'll need a Mastodon account.
Go to Preferences > Development, click New Application, and create one.
Under scopes, make sure that write:statuses is checked.
*IMPORTANT - once you have your Mastodon account setup, follow the @cheerlights bot. It should follow you back. Then posting "@cheerlights #blue", for example, results in Cheerlights around the world turning blue.
Setup Your Python EnvironmentBefore installing the dependencies, it's recommended that you setup a virtual environment to keep the project separate from others on your machine. Here's how to do that:
1. From your root directory, open Terminal and create a new virtual environment
python3 -m venv venv
2. Activate the virtual environment
source venv/bin/activate
HINT: it's active when you see (venv) at the beginning of your terminal prompt
3. Install the required Python packages
pip install -r requirements.txt
4. Customize lines 38 - 39 with your name and language option
5. That's it! You're ready to run the project
python gemini_cheer_tts_final.py
6. When you're ready to exit the virtual environment just type: deactivate
[OPTIONAL] Assemble HardwareTo see the Cheerlights change color in real time, there are several good options:
1. View my Cheerlights project page: https://www.sanddollarapps.com
2. Install the Cheerlights Extension for Chrome and pin it in Chrome
3. Build your own IoT device
Making the CircuitThere are just 3 connections you need to make:
- Ground: Connect GND on the ESP32 to GND on the NeoPixel Ring
- Power: Connect VIN from the ESP32 to POWER on the Ring
- Data: Connect GPIO 15 on the ESP32 to IN on the Ring
Finally, connect the board via USB to your laptop.
In the project folder on Github you'll find the Cheerlights sketch for your ESP32. As always, you'll need to enter your own Wifi SSID and password so that it will work in your environment.
Making it Your OwnHere are a few suggestions:
1. Change the array of languages available.
2. Change the voices used (https://cloud.google.com/text-to-speech/docs/voices) for each language.
3. Add automatic language detection.
One of the things I've done on the Mac is to create a desktop application using Automator.app. This allows me to double-click an app icon and launch the experience without opening Terminal manually. It’s a quick way to activate the script and start chatting with Gemini!
Comments
Please log in or sign up to comment.